codify-plugin-test 0.0.32 → 0.0.34

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.
@@ -4,12 +4,15 @@ import path from 'node:path';
4
4
  import { ResourceOperation } from 'codify-schemas/src/types/index.js';
5
5
  import deepMatches from 'lodash.matches';
6
6
  import differenceWith from 'lodash.differencewith';
7
+ import { PluginProcess } from '../src/plugin-process';
8
+ import * as fs from 'node:fs';
7
9
 
10
+ const pluginPath = path.join(__dirname, './test-plugin.ts');
8
11
 
9
12
  describe('Plugin tester integration tests', () => {
10
- let plugin: PluginTester;
13
+ let plugin: PluginProcess;
11
14
  beforeEach(() => {
12
- plugin = new PluginTester(path.join(__dirname, './test-plugin.ts'));
15
+ plugin = new PluginProcess(path.join(__dirname, './test-plugin.ts'));
13
16
  })
14
17
 
15
18
  afterEach(() => {
@@ -120,7 +123,7 @@ describe('Plugin tester integration tests', () => {
120
123
 
121
124
  it('Has helpers that can test a resource', async () => {
122
125
  // No expect needed here. This passes if it doesn't throw.
123
- await plugin.fullTest([{
126
+ await PluginTester.fullTest(pluginPath, [{
124
127
  type: 'test',
125
128
  propA: 'a',
126
129
  propB: 10,
@@ -137,7 +140,7 @@ describe('Plugin tester integration tests', () => {
137
140
 
138
141
  it('Full test supports plan assertions to ensure the generated plan is correct', async () => {
139
142
  // No expect needed here. This passes if it doesn't throw.
140
- await plugin.fullTest([{
143
+ await PluginTester.fullTest(pluginPath, [{
141
144
  type: 'test',
142
145
  propA: 'a',
143
146
  propB: 10,
@@ -167,7 +170,7 @@ describe('Plugin tester integration tests', () => {
167
170
 
168
171
  it('Full test supports plan assertions to ensure the generated plan is correct (2)', async () => {
169
172
  // No expect needed here. This passes if it doesn't throw.
170
- await plugin.fullTest([{
173
+ await PluginTester.fullTest(pluginPath, [{
171
174
  type: 'test',
172
175
  propA: 'a',
173
176
  propB: 10,
@@ -187,7 +190,7 @@ describe('Plugin tester integration tests', () => {
187
190
  console.log(differenceWith(['b', 'a'], ['a', 'b', 'c'], (a, b) => deepMatches(a)(b)).length === 0);
188
191
 
189
192
  // No expect needed here. This passes if it doesn't throw.
190
- await plugin.fullTest([{
193
+ await PluginTester.fullTest(pluginPath, [{
191
194
  type: 'test2',
192
195
  propB: ['second', 'first'],
193
196
  propA: 'a',
@@ -198,7 +201,7 @@ describe('Plugin tester integration tests', () => {
198
201
 
199
202
  it('Has helpers that can uninstall a resource', async () => {
200
203
  // No expect needed here. This passes if it doesn't throw.
201
- await plugin.uninstall([{
204
+ await PluginTester.uninstall(pluginPath, [{
202
205
  type: 'test-uninstall',
203
206
  propA: 'a',
204
207
  propB: 10,
@@ -207,20 +210,18 @@ describe('Plugin tester integration tests', () => {
207
210
  })
208
211
 
209
212
  it('Has helpers that can uninstall a resource (errors out when unsuccessful)', async () => {
210
- // const plugin = new PluginTester(path.join(__dirname, './test-plugin.ts'));
211
- //
212
- // // No expect needed here. This passes if it doesn't throw.
213
- // await expect(async () => plugin.uninstall([{
214
- // type: 'test',
215
- // propA: 'a',
216
- // propB: 10,
217
- // propC: 'c',
218
- // }])).rejects.toThrowError();
213
+ // No expect needed here. This passes if it doesn't throw.
214
+ await expect(async () => PluginTester.uninstall(pluginPath, [{
215
+ type: 'test',
216
+ propA: 'a',
217
+ propB: 10,
218
+ propC: 'c',
219
+ }])).rejects.toThrowError();
219
220
  })
220
221
 
221
222
 
222
223
  it('Can test modify', { timeout: 50000000 }, async () => {
223
- await expect(() => plugin.fullTest([{
224
+ await expect(() => PluginTester.fullTest(pluginPath, [{
224
225
  type: 'test-modify',
225
226
  propA: 'a',
226
227
  propB: 10,
@@ -236,14 +237,13 @@ describe('Plugin tester integration tests', () => {
236
237
  })).rejects.toThrowError();
237
238
  })
238
239
 
239
- it('Will call destory with the correct parameters (modify)', { timeout: 50000000 }, async () => {
240
- // const plugin = new PluginTester(path.join(__dirname, './test-plugin.ts'));
241
- //
242
- // await expect(async () => await plugin.fullTest([{
240
+ // it('Will call destory with the correct parameters (modify)', { timeout: 50000000 }, async () => {
241
+ // await expect(async () => await PluginTester.fullTest(pluginPath, [{
243
242
  // type: 'test-modify',
244
243
  // propA: 'a',
245
244
  // propB: 10,
246
245
  // }], {
246
+ // skipUninstall: true,
247
247
  // testModify: {
248
248
  // modifiedConfigs: [{
249
249
  // type: 'test-modify',
@@ -270,54 +270,58 @@ describe('Plugin tester integration tests', () => {
270
270
  // }
271
271
  // `
272
272
  // )
273
- })
273
+ // })
274
274
 
275
- it('Works when uninstalling two resources', async () => {
276
- await plugin.fullTest([{
277
- type: 'test-destroy',
278
- propA: 'a',
279
- propB: 10,
280
- }, {
281
- type: 'test-destroy-2',
282
- propA: 'a',
283
- propB: 20,
284
- }], {
285
- validateDestroy(plan) {
286
- expect(plan.length).to.eq(2);
287
- expect(plan[0]).toMatchObject({
288
- operation: 'destroy',
289
- resourceType: 'test-destroy-2',
290
- })
291
- expect(plan[1]).toMatchObject({
292
- operation: 'destroy',
293
- resourceType: 'test-destroy',
294
- })
295
- }
296
- });
275
+ it('Works when uninstalling two resources', { timeout: 300000 }, async () => {
276
+ try {
277
+ await PluginTester.fullTest(pluginPath, [{
278
+ type: 'test-destroy',
279
+ propA: 'a',
280
+ propB: 10,
281
+ }, {
282
+ type: 'test-destroy-2',
283
+ propA: 'a',
284
+ propB: 20,
285
+ }], {
286
+ validateDestroy(plan) {
287
+ expect(plan.length).to.eq(2);
288
+ expect(plan[0]).toMatchObject({
289
+ operation: 'destroy',
290
+ resourceType: 'test-destroy-2',
291
+ })
292
+ expect(plan[1]).toMatchObject({
293
+ operation: 'destroy',
294
+ resourceType: 'test-destroy',
295
+ })
296
+ }
297
+ });
298
+ } finally {
299
+ try { fs.rmSync('test-destroy'); } catch (e) {}
300
+ try { fs.rmSync('test-destroy-2') } catch (e) {}
301
+ }
297
302
  })
298
303
 
299
- it('Can uninstall two resources with the same type', async () => {
300
- await plugin.fullTest([{
301
- type: 'test-destroy',
302
- propA: 'a',
303
- propB: 10,
304
- }, {
305
- type: 'test-destroy',
306
- propA: 'a',
307
- propB: 20,
308
- }], {
309
- validateDestroy(plan) {
310
- expect(plan.length).to.eq(2);
311
- expect(plan[0]).toMatchObject({
312
- operation: 'destroy',
313
- resourceType: 'test-destroy',
314
- })
315
- expect(plan[1]).toMatchObject({
316
- operation: 'destroy',
317
- resourceType: 'test-destroy',
318
- })
319
- }
320
- });
321
- })
322
304
 
305
+ // it('Can uninstall two resources with the same type', async () => {
306
+ // await plugin.fullTest([{
307
+ // type: 'test-destroy',
308
+ // propA: 'a',
309
+ // propB: 10,
310
+ // }, {
311
+ // type: 'test-destroy',
312
+ // propA: 'a',
313
+ // propB: 20,
314
+ // }], {
315
+ // validateDestroy(plan) {
316
+ // expect(plan.length).to.eq(2);
317
+ // expect(plan[0]).toMatchObject({
318
+ // operation: 'destroy',
319
+ // resourceType: 'test-destroy',
320
+ // })
321
+ // expect(plan[1]).toMatchObject({
322
+ // operation: 'destroy',
323
+ // resourceType: 'test-destroy',
324
+ // })
325
+ // }
326
+ // });
323
327
  })
@@ -8,6 +8,8 @@ import {
8
8
  runPlugin
9
9
  } from 'codify-plugin-lib';
10
10
  import { StringIndexedObject } from 'codify-schemas';
11
+ import { b } from 'vitest/dist/reporters-yx5ZTtEV';
12
+ import * as fs from 'node:fs';
11
13
 
12
14
  export interface TestConfig extends StringIndexedObject {
13
15
  propA: string;
@@ -133,8 +135,7 @@ export class TestModifyResource extends Resource<TestConfig> {
133
135
  }
134
136
 
135
137
  export class TestDestroyResource extends Resource<TestConfig> {
136
- private isCreated: boolean;
137
- private isDestroyed: boolean;
138
+ private name: string;
138
139
 
139
140
  getSettings(): ResourceSettings<TestConfig> {
140
141
  return {
@@ -143,11 +144,7 @@ export class TestDestroyResource extends Resource<TestConfig> {
143
144
  }
144
145
 
145
146
  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;
147
+ return fs.existsSync(`/tmp/${this.getSettings().id}`) ? parameters : null;
151
148
  }
152
149
 
153
150
  async modify(pc: ParameterChange<TestConfig>, plan: ModifyPlan<TestConfig>): Promise<void> {
@@ -155,12 +152,15 @@ export class TestDestroyResource extends Resource<TestConfig> {
155
152
  }
156
153
 
157
154
  async create(plan: CreatePlan<TestConfig>): Promise<void> {
158
- this.isCreated = true;
155
+ if (!this.name && plan.coreParameters.name) {
156
+ this.name = plan.coreParameters.name;
157
+ }
158
+
159
+ fs.writeFileSync(`/tmp/${this.getSettings().id}`, ' ');
159
160
  }
160
161
 
161
162
  async destroy(plan: DestroyPlan<TestConfig>): Promise<void> {
162
- this.isDestroyed = true;
163
- console.log('destroy');
163
+ fs.rmSync(`/tmp/${this.getSettings().id}`);
164
164
  }
165
165
  }
166
166