|
4 | 4 | InitializeResponseData, |
5 | 5 | IpcMessageSchema, |
6 | 6 | MessageCmd, |
7 | | - ParameterOperation, |
8 | 7 | PlanRequestData, |
9 | 8 | PlanResponseData, |
10 | 9 | ResourceConfig, |
@@ -53,7 +52,7 @@ export class PluginTester { |
53 | 52 | this.handleSudoRequests(this.childProcess); |
54 | 53 | } |
55 | 54 |
|
56 | | - async fullTest(configs: ResourceConfig[], assertPlans?: (plans: PlanResponseData[]) => void): Promise<void> { |
| 55 | + async fullTest(configs: ResourceConfig[], skipUninstall = false, assertPlans?: (plans: PlanResponseData[]) => void): Promise<void> { |
57 | 56 | const initializeResult = await this.initialize(); |
58 | 57 |
|
59 | 58 | const unsupportedConfigs = configs.filter((c) => |
@@ -105,38 +104,45 @@ export class PluginTester { |
105 | 104 | ${JSON.stringify(unsuccessfulPlans, null, 2)}` |
106 | 105 | ) |
107 | 106 | } |
| 107 | + |
| 108 | + if (!skipUninstall) { |
| 109 | + await this.uninstall(configs.toReversed()); |
| 110 | + } |
108 | 111 | } |
109 | 112 |
|
110 | 113 | async uninstall(configs: ResourceConfig[]) { |
| 114 | + const plans = []; |
| 115 | + |
111 | 116 | for (const config of configs) { |
112 | | - const { dependsOn, name, type, ...parameters } = config |
| 117 | + plans.push(await this.plan({ |
| 118 | + desired: undefined, |
| 119 | + isStateful: true, |
| 120 | + state: config |
| 121 | + })) |
| 122 | + } |
| 123 | + |
| 124 | + for (const plan of plans) { |
| 125 | + if (plan.operation !== ResourceOperation.DESTROY) { |
| 126 | + throw new Error(`Expect resource operation to be 'destory' but instead received plan: \n ${JSON.stringify(plan, null, 2)}`) |
| 127 | + } |
113 | 128 |
|
114 | 129 | await this.apply({ |
115 | | - plan: { |
116 | | - operation: ResourceOperation.DESTROY, |
117 | | - parameters: Object.entries(parameters).map(([key, value]) => ({ |
118 | | - name: key, |
119 | | - newValue: null, |
120 | | - operation: ParameterOperation.REMOVE, |
121 | | - previousValue: value, |
122 | | - })), |
123 | | - resourceType: type, |
124 | | - } |
| 130 | + planId: plan.planId |
125 | 131 | }); |
| 132 | + } |
126 | 133 |
|
127 | | - // Validate that the destroy was successful |
| 134 | + // Validate that the destroy was successful |
| 135 | + for (const config of configs) { |
128 | 136 | const validationPlan = await this.plan({ |
129 | 137 | desired: config, |
130 | | - state: undefined, |
131 | | - isStateful: false, |
132 | | - }); |
| 138 | + isStateful: true, |
| 139 | + state: undefined |
| 140 | + }) |
133 | 141 | if (validationPlan.operation !== ResourceOperation.CREATE) { |
134 | | - throw new Error(`Resource ${type} was not successfully destroyed. |
| 142 | + throw new Error(`Resource was not successfully destroyed. |
135 | 143 | Validation plan shows: |
136 | 144 | ${JSON.stringify(validationPlan, null, 2)} |
137 | | -Previous config: |
138 | | -${JSON.stringify(config, null, 2)}` |
139 | | - ); |
| 145 | + `); |
140 | 146 | } |
141 | 147 | } |
142 | 148 | } |
|
0 commit comments