Skip to content

Commit ed51ea6

Browse files
committed
Added ability to test modify in full tests
1 parent 833ae6e commit ed51ea6

4 files changed

Lines changed: 89 additions & 3 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "codify-plugin-test",
3-
"version": "0.0.22",
3+
"version": "0.0.23",
44
"description": "",
55
"main": "dist/index.js",
66
"typings": "dist/index.d.ts",

src/plugin-tester.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ export class PluginTester {
6464
validateApply?: (plans: PlanResponseData[]) => Promise<void> | void,
6565
validateDestroy?: (plans: PlanResponseData[]) => Promise<void> | void,
6666
validateImport?: (importResults: (ImportResponseData['result'][0])[]) => Promise<void> | void,
67+
testModify?: {
68+
configs: ResourceConfig[],
69+
validate?: (plans: PlanResponseData[]) => Promise<void> | void,
70+
}
6771
}): Promise<void> {
6872
const {
6973
skipUninstall = false,
@@ -146,6 +150,32 @@ ${JSON.stringify(unsuccessfulImports, null, 2)}`);
146150
await options.validateImport(importResults.map((r) => r.result[0]));
147151
}
148152

153+
if (options?.testModify) {
154+
const modifyPlans = [];
155+
for (const config of options.testModify.configs) {
156+
modifyPlans.push(await this.plan({
157+
desired: config,
158+
isStateful: false,
159+
state: undefined,
160+
}));
161+
}
162+
163+
if (modifyPlans.some((p) => p.operation !== ResourceOperation.MODIFY)) {
164+
throw new Error(`Error while testing modify. Non-modify results were found in the plan:
165+
${JSON.stringify(modifyPlans, null, 2)}`)
166+
}
167+
168+
for (const plan of modifyPlans) {
169+
await this.apply({
170+
planId: plan.planId
171+
});
172+
}
173+
174+
if (options.testModify.validate) {
175+
await options.testModify.validate(modifyPlans);
176+
}
177+
}
178+
149179
if (!skipUninstall) {
150180
await this.uninstall(configs.toReversed(), options);
151181
}

test/plugin-tester.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,4 +222,22 @@ describe('Plugin tester integration tests', () => {
222222
})
223223

224224

225+
it('Can test modify', { timeout: 50000000 }, async () => {
226+
const plugin = new PluginTester(path.join(__dirname, './test-plugin.ts'));
227+
228+
await plugin.fullTest([{
229+
type: 'test-modify',
230+
propA: 'a',
231+
propB: 10,
232+
}], {
233+
skipUninstall: true,
234+
testModify: {
235+
configs: [{
236+
type: 'test-modify',
237+
propA: 'Modify',
238+
propB: 10,
239+
}]
240+
}
241+
})
242+
})
225243
})

test/test-plugin.ts

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
import { CreatePlan, DestroyPlan, Plugin, Resource, ResourceSettings, runPlugin } from 'codify-plugin-lib';
1+
import {
2+
CreatePlan,
3+
DestroyPlan, ModifyPlan,
4+
ParameterChange,
5+
Plugin,
6+
Resource,
7+
ResourceSettings,
8+
runPlugin
9+
} from 'codify-plugin-lib';
210
import { StringIndexedObject } from 'codify-schemas';
311

412
export interface TestConfig extends StringIndexedObject {
@@ -91,11 +99,41 @@ export class TestUninstallResource extends Resource<TestConfig> {
9199
}
92100
}
93101

102+
export class TestModifyResource extends Resource<TestConfig> {
103+
getSettings(): ResourceSettings<TestConfig> {
104+
return {
105+
id: 'test-modify',
106+
parameterSettings: {
107+
propA: { type: 'string', canModify: true },
108+
propB: { type: 'string', canModify: true },
109+
propC: { type: 'string', canModify: true }
110+
}
111+
}
112+
}
113+
114+
async refresh(parameters: Partial<TestConfig>): Promise<Array<Partial<TestConfig>> | Partial<TestConfig> | null> {
115+
if (parameters.propA === 'Modify') {
116+
parameters.propA = 'Modify__';
117+
}
118+
119+
return parameters;
120+
}
121+
122+
async modify(pc: ParameterChange<TestConfig>, plan: ModifyPlan<TestConfig>): Promise<void> {
123+
return super.modify(pc, plan);
124+
}
125+
126+
async create(plan: CreatePlan<TestConfig>): Promise<void> {}
127+
128+
async destroy(plan: DestroyPlan<TestConfig>): Promise<void> {}
129+
}
130+
94131
runPlugin(Plugin.create(
95132
'default',
96133
[
97134
new TestResource(),
98135
new TestResource2(),
99-
new TestUninstallResource()
136+
new TestUninstallResource(),
137+
new TestModifyResource()
100138
]
101139
));

0 commit comments

Comments
 (0)