|
1 | 1 | import Ajv2020 from 'ajv/dist/2020.js'; |
2 | 2 | import { |
3 | | - ApplyRequestData, InitializeResponseData, IpcMessageSchema, |
| 3 | + ApplyRequestData, |
| 4 | + InitializeResponseData, |
| 5 | + IpcMessageSchema, |
4 | 6 | MessageCmd, |
| 7 | + ParameterOperation, |
5 | 8 | PlanRequestData, |
6 | | - PlanResponseData, ResourceConfig, ResourceOperation, |
| 9 | + PlanResponseData, |
| 10 | + ResourceConfig, |
| 11 | + ResourceOperation, |
7 | 12 | SpawnStatus, |
8 | | - SudoRequestData, SudoRequestDataSchema, ValidateRequestData, ValidateResponseData |
| 13 | + SudoRequestData, |
| 14 | + SudoRequestDataSchema, |
| 15 | + ValidateRequestData, |
| 16 | + ValidateResponseData |
9 | 17 | } from 'codify-schemas'; |
10 | | -import { ChildProcess, SpawnOptions, fork, spawn } from 'node:child_process'; |
| 18 | +import { ChildProcess, fork, spawn, SpawnOptions } from 'node:child_process'; |
11 | 19 |
|
12 | 20 | import { CodifyTestUtils } from './test-utils.js'; |
13 | 21 | import path from 'node:path'; |
@@ -45,7 +53,7 @@ export class PluginTester { |
45 | 53 | this.handleSudoRequests(this.childProcess); |
46 | 54 | } |
47 | 55 |
|
48 | | - async test(configs: ResourceConfig[]): Promise<void> { |
| 56 | + async fullTest(configs: ResourceConfig[]): Promise<void> { |
49 | 57 | const initializeResult = await this.initialize(); |
50 | 58 |
|
51 | 59 | const unsupportedConfigs = configs.filter((c) => |
@@ -81,7 +89,39 @@ export class PluginTester { |
81 | 89 |
|
82 | 90 | const unsuccessfulPlans = validationPlans.filter((p) => p.operation !== ResourceOperation.NOOP); |
83 | 91 | if (unsuccessfulPlans.length > 0) { |
84 | | - throw new Error(`The following applies were not successful.\n ${JSON.stringify(unsuccessfulPlans, null, 2)}`) |
| 92 | + throw new Error(`The following applies were not successful. Re-running plan shows that the resources did not return no-op but instead returned: |
| 93 | +${JSON.stringify(unsuccessfulPlans, null, 2)}` |
| 94 | + ) |
| 95 | + } |
| 96 | + } |
| 97 | + |
| 98 | + async uninstall(configs: ResourceConfig[]) { |
| 99 | + for (const config of configs) { |
| 100 | + const { type, dependsOn, name, ...parameters } = config |
| 101 | + |
| 102 | + await this.apply({ |
| 103 | + plan: { |
| 104 | + operation: ResourceOperation.DESTROY, |
| 105 | + resourceType: config.type, |
| 106 | + parameters: Object.entries(parameters).map(([key, value]) => ({ |
| 107 | + name: key, |
| 108 | + previousValue: value, |
| 109 | + newValue: null, |
| 110 | + operation: ParameterOperation.REMOVE, |
| 111 | + })), |
| 112 | + } |
| 113 | + }); |
| 114 | + |
| 115 | + // Validate that the destroy was successful |
| 116 | + const validationPlan = await this.plan(config); |
| 117 | + if (validationPlan.operation !== ResourceOperation.CREATE) { |
| 118 | + throw new Error(`Resource ${config.type} was not successfully destroyed. |
| 119 | +Validation plan shows: |
| 120 | +${JSON.stringify(validationPlan, null, 2)} |
| 121 | +Previous config: |
| 122 | +${JSON.stringify(config, null, 2)}` |
| 123 | + ); |
| 124 | + } |
85 | 125 | } |
86 | 126 | } |
87 | 127 |
|
|
0 commit comments