Skip to content

Commit f7035c5

Browse files
committed
Improved naming + fixed destroy after modify
1 parent ed51ea6 commit f7035c5

4 files changed

Lines changed: 56 additions & 10 deletions

File tree

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "codify-plugin-test",
3-
"version": "0.0.23",
3+
"version": "0.0.25",
44
"description": "",
55
"main": "dist/index.js",
66
"typings": "dist/index.d.ts",
@@ -17,14 +17,16 @@
1717
"ajv-formats": "^3.0.1",
1818
"codify-schemas": "1.0.52",
1919
"lodash.matches": "^4.6.0",
20-
"lodash.differencewith": "4.5.0"
20+
"lodash.differencewith": "4.5.0",
21+
"lodash.unionby": "^4.8.0"
2122
},
2223
"devDependencies": {
2324
"@oclif/prettier-config": "^0.2.1",
2425
"@types/debug": "^4.1.12",
2526
"@types/node": "^18",
2627
"@types/lodash.matches": "^4.6.9",
2728
"@types/lodash.differencewith": "^4.5.9",
29+
"@types/lodash.unionby": "^4.8.9",
2830
"eslint": "^8.51.0",
2931
"eslint-config-oclif": "^5",
3032
"eslint-config-oclif-typescript": "^3",

src/plugin-tester.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ import {
1717
ValidateResponseData
1818
} from 'codify-schemas';
1919
import { ChildProcess, SpawnOptions, fork, spawn } from 'node:child_process';
20-
import inspector from 'node:inspector'
2120
import path from 'node:path';
21+
import unionBy from 'lodash.unionby';
2222

2323
import { CodifyTestUtils } from './test-utils.js';
2424

@@ -65,8 +65,8 @@ export class PluginTester {
6565
validateDestroy?: (plans: PlanResponseData[]) => Promise<void> | void,
6666
validateImport?: (importResults: (ImportResponseData['result'][0])[]) => Promise<void> | void,
6767
testModify?: {
68-
configs: ResourceConfig[],
69-
validate?: (plans: PlanResponseData[]) => Promise<void> | void,
68+
modifiedConfigs: ResourceConfig[],
69+
validateModify?: (plans: PlanResponseData[]) => Promise<void> | void,
7070
}
7171
}): Promise<void> {
7272
const {
@@ -152,7 +152,7 @@ ${JSON.stringify(unsuccessfulImports, null, 2)}`);
152152

153153
if (options?.testModify) {
154154
const modifyPlans = [];
155-
for (const config of options.testModify.configs) {
155+
for (const config of options.testModify.modifiedConfigs) {
156156
modifyPlans.push(await this.plan({
157157
desired: config,
158158
isStateful: false,
@@ -171,13 +171,16 @@ ${JSON.stringify(modifyPlans, null, 2)}`)
171171
});
172172
}
173173

174-
if (options.testModify.validate) {
175-
await options.testModify.validate(modifyPlans);
174+
if (options.testModify.validateModify) {
175+
await options.testModify.validateModify(modifyPlans);
176176
}
177177
}
178178

179179
if (!skipUninstall) {
180-
await this.uninstall(configs.toReversed(), options);
180+
const id = (config: ResourceConfig) => config.type + config.name ? `.${config.name}` : '';
181+
182+
const configsToDestroy = unionBy(options?.testModify?.modifiedConfigs ?? [], configs, id);
183+
await this.uninstall(configsToDestroy.toReversed(), options);
181184
}
182185
}
183186

test/plugin-tester.test.ts

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,12 +232,49 @@ describe('Plugin tester integration tests', () => {
232232
}], {
233233
skipUninstall: true,
234234
testModify: {
235-
configs: [{
235+
modifiedConfigs: [{
236236
type: 'test-modify',
237237
propA: 'Modify',
238238
propB: 10,
239239
}]
240240
}
241241
})
242242
})
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+
243280
})

test/test-plugin.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ export class TestModifyResource extends Resource<TestConfig> {
112112
}
113113

114114
async refresh(parameters: Partial<TestConfig>): Promise<Array<Partial<TestConfig>> | Partial<TestConfig> | null> {
115+
if (parameters === null) {
116+
return null;
117+
}
118+
115119
if (parameters.propA === 'Modify') {
116120
parameters.propA = 'Modify__';
117121
}

0 commit comments

Comments
 (0)