Skip to content

Commit aedce0f

Browse files
committed
feat: Updated tests and fixed issues with new os parameter
1 parent 64176ce commit aedce0f

File tree

8 files changed

+89
-22
lines changed

8 files changed

+89
-22
lines changed

src/plan/plan.test.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { describe, expect, it } from 'vitest';
22
import { Plan } from './plan.js';
3-
import { ParameterOperation, ResourceOperation } from 'codify-schemas';
3+
import { OS, ParameterOperation, ResourceOperation } from 'codify-schemas';
44
import { TestConfig, TestResource } from '../utils/test-utils.test.js';
55
import { ResourceController } from '../resource/resource-controller.js';
66
import { ParsedResourceSettings } from '../resource/parsed-resource-settings.js';
@@ -152,6 +152,7 @@ describe('Plan entity tests', () => {
152152
getSettings(): ResourceSettings<any> {
153153
return {
154154
id: 'type',
155+
operatingSystems: [OS.Darwin],
155156
parameterSettings: {
156157
propZ: { type: 'array', isElementEqual: (a, b) => b.includes(a) }
157158
}
@@ -184,6 +185,7 @@ describe('Plan entity tests', () => {
184185
getSettings(): ResourceSettings<any> {
185186
return {
186187
id: 'type',
188+
operatingSystems: [OS.Darwin],
187189
parameterSettings: {
188190
propZ: {
189191
type: 'array',
@@ -236,6 +238,7 @@ describe('Plan entity tests', () => {
236238
getSettings(): ResourceSettings<TestConfig> {
237239
return {
238240
id: 'type',
241+
operatingSystems: [OS.Darwin],
239242
parameterSettings: {
240243
propA: { type: 'string' },
241244
propB: { type: 'string', canModify: true },
@@ -289,6 +292,7 @@ describe('Plan entity tests', () => {
289292
getSettings(): ResourceSettings<TestConfig> {
290293
return {
291294
id: 'type',
295+
operatingSystems: [OS.Darwin],
292296
parameterSettings: {
293297
propA: { type: 'string' },
294298
propB: { type: 'string', canModify: true },
@@ -351,6 +355,7 @@ function createTestResource() {
351355
getSettings(): ResourceSettings<TestConfig> {
352356
return {
353357
id: 'type',
358+
operatingSystems: [OS.Darwin],
354359
parameterSettings: {
355360
propA: {
356361
default: 'defaultA'

src/plugin/plugin.test.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { describe, expect, it } from 'vitest';
22
import { Plugin } from './plugin.js';
3-
import { ApplyRequestData, ParameterOperation, ResourceOperation, StringIndexedObject } from 'codify-schemas';
3+
import { ApplyRequestData, OS, ParameterOperation, ResourceOperation, StringIndexedObject } from 'codify-schemas';
44
import { Resource } from '../resource/resource.js';
55
import { Plan } from '../plan/plan.js';
66
import { spy } from 'sinon';
@@ -17,7 +17,8 @@ interface TestConfig extends StringIndexedObject {
1717
class TestResource extends Resource<TestConfig> {
1818
getSettings(): ResourceSettings<TestConfig> {
1919
return {
20-
id: 'testResource'
20+
id: 'testResource',
21+
operatingSystems: [OS.Darwin],
2122
};
2223
}
2324

@@ -154,6 +155,7 @@ describe('Plugin tests', () => {
154155
getSettings(): ResourceSettings<TestConfig> {
155156
return {
156157
id: 'typeId',
158+
operatingSystems: [OS.Darwin],
157159
schema,
158160
}
159161
}
@@ -192,6 +194,7 @@ describe('Plugin tests', () => {
192194
getSettings(): ResourceSettings<TestConfig> {
193195
return {
194196
id: 'typeId',
197+
operatingSystems: [OS.Darwin],
195198
schema,
196199
importAndDestroy: {
197200
requiredParameters: []
@@ -285,6 +288,7 @@ describe('Plugin tests', () => {
285288
getSettings(): ResourceSettings<TestConfig> {
286289
return {
287290
id: 'type',
291+
operatingSystems: [OS.Darwin],
288292
schema: {
289293
'$schema': 'http://json-schema.org/draft-07/schema',
290294
'$id': 'https://www.codifycli.com/ssh-config.json',
@@ -330,6 +334,7 @@ describe('Plugin tests', () => {
330334
getSettings(): ResourceSettings<TestConfig> {
331335
return {
332336
...super.getSettings(),
337+
operatingSystems: [OS.Darwin],
333338
allowMultiple: {
334339
identifyingParameters: ['path', 'paths']
335340
}
@@ -351,6 +356,7 @@ describe('Plugin tests', () => {
351356
getSettings(): ResourceSettings<TestConfig> {
352357
return {
353358
...super.getSettings(),
359+
operatingSystems: [OS.Darwin],
354360
parameterSettings: {
355361
path: { type: 'directory' },
356362
paths: { type: 'array', itemType: 'directory' }
@@ -407,6 +413,7 @@ describe('Plugin tests', () => {
407413
getSettings(): ResourceSettings<TestConfig> {
408414
return {
409415
id: 'ssh-config',
416+
operatingSystems: [OS.Darwin],
410417
parameterSettings: {
411418
hosts: { type: 'stateful', definition: new TestStatefulParameter() }
412419
},
@@ -454,6 +461,7 @@ describe('Plugin tests', () => {
454461
getSettings(): ResourceSettings<TestConfig> {
455462
return {
456463
id: 'ssh-config',
464+
operatingSystems: [OS.Darwin],
457465
allowMultiple: true
458466
}
459467
}
@@ -476,6 +484,7 @@ describe('Plugin tests', () => {
476484
getSettings(): ResourceSettings<TestConfig> {
477485
return {
478486
id: 'ssh-config',
487+
operatingSystems: [OS.Darwin],
479488
}
480489
}
481490
})

src/pty/index.test.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ import { TestConfig, TestResource } from '../utils/test-utils.test.js';
33
import { getPty, IPty } from './index.js';
44
import { Plugin } from '../plugin/plugin.js'
55
import { CreatePlan } from '../plan/plan-types.js';
6-
import { ResourceOperation } from 'codify-schemas';
6+
import { OS, ResourceOperation } from 'codify-schemas';
77
import { ResourceSettings } from '../resource/resource-settings.js';
8+
import { SequentialPty } from './seqeuntial-pty.js';
89

910
describe('General tests for PTYs', () => {
1011
it('Can get pty within refresh', async () => {
@@ -45,7 +46,8 @@ describe('General tests for PTYs', () => {
4546
const testResource1 = new class extends TestResource {
4647
getSettings(): ResourceSettings<TestConfig> {
4748
return {
48-
id: 'type1'
49+
id: 'type1',
50+
operatingSystems: [OS.Darwin],
4951
}
5052
}
5153

@@ -64,6 +66,7 @@ describe('General tests for PTYs', () => {
6466
getSettings(): ResourceSettings<TestConfig> {
6567
return {
6668
id: 'type2',
69+
operatingSystems: [OS.Darwin],
6770
}
6871
}
6972

@@ -103,11 +106,11 @@ describe('General tests for PTYs', () => {
103106
expect(pty1).to.eq(pty2);
104107
})
105108

106-
it('Currently pty not available for apply', async () => {
109+
it('Sequential pty should be available for applies', async () => {
107110
const testResource = new class extends TestResource {
108111
create(plan: CreatePlan<TestConfig>): Promise<void> {
109112
const $ = getPty();
110-
expect($).to.be.undefined;
113+
expect($).to.instanceof(SequentialPty)
111114
}
112115
}
113116

src/resource/parsed-resource-settings.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { JSONSchemaType } from 'ajv';
2-
import { StringIndexedObject } from 'codify-schemas';
2+
import { OS, StringIndexedObject } from 'codify-schemas';
33

44
import { StatefulParameterController } from '../stateful-parameter/stateful-parameter-controller.js';
55
import {
@@ -46,16 +46,17 @@ export class ParsedResourceSettings<T extends StringIndexedObject> implements Re
4646
removeStatefulParametersBeforeDestroy?: boolean | undefined;
4747
dependencies?: string[] | undefined;
4848
transformation?: InputTransformation;
49+
50+
operatingSystems!: Array<OS>;
51+
isSensitive?: boolean;
52+
4953
private settings: ResourceSettings<T>;
5054

5155
constructor(settings: ResourceSettings<T>) {
5256
this.settings = settings;
53-
this.id = settings.id;
54-
this.schema = settings.schema;
55-
this.allowMultiple = settings.allowMultiple;
56-
this.removeStatefulParametersBeforeDestroy = settings.removeStatefulParametersBeforeDestroy;
57-
this.dependencies = settings.dependencies;
58-
this.transformation = settings.transformation;
57+
58+
const { parameterSettings, ...rest } = settings;
59+
Object.assign(this, rest);
5960

6061
this.validateSettings();
6162
}

src/resource/resource-controller-stateful-mode.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { describe, expect, it } from 'vitest';
2-
import { ParameterOperation, ResourceOperation } from 'codify-schemas';
2+
import { OS, ParameterOperation, ResourceOperation } from 'codify-schemas';
33
import { TestConfig, TestResource, TestStatefulParameter } from '../utils/test-utils.test.js';
44
import { ResourceSettings } from './resource-settings.js';
55
import { ResourceController } from './resource-controller.js';
@@ -179,6 +179,7 @@ describe('Resource tests for stateful plans', () => {
179179
getSettings(): ResourceSettings<TestConfig> {
180180
return {
181181
id: 'type',
182+
operatingSystems: [OS.Darwin],
182183
parameterSettings: {
183184
propD: { type: 'stateful', definition: statefulParameter },
184185
}

src/resource/resource-controller.test.ts

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Resource } from './resource.js';
2-
import { ResourceOperation } from 'codify-schemas';
2+
import { OS, ResourceOperation } from 'codify-schemas';
33
import { spy } from 'sinon';
44
import { describe, expect, it } from 'vitest'
55
import { ArrayParameterSetting, ParameterSetting, ResourceSettings } from './resource-settings.js';
@@ -19,6 +19,7 @@ describe('Resource tests', () => {
1919
getSettings(): ResourceSettings<TestConfig> {
2020
return {
2121
id: 'type',
22+
operatingSystems: [OS.Darwin],
2223
dependencies: ['homebrew', 'python'],
2324
parameterSettings: {
2425
propA: {
@@ -197,6 +198,7 @@ describe('Resource tests', () => {
197198
getSettings(): ResourceSettings<TestConfig> {
198199
return {
199200
id: 'resource',
201+
operatingSystems: [OS.Darwin],
200202
parameterSettings: {
201203
propA: { canModify: true },
202204
propB: { canModify: true },
@@ -232,6 +234,7 @@ describe('Resource tests', () => {
232234
getSettings(): ResourceSettings<TestConfig> {
233235
return {
234236
id: 'type',
237+
operatingSystems: [OS.Darwin],
235238
dependencies: ['homebrew', 'python'],
236239
parameterSettings: {
237240
propA: { canModify: true },
@@ -254,6 +257,7 @@ describe('Resource tests', () => {
254257
getSettings(): ResourceSettings<TestConfig> {
255258
return {
256259
id: 'type',
260+
operatingSystems: [OS.Darwin],
257261
dependencies: ['homebrew', 'python'],
258262
parameterSettings: {
259263
propA: { canModify: true },
@@ -270,6 +274,7 @@ describe('Resource tests', () => {
270274
getSettings(): ResourceSettings<TestConfig> {
271275
return {
272276
id: 'type',
277+
operatingSystems: [OS.Darwin],
273278
parameterSettings: {
274279
propA: { default: 'propADefault' }
275280
}
@@ -298,6 +303,7 @@ describe('Resource tests', () => {
298303
getSettings(): ResourceSettings<TestConfig> {
299304
return {
300305
id: 'type',
306+
operatingSystems: [OS.Darwin],
301307
parameterSettings: {
302308
propE: { default: 'propEDefault' }
303309
}
@@ -325,6 +331,7 @@ describe('Resource tests', () => {
325331
getSettings(): ResourceSettings<TestConfig> {
326332
return {
327333
id: 'type',
334+
operatingSystems: [OS.Darwin],
328335
parameterSettings: {
329336
propE: { default: 'propEDefault' }
330337
}
@@ -348,6 +355,7 @@ describe('Resource tests', () => {
348355
getSettings(): ResourceSettings<TestConfig> {
349356
return {
350357
id: 'type',
358+
operatingSystems: [OS.Darwin],
351359
parameterSettings: {
352360
propA: { default: 'propADefault' }
353361
}
@@ -376,6 +384,7 @@ describe('Resource tests', () => {
376384
getSettings(): ResourceSettings<TestConfig> {
377385
return {
378386
id: 'type',
387+
operatingSystems: [OS.Darwin],
379388
parameterSettings: {
380389
propA: { default: 'propADefault' }
381390
}
@@ -392,7 +401,7 @@ describe('Resource tests', () => {
392401
it('Has the correct typing for applys', () => {
393402
const resource = new class extends Resource<TestConfig> {
394403
getSettings(): ResourceSettings<TestConfig> {
395-
return { id: 'type' }
404+
return { id: 'type', operatingSystems: [OS.Darwin], }
396405
}
397406

398407
async refresh(): Promise<Partial<TestConfig> | null> {
@@ -418,7 +427,8 @@ describe('Resource tests', () => {
418427
const parameter1 = new class extends StatefulParameter<any, any> {
419428
getSettings(): ParameterSetting {
420429
return {
421-
type: 'version'
430+
type: 'version',
431+
operatingSystems: [OS.Darwin],
422432
}
423433
}
424434

@@ -462,6 +472,7 @@ describe('Resource tests', () => {
462472
getSettings(): ResourceSettings<TestConfig> {
463473
return {
464474
id: 'nvm',
475+
operatingSystems: [OS.Darwin],
465476
parameterSettings: {
466477
global: { type: 'stateful', definition: parameter1, order: 2 },
467478
nodeVersions: { type: 'stateful', definition: parameter2, order: 1 },
@@ -514,6 +525,7 @@ describe('Resource tests', () => {
514525
getSettings(): ResourceSettings<TestConfig> {
515526
return {
516527
id: 'nvm',
528+
operatingSystems: [OS.Darwin],
517529
parameterSettings: {
518530
global: { type: 'stateful', definition: parameter1, order: 2 },
519531
nodeVersions: { type: 'stateful', definition: parameter2, order: 1 },
@@ -546,6 +558,7 @@ describe('Resource tests', () => {
546558
getSettings(): ResourceSettings<TestConfig> {
547559
return {
548560
id: 'resourceType',
561+
operatingSystems: [OS.Darwin],
549562
parameterSettings: {
550563
propD: {
551564
type: 'array',
@@ -630,6 +643,7 @@ describe('Resource tests', () => {
630643
getSettings(): ResourceSettings<TestConfig> {
631644
return {
632645
id: 'resourceType',
646+
operatingSystems: [OS.Darwin],
633647
parameterSettings: {
634648
propD: {
635649
type: 'array',
@@ -720,6 +734,7 @@ describe('Resource tests', () => {
720734
getSettings(): ResourceSettings<TestConfig> {
721735
return {
722736
id: 'resourceType',
737+
operatingSystems: [OS.Darwin],
723738
parameterSettings: {
724739
propA: { type: 'string', default: 'defaultValue' },
725740
propB: { type: 'boolean', default: true }
@@ -755,6 +770,7 @@ describe('Resource tests', () => {
755770
getSettings(): ResourceSettings<any> {
756771
return {
757772
id: 'path',
773+
operatingSystems: [OS.Darwin],
758774
parameterSettings: {
759775
path: { type: 'string', isEqual: 'directory' },
760776
paths: { canModify: true, type: 'array', isElementEqual: 'directory' },
@@ -797,6 +813,7 @@ describe('Resource tests', () => {
797813
getSettings(): ResourceSettings<any> {
798814
return {
799815
id: 'path',
816+
operatingSystems: [OS.Darwin],
800817
parameterSettings: {
801818
path: { type: 'string', isEqual: 'directory' },
802819
paths: { canModify: true, type: 'array', isElementEqual: 'directory' },
@@ -840,6 +857,7 @@ describe('Resource tests', () => {
840857
getSettings(): ResourceSettings<any> {
841858
return {
842859
id: 'path',
860+
operatingSystems: [OS.Darwin],
843861
parameterSettings: {
844862
path: { type: 'directory' },
845863
paths: { canModify: true, type: 'array', itemType: 'directory' },

0 commit comments

Comments
 (0)