Skip to content

Commit 7df9e6c

Browse files
committed
feat: Updated to latest schemas which separates core and parameters
1 parent 9403130 commit 7df9e6c

4 files changed

Lines changed: 62 additions & 16 deletions

File tree

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "codify-plugin-test",
3-
"version": "0.0.46",
3+
"version": "0.0.47",
44
"description": "",
55
"main": "dist/index.js",
66
"typings": "dist/index.d.ts",
@@ -15,7 +15,7 @@
1515
"dependencies": {
1616
"ajv": "^8.12.0",
1717
"ajv-formats": "^3.0.1",
18-
"codify-schemas": "1.0.54",
18+
"codify-schemas": "1.0.61",
1919
"lodash.matches": "^4.6.0",
2020
"lodash.differencewith": "4.5.0",
2121
"lodash.unionby": "^4.8.0",
@@ -36,7 +36,7 @@
3636
"tsx": "^4.7.3",
3737
"typescript": "^5",
3838
"vitest": "^1.4.0",
39-
"codify-plugin-lib": "1.0.117"
39+
"codify-plugin-lib": "1.0.130"
4040
},
4141
"engines": {
4242
"node": ">=18.0.0"

src/plugin-tester.ts

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
import unionBy from 'lodash.unionby';
99

1010
import { PluginProcess } from './plugin-process.js';
11+
import { splitUserConfig } from './utils.js';
1112

1213
export class PluginTester {
1314
static async fullTest(
@@ -45,7 +46,10 @@ export class PluginTester {
4546
}
4647

4748
console.info(chalk.cyan('Testing validate...'))
48-
const validate = await plugin.validate({ configs });
49+
const validate = await plugin.validate({ configs: configs.map((c) => {
50+
const { coreParameters, parameters } = splitUserConfig(c)
51+
return { core: coreParameters, parameters };
52+
}) });
4953

5054
const invalidConfigs = validate.resourceValidations.filter((v) => !v.isValid)
5155
if (invalidConfigs.length > 0) {
@@ -55,8 +59,11 @@ export class PluginTester {
5559
console.info(chalk.cyan('Testing plan...'))
5660
const plans = [];
5761
for (const config of configs) {
62+
const { coreParameters, parameters } = splitUserConfig(config);
63+
5864
plans.push(await plugin.plan({
59-
desired: config,
65+
core: coreParameters,
66+
desired: parameters,
6067
isStateful: false,
6168
state: undefined,
6269
}));
@@ -86,7 +93,9 @@ export class PluginTester {
8693

8794
const importResults = [];
8895
for (const config of configs) {
89-
const importResult = await importPlugin.import({ config })
96+
const { coreParameters, parameters } = splitUserConfig(config);
97+
98+
const importResult = await importPlugin.import({ core: coreParameters, parameters })
9099
importResults.push(importResult);
91100
}
92101

@@ -105,8 +114,11 @@ export class PluginTester {
105114

106115
const modifyPlans = [];
107116
for (const config of options.testModify.modifiedConfigs) {
117+
const { coreParameters, parameters } = splitUserConfig(config);
118+
108119
modifyPlans.push(await modifyPlugin.plan({
109-
desired: config,
120+
core: coreParameters,
121+
desired: parameters,
110122
isStateful: false,
111123
state: undefined,
112124
}));
@@ -153,9 +165,12 @@ ${JSON.stringify(modifyPlans, null, 2)}`)
153165

154166
const plans = [];
155167
for (const config of configs) {
168+
const { coreParameters, parameters } = splitUserConfig(config);
169+
156170
plans.push(await destroyPlugin.plan({
171+
core: coreParameters,
157172
isStateful: true,
158-
state: config,
173+
state: parameters,
159174
desired: undefined
160175
}))
161176
}

src/utils.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { ResourceConfig, StringIndexedObject } from 'codify-schemas';
2+
3+
export function splitUserConfig<T extends StringIndexedObject>(
4+
config: ResourceConfig & T
5+
): { parameters: T; coreParameters: ResourceConfig } {
6+
const coreParameters = {
7+
type: config.type,
8+
...(config.name ? { name: config.name } : {}),
9+
...(config.dependsOn ? { dependsOn: config.dependsOn } : {}),
10+
};
11+
12+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
13+
const { type, name, dependsOn, ...parameters } = config;
14+
15+
return {
16+
parameters: parameters as T,
17+
coreParameters,
18+
};
19+
}

test/plugin-tester.test.ts

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,14 @@ describe('Plugin tester integration tests', () => {
4141
it('Can validate a config', async () => {
4242
const result = await plugin.validate({
4343
configs: [{
44-
type: 'test',
45-
propA: 'a',
46-
propB: 2,
47-
propC: 'c',
44+
core: {
45+
type: 'test',
46+
},
47+
parameters: {
48+
propA: 'a',
49+
propB: 2,
50+
propC: 'c',
51+
}
4852
}]
4953
})
5054

@@ -55,8 +59,10 @@ describe('Plugin tester integration tests', () => {
5559

5660
it('Can generate a plan', async () => {
5761
const result = await plugin.plan({
58-
desired: {
62+
core: {
5963
type: 'test',
64+
},
65+
desired: {
6066
propA: 'a',
6167
propB: 10,
6268
propC: 'c',
@@ -74,8 +80,10 @@ describe('Plugin tester integration tests', () => {
7480

7581
it('Can generate a plan', async () => {
7682
const result = await plugin.plan({
77-
desired: {
83+
core: {
7884
type: 'test',
85+
},
86+
desired: {
7987
propA: 'a',
8088
propB: 10,
8189
propC: 'c',
@@ -93,8 +101,10 @@ describe('Plugin tester integration tests', () => {
93101

94102
it('Can apply a plan', async () => {
95103
const plan = await plugin.plan({
96-
desired: {
104+
core: {
97105
type: 'test',
106+
},
107+
desired: {
98108
propA: 'a',
99109
propB: 10,
100110
propC: 'c',
@@ -109,8 +119,10 @@ describe('Plugin tester integration tests', () => {
109119

110120
it('Handles errors that are thrown', async () => {
111121
expect(async () => plugin.plan({
112-
desired: {
122+
core: {
113123
type: 'test',
124+
},
125+
desired: {
114126
propA: 'a',
115127
propB: 10,
116128
propC: 'c',

0 commit comments

Comments
 (0)