codify-plugin-test 0.0.24 → 0.0.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/plugin-tester.d.ts +1 -0
- package/dist/plugin-tester.js +18 -1
- package/dist/plugin-tester.js.map +1 -1
- package/package.json +4 -2
- package/src/plugin-tester.ts +25 -2
- package/test/plugin-tester.test.ts +89 -0
- package/test/test-plugin.ts +47 -1
package/dist/plugin-tester.d.ts
CHANGED
package/dist/plugin-tester.js
CHANGED
|
@@ -2,6 +2,7 @@ import Ajv from 'ajv';
|
|
|
2
2
|
import { IpcMessageSchema, MessageCmd, ResourceOperation, SpawnStatus, SudoRequestDataSchema } from 'codify-schemas';
|
|
3
3
|
import { fork, spawn } from 'node:child_process';
|
|
4
4
|
import path from 'node:path';
|
|
5
|
+
import unionBy from 'lodash.unionby';
|
|
5
6
|
import { CodifyTestUtils } from './test-utils.js';
|
|
6
7
|
const ajv = new Ajv.default({
|
|
7
8
|
strict: true
|
|
@@ -104,7 +105,11 @@ ${JSON.stringify(modifyPlans, null, 2)}`);
|
|
|
104
105
|
}
|
|
105
106
|
}
|
|
106
107
|
if (!skipUninstall) {
|
|
107
|
-
|
|
108
|
+
const configsWithNames = this.addNamesToConfigs(configs);
|
|
109
|
+
const modifiedConfigs = this.addNamesToConfigs(options?.testModify?.modifiedConfigs ?? []);
|
|
110
|
+
const id = (config) => config.type + (config.name ? `.${config.name}` : '');
|
|
111
|
+
const configsToDestroy = unionBy(modifiedConfigs, configsWithNames, id);
|
|
112
|
+
await this.uninstall(configsToDestroy.toReversed(), options);
|
|
108
113
|
}
|
|
109
114
|
}
|
|
110
115
|
async uninstall(configs, options) {
|
|
@@ -194,6 +199,18 @@ ${JSON.stringify(validationPlan, null, 2)}
|
|
|
194
199
|
}
|
|
195
200
|
});
|
|
196
201
|
}
|
|
202
|
+
addNamesToConfigs(configs) {
|
|
203
|
+
const configsWithNames = Array();
|
|
204
|
+
const typeSet = new Set(configs.map((c) => c.type));
|
|
205
|
+
for (const type of typeSet) {
|
|
206
|
+
const sameTypeConfigs = configs.filter((c) => c.type === type);
|
|
207
|
+
if (sameTypeConfigs.length > 1) {
|
|
208
|
+
sameTypeConfigs.forEach((c, idx) => { c.name = c.name ?? idx.toString(); });
|
|
209
|
+
}
|
|
210
|
+
configsWithNames.push(...sameTypeConfigs);
|
|
211
|
+
}
|
|
212
|
+
return configsWithNames;
|
|
213
|
+
}
|
|
197
214
|
}
|
|
198
215
|
async function sudoSpawn(cmd, opts) {
|
|
199
216
|
return new Promise((resolve) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin-tester.js","sourceRoot":"","sources":["../src/plugin-tester.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,KAAK,CAAC;AACtB,OAAO,EAKL,gBAAgB,EAChB,UAAU,EAIV,iBAAiB,EACjB,WAAW,EAEX,qBAAqB,EAGtB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAA8B,IAAI,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"plugin-tester.js","sourceRoot":"","sources":["../src/plugin-tester.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,KAAK,CAAC;AACtB,OAAO,EAKL,gBAAgB,EAChB,UAAU,EAIV,iBAAiB,EACjB,WAAW,EAEX,qBAAqB,EAGtB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAA8B,IAAI,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC7E,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,OAAO,MAAM,gBAAgB,CAAC;AAErC,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAElD,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC;IAC1B,MAAM,EAAE,IAAI;CACb,CAAC,CAAC;AACH,MAAM,mBAAmB,GAAG,GAAG,CAAC,OAAO,CAA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A;QAEF,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QAC5B,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QAE5B,QAAQ,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,EAAE;YAC5B,OAAO,CAAC;gBACN,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;gBACrB,MAAM,EAAE,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC,WAAW,CAAC,KAAK;aAC7D,CAAC,CAAA;QACJ,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "codify-plugin-test",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.26",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
@@ -17,7 +17,8 @@
|
|
|
17
17
|
"ajv-formats": "^3.0.1",
|
|
18
18
|
"codify-schemas": "1.0.52",
|
|
19
19
|
"lodash.matches": "^4.6.0",
|
|
20
|
-
"lodash.differencewith": "4.5.0"
|
|
20
|
+
"lodash.differencewith": "4.5.0",
|
|
21
|
+
"lodash.unionby": "^4.8.0"
|
|
21
22
|
},
|
|
22
23
|
"devDependencies": {
|
|
23
24
|
"@oclif/prettier-config": "^0.2.1",
|
|
@@ -25,6 +26,7 @@
|
|
|
25
26
|
"@types/node": "^18",
|
|
26
27
|
"@types/lodash.matches": "^4.6.9",
|
|
27
28
|
"@types/lodash.differencewith": "^4.5.9",
|
|
29
|
+
"@types/lodash.unionby": "^4.8.9",
|
|
28
30
|
"eslint": "^8.51.0",
|
|
29
31
|
"eslint-config-oclif": "^5",
|
|
30
32
|
"eslint-config-oclif-typescript": "^3",
|
package/src/plugin-tester.ts
CHANGED
|
@@ -17,8 +17,8 @@ import {
|
|
|
17
17
|
ValidateResponseData
|
|
18
18
|
} from 'codify-schemas';
|
|
19
19
|
import { ChildProcess, SpawnOptions, fork, spawn } from 'node:child_process';
|
|
20
|
-
import inspector from 'node:inspector'
|
|
21
20
|
import path from 'node:path';
|
|
21
|
+
import unionBy from 'lodash.unionby';
|
|
22
22
|
|
|
23
23
|
import { CodifyTestUtils } from './test-utils.js';
|
|
24
24
|
|
|
@@ -177,7 +177,14 @@ ${JSON.stringify(modifyPlans, null, 2)}`)
|
|
|
177
177
|
}
|
|
178
178
|
|
|
179
179
|
if (!skipUninstall) {
|
|
180
|
-
|
|
180
|
+
// We need to add unique names to multiple configs with the same type or else it breaks the unionBy below.
|
|
181
|
+
const configsWithNames = this.addNamesToConfigs(configs);
|
|
182
|
+
const modifiedConfigs = this.addNamesToConfigs(options?.testModify?.modifiedConfigs ?? [])
|
|
183
|
+
|
|
184
|
+
const id = (config: ResourceConfig) => config.type + (config.name ? `.${config.name}` : '')
|
|
185
|
+
|
|
186
|
+
const configsToDestroy = unionBy(modifiedConfigs, configsWithNames, id);
|
|
187
|
+
await this.uninstall(configsToDestroy.toReversed(), options);
|
|
181
188
|
}
|
|
182
189
|
}
|
|
183
190
|
|
|
@@ -288,6 +295,22 @@ ${JSON.stringify(validationPlan, null, 2)}
|
|
|
288
295
|
}
|
|
289
296
|
})
|
|
290
297
|
}
|
|
298
|
+
|
|
299
|
+
private addNamesToConfigs(configs: ResourceConfig[]): ResourceConfig[] {
|
|
300
|
+
const configsWithNames = new Array<ResourceConfig>();
|
|
301
|
+
|
|
302
|
+
const typeSet = new Set(configs.map((c) => c.type));
|
|
303
|
+
for (const type of typeSet) {
|
|
304
|
+
const sameTypeConfigs = configs.filter((c) => c.type === type);
|
|
305
|
+
if (sameTypeConfigs.length > 1) {
|
|
306
|
+
sameTypeConfigs.forEach((c, idx) => { c.name = c.name ?? idx.toString() });
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
configsWithNames.push(...sameTypeConfigs);
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
return configsWithNames;
|
|
313
|
+
}
|
|
291
314
|
}
|
|
292
315
|
|
|
293
316
|
|
|
@@ -240,4 +240,93 @@ describe('Plugin tester integration tests', () => {
|
|
|
240
240
|
}
|
|
241
241
|
})
|
|
242
242
|
})
|
|
243
|
+
|
|
244
|
+
it('Will call destory with the correct parameters (modify)', { timeout: 50000000 }, async () => {
|
|
245
|
+
const plugin = new PluginTester(path.join(__dirname, './test-plugin.ts'));
|
|
246
|
+
|
|
247
|
+
await expect(async () => await plugin.fullTest([{
|
|
248
|
+
type: 'test-modify',
|
|
249
|
+
propA: 'a',
|
|
250
|
+
propB: 10,
|
|
251
|
+
}], {
|
|
252
|
+
testModify: {
|
|
253
|
+
modifiedConfigs: [{
|
|
254
|
+
type: 'test-modify',
|
|
255
|
+
propA: 'Modify',
|
|
256
|
+
propB: 10,
|
|
257
|
+
}]
|
|
258
|
+
}
|
|
259
|
+
})).rejects.toThrow(
|
|
260
|
+
`
|
|
261
|
+
"parameters": [
|
|
262
|
+
{
|
|
263
|
+
"name": "propA",
|
|
264
|
+
"previousValue": "Modify__",
|
|
265
|
+
"newValue": "Modify",
|
|
266
|
+
"operation": "modify"
|
|
267
|
+
},
|
|
268
|
+
{
|
|
269
|
+
"name": "propB",
|
|
270
|
+
"previousValue": "10",
|
|
271
|
+
"newValue": "10",
|
|
272
|
+
"operation": "noop"
|
|
273
|
+
}
|
|
274
|
+
]
|
|
275
|
+
}
|
|
276
|
+
`
|
|
277
|
+
)
|
|
278
|
+
})
|
|
279
|
+
|
|
280
|
+
it('Works when uninstalling two resources', async () => {
|
|
281
|
+
const plugin = new PluginTester(path.join(__dirname, './test-plugin.ts'));
|
|
282
|
+
|
|
283
|
+
await plugin.fullTest([{
|
|
284
|
+
type: 'test-destroy',
|
|
285
|
+
propA: 'a',
|
|
286
|
+
propB: 10,
|
|
287
|
+
}, {
|
|
288
|
+
type: 'test-destroy-2',
|
|
289
|
+
propA: 'a',
|
|
290
|
+
propB: 20,
|
|
291
|
+
}], {
|
|
292
|
+
validateDestroy(plan) {
|
|
293
|
+
expect(plan.length).to.eq(2);
|
|
294
|
+
expect(plan[0]).toMatchObject({
|
|
295
|
+
operation: 'destroy',
|
|
296
|
+
resourceType: 'test-destroy-2',
|
|
297
|
+
})
|
|
298
|
+
expect(plan[1]).toMatchObject({
|
|
299
|
+
operation: 'destroy',
|
|
300
|
+
resourceType: 'test-destroy',
|
|
301
|
+
})
|
|
302
|
+
}
|
|
303
|
+
});
|
|
304
|
+
})
|
|
305
|
+
|
|
306
|
+
it('Can uninstall two resources with the same type', async () => {
|
|
307
|
+
const plugin = new PluginTester(path.join(__dirname, './test-plugin.ts'));
|
|
308
|
+
|
|
309
|
+
await plugin.fullTest([{
|
|
310
|
+
type: 'test-destroy',
|
|
311
|
+
propA: 'a',
|
|
312
|
+
propB: 10,
|
|
313
|
+
}, {
|
|
314
|
+
type: 'test-destroy',
|
|
315
|
+
propA: 'a',
|
|
316
|
+
propB: 20,
|
|
317
|
+
}], {
|
|
318
|
+
validateDestroy(plan) {
|
|
319
|
+
expect(plan.length).to.eq(2);
|
|
320
|
+
expect(plan[0]).toMatchObject({
|
|
321
|
+
operation: 'destroy',
|
|
322
|
+
resourceType: 'test-destroy',
|
|
323
|
+
})
|
|
324
|
+
expect(plan[1]).toMatchObject({
|
|
325
|
+
operation: 'destroy',
|
|
326
|
+
resourceType: 'test-destroy',
|
|
327
|
+
})
|
|
328
|
+
}
|
|
329
|
+
});
|
|
330
|
+
})
|
|
331
|
+
|
|
243
332
|
})
|
package/test/test-plugin.ts
CHANGED
|
@@ -112,6 +112,10 @@ export class TestModifyResource extends Resource<TestConfig> {
|
|
|
112
112
|
}
|
|
113
113
|
|
|
114
114
|
async refresh(parameters: Partial<TestConfig>): Promise<Array<Partial<TestConfig>> | Partial<TestConfig> | null> {
|
|
115
|
+
if (parameters === null) {
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
|
|
115
119
|
if (parameters.propA === 'Modify') {
|
|
116
120
|
parameters.propA = 'Modify__';
|
|
117
121
|
}
|
|
@@ -128,12 +132,54 @@ export class TestModifyResource extends Resource<TestConfig> {
|
|
|
128
132
|
async destroy(plan: DestroyPlan<TestConfig>): Promise<void> {}
|
|
129
133
|
}
|
|
130
134
|
|
|
135
|
+
export class TestDestroyResource extends Resource<TestConfig> {
|
|
136
|
+
private isCreated: boolean;
|
|
137
|
+
private isDestroyed: boolean;
|
|
138
|
+
|
|
139
|
+
getSettings(): ResourceSettings<TestConfig> {
|
|
140
|
+
return {
|
|
141
|
+
id: 'test-destroy',
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
async refresh(parameters: Partial<TestConfig>): Promise<Array<Partial<TestConfig>> | Partial<TestConfig> | null> {
|
|
146
|
+
if (this.isCreated && !this.isDestroyed) {
|
|
147
|
+
return parameters;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
return null;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
async modify(pc: ParameterChange<TestConfig>, plan: ModifyPlan<TestConfig>): Promise<void> {
|
|
154
|
+
return super.modify(pc, plan);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
async create(plan: CreatePlan<TestConfig>): Promise<void> {
|
|
158
|
+
this.isCreated = true;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
async destroy(plan: DestroyPlan<TestConfig>): Promise<void> {
|
|
162
|
+
this.isDestroyed = true;
|
|
163
|
+
console.log('destroy');
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export class TestDestroyResource2 extends TestDestroyResource {
|
|
168
|
+
getSettings(): ResourceSettings<TestConfig> {
|
|
169
|
+
return {
|
|
170
|
+
id: 'test-destroy-2',
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
131
175
|
runPlugin(Plugin.create(
|
|
132
176
|
'default',
|
|
133
177
|
[
|
|
134
178
|
new TestResource(),
|
|
135
179
|
new TestResource2(),
|
|
136
180
|
new TestUninstallResource(),
|
|
137
|
-
new TestModifyResource()
|
|
181
|
+
new TestModifyResource(),
|
|
182
|
+
new TestDestroyResource(),
|
|
183
|
+
new TestDestroyResource2()
|
|
138
184
|
]
|
|
139
185
|
));
|