codify-plugin-test 0.0.46 → 0.0.48
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.
- package/dist/plugin-process.js +0 -3
- package/dist/plugin-process.js.map +1 -1
- package/dist/plugin-tester.js +16 -5
- package/dist/plugin-tester.js.map +1 -1
- package/dist/utils.d.ts +5 -0
- package/dist/utils.js +13 -0
- package/dist/utils.js.map +1 -0
- package/package.json +3 -3
- package/src/plugin-process.ts +0 -5
- package/src/plugin-tester.ts +34 -16
- package/src/utils.ts +19 -0
- package/test/plugin-tester.test.ts +20 -8
package/dist/plugin-process.js
CHANGED
|
@@ -16,13 +16,11 @@ export class PluginProcess {
|
|
|
16
16
|
throw new Error('A fully qualified path must be supplied to PluginTester');
|
|
17
17
|
}
|
|
18
18
|
const debug = (process.env.DEBUG) ? ['--inspect-brk=9221'] : [];
|
|
19
|
-
console.log(JSON.stringify({ debug }, null, 2));
|
|
20
19
|
this.childProcess = fork(pluginPath, [], {
|
|
21
20
|
env: { ...process.env },
|
|
22
21
|
execArgv: ['--import', 'tsx/esm', ...debug],
|
|
23
22
|
stdio: 'pipe',
|
|
24
23
|
});
|
|
25
|
-
console.log(process.env.DEBUG);
|
|
26
24
|
this.childProcess.stderr?.pipe(process.stderr);
|
|
27
25
|
this.childProcess.stdout?.pipe(process.stdout);
|
|
28
26
|
this.handleSudoRequests(this.childProcess);
|
|
@@ -76,7 +74,6 @@ export class PluginProcess {
|
|
|
76
74
|
throw new Error(`Invalid sudo request from plugin. ${JSON.stringify(sudoRequestValidator.errors, null, 2)}`);
|
|
77
75
|
}
|
|
78
76
|
const { command, options } = data;
|
|
79
|
-
console.log(`Running command with sudo: 'sudo ${command}'`);
|
|
80
77
|
const result = await sudoSpawn(command, options);
|
|
81
78
|
process.send({
|
|
82
79
|
cmd: MessageCmd.SUDO_REQUEST + '_Response',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin-process.js","sourceRoot":"","sources":["../src/plugin-process.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,KAAK,CAAC;AACtB,OAAO,EAGL,gBAAgB,EAEhB,UAAU,EACV,WAAW,EAEX,qBAAqB,EACtB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAA8B,IAAI,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC7E,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAElD,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC;IAC1B,MAAM,EAAE,IAAI;CACb,CAAC,CAAC;AAEH,MAAM,mBAAmB,GAAG,GAAG,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC;AAC1D,MAAM,oBAAoB,GAAG,GAAG,CAAC,OAAO,CAAC,qBAAqB,CAAC,CAAC;AAEhE,MAAM,OAAO,aAAa;IACxB,YAAY,CAAc;IAO1B,YAAY,UAAkB;QAC5B,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;YACjC,MAAM,IAAI,KAAK,CAAC,yDAAyD,CAAC,CAAC;QAC7E,CAAC;QAED,MAAM,KAAK,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,oBAAoB,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"plugin-process.js","sourceRoot":"","sources":["../src/plugin-process.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,KAAK,CAAC;AACtB,OAAO,EAGL,gBAAgB,EAEhB,UAAU,EACV,WAAW,EAEX,qBAAqB,EACtB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAA8B,IAAI,EAAE,KAAK,EAAE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3B,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;QAE3B,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE;YACzB,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;QAC/B,CAAC,CAAC,CAAA;QAEF,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE;YACzB,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;QAC/B,CAAC,CAAC,CAAA;QAEF,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QAC5B,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QAE5B,QAAQ,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,EAAE;YAC5B,OAAO,CAAC;gBACN,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;gBACrB,MAAM,EAAE,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC,WAAW,CAAC,KAAK;aAC7D,CAAC,CAAA;QACJ,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC"}
|
package/dist/plugin-tester.js
CHANGED
|
@@ -2,6 +2,7 @@ import chalk from 'chalk';
|
|
|
2
2
|
import { ResourceOperation, } from 'codify-schemas';
|
|
3
3
|
import unionBy from 'lodash.unionby';
|
|
4
4
|
import { PluginProcess } from './plugin-process.js';
|
|
5
|
+
import { splitUserConfig } from './utils.js';
|
|
5
6
|
export class PluginTester {
|
|
6
7
|
static async fullTest(pluginPath, configs, options) {
|
|
7
8
|
const ids = configs.map((c) => c.name ? `${c.type}.${c.name}` : c.type).join(', ');
|
|
@@ -16,7 +17,10 @@ export class PluginTester {
|
|
|
16
17
|
throw new Error(`The plugin does not support the following configs supplied:\n ${JSON.stringify(unsupportedConfigs, null, 2)}\n Initialize result: ${JSON.stringify(initializeResult)}`);
|
|
17
18
|
}
|
|
18
19
|
console.info(chalk.cyan('Testing validate...'));
|
|
19
|
-
const validate = await plugin.validate({ configs
|
|
20
|
+
const validate = await plugin.validate({ configs: configs.map((c) => {
|
|
21
|
+
const { coreParameters, parameters } = splitUserConfig(c);
|
|
22
|
+
return { core: coreParameters, parameters };
|
|
23
|
+
}) });
|
|
20
24
|
const invalidConfigs = validate.resourceValidations.filter((v) => !v.isValid);
|
|
21
25
|
if (invalidConfigs.length > 0) {
|
|
22
26
|
throw new Error(`The following configs did not validate:\n ${JSON.stringify(invalidConfigs, null, 2)}`);
|
|
@@ -24,8 +28,10 @@ export class PluginTester {
|
|
|
24
28
|
console.info(chalk.cyan('Testing plan...'));
|
|
25
29
|
const plans = [];
|
|
26
30
|
for (const config of configs) {
|
|
31
|
+
const { coreParameters, parameters } = splitUserConfig(config);
|
|
27
32
|
plans.push(await plugin.plan({
|
|
28
|
-
|
|
33
|
+
core: coreParameters,
|
|
34
|
+
desired: parameters,
|
|
29
35
|
isStateful: false,
|
|
30
36
|
state: undefined,
|
|
31
37
|
}));
|
|
@@ -51,7 +57,8 @@ export class PluginTester {
|
|
|
51
57
|
console.info(chalk.cyan('Testing import...'));
|
|
52
58
|
const importResults = [];
|
|
53
59
|
for (const config of configs) {
|
|
54
|
-
const
|
|
60
|
+
const { coreParameters, parameters } = splitUserConfig(config);
|
|
61
|
+
const importResult = await importPlugin.import({ core: coreParameters, parameters });
|
|
55
62
|
importResults.push(importResult);
|
|
56
63
|
}
|
|
57
64
|
if (options?.validateImport) {
|
|
@@ -67,8 +74,10 @@ export class PluginTester {
|
|
|
67
74
|
console.info(chalk.cyan('Testing modify...'));
|
|
68
75
|
const modifyPlans = [];
|
|
69
76
|
for (const config of options.testModify.modifiedConfigs) {
|
|
77
|
+
const { coreParameters, parameters } = splitUserConfig(config);
|
|
70
78
|
modifyPlans.push(await modifyPlugin.plan({
|
|
71
|
-
|
|
79
|
+
core: coreParameters,
|
|
80
|
+
desired: parameters,
|
|
72
81
|
isStateful: false,
|
|
73
82
|
state: undefined,
|
|
74
83
|
}));
|
|
@@ -104,9 +113,11 @@ ${JSON.stringify(modifyPlans, null, 2)}`);
|
|
|
104
113
|
console.info(chalk.cyan('Testing destroy...'));
|
|
105
114
|
const plans = [];
|
|
106
115
|
for (const config of configs) {
|
|
116
|
+
const { coreParameters, parameters } = splitUserConfig(config);
|
|
107
117
|
plans.push(await destroyPlugin.plan({
|
|
118
|
+
core: coreParameters,
|
|
108
119
|
isStateful: true,
|
|
109
|
-
state:
|
|
120
|
+
state: parameters,
|
|
110
121
|
desired: undefined
|
|
111
122
|
}));
|
|
112
123
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin-tester.js","sourceRoot":"","sources":["../src/plugin-tester.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAIL,iBAAiB,GAClB,MAAM,gBAAgB,CAAC;AACxB,OAAO,OAAO,MAAM,gBAAgB,CAAC;AAErC,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"plugin-tester.js","sourceRoot":"","sources":["../src/plugin-tester.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAIL,iBAAiB,GAClB,MAAM,gBAAgB,CAAC;AACxB,OAAO,OAAO,MAAM,gBAAgB,CAAC;AAErC,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAE7C,MAAM,OAAO,YAAY;IACvB,MAAM,CAAC,KAAK,CAAC,QAAQ,CACnB,UAAkB,EAClB,OAAyB,EACzB,OAUD;QACC,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,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,MAAM,EAAE,IAAI,CAAC,MAAM;iBACpB,CAAC,CAAC;YACL,CAAC;YAED,IAAI,OAAO,EAAE,eAAe,EAAE,CAAC;gBAC7B,MAAM,OAAO,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC;YACvC,CAAC;QACH,CAAC;gBAAS,CAAC;YACT,aAAa,CAAC,IAAI,EAAE,CAAC;QACvB,CAAC;IACH,CAAC;IAEO,MAAM,CAAC,iBAAiB,CAAC,OAAyB;QACxD,MAAM,gBAAgB,GAAG,IAAI,KAAK,EAAkB,CAAC;QAErD,MAAM,OAAO,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;QACpD,KAAK,MAAM,IAAI,IAAI,OAAO,EAAE,CAAC;YAC3B,MAAM,eAAe,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC;YAC/D,IAAI,eAAe,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBAC/B,eAAe,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,EAAE,GAAG,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,IAAI,IAAI,GAAG,CAAC,QAAQ,EAAE,CAAA,CAAC,CAAC,CAAC,CAAC;YAC7E,CAAC;YAED,gBAAgB,CAAC,IAAI,CAAC,GAAG,eAAe,CAAC,CAAC;QAC5C,CAAC;QAED,OAAO,gBAAgB,CAAC;IAC1B,CAAC;CACF"}
|
package/dist/utils.d.ts
ADDED
package/dist/utils.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export function splitUserConfig(config) {
|
|
2
|
+
const coreParameters = {
|
|
3
|
+
type: config.type,
|
|
4
|
+
...(config.name ? { name: config.name } : {}),
|
|
5
|
+
...(config.dependsOn ? { dependsOn: config.dependsOn } : {}),
|
|
6
|
+
};
|
|
7
|
+
const { type, name, dependsOn, ...parameters } = config;
|
|
8
|
+
return {
|
|
9
|
+
parameters: parameters,
|
|
10
|
+
coreParameters,
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,eAAe,CAC7B,MAA0B;IAE1B,MAAM,cAAc,GAAG;QACrB,IAAI,EAAE,MAAM,CAAC,IAAI;QACjB,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC7C,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,MAAM,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAC7D,CAAC;IAGF,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,GAAG,UAAU,EAAE,GAAG,MAAM,CAAC;IAExD,OAAO;QACL,UAAU,EAAE,UAAe;QAC3B,cAAc;KACf,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "codify-plugin-test",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.48",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"dependencies": {
|
|
16
16
|
"ajv": "^8.12.0",
|
|
17
17
|
"ajv-formats": "^3.0.1",
|
|
18
|
-
"codify-schemas": "1.0.
|
|
18
|
+
"codify-schemas": "1.0.61",
|
|
19
19
|
"lodash.matches": "^4.6.0",
|
|
20
20
|
"lodash.differencewith": "4.5.0",
|
|
21
21
|
"lodash.unionby": "^4.8.0",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"tsx": "^4.7.3",
|
|
37
37
|
"typescript": "^5",
|
|
38
38
|
"vitest": "^1.4.0",
|
|
39
|
-
"codify-plugin-lib": "1.0.
|
|
39
|
+
"codify-plugin-lib": "1.0.130"
|
|
40
40
|
},
|
|
41
41
|
"engines": {
|
|
42
42
|
"node": ">=18.0.0"
|
package/src/plugin-process.ts
CHANGED
|
@@ -36,7 +36,6 @@ export class PluginProcess {
|
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
const debug = (process.env.DEBUG) ? ['--inspect-brk=9221'] : [];
|
|
39
|
-
console.log(JSON.stringify({ debug }, null, 2))
|
|
40
39
|
|
|
41
40
|
this.childProcess = fork(
|
|
42
41
|
pluginPath,
|
|
@@ -50,8 +49,6 @@ export class PluginProcess {
|
|
|
50
49
|
},
|
|
51
50
|
)
|
|
52
51
|
|
|
53
|
-
console.log(process.env.DEBUG);
|
|
54
|
-
|
|
55
52
|
this.childProcess.stderr?.pipe(process.stderr);
|
|
56
53
|
this.childProcess.stdout?.pipe(process.stdout);
|
|
57
54
|
|
|
@@ -116,8 +113,6 @@ export class PluginProcess {
|
|
|
116
113
|
}
|
|
117
114
|
|
|
118
115
|
const { command, options } = data as unknown as SudoRequestData;
|
|
119
|
-
|
|
120
|
-
console.log(`Running command with sudo: 'sudo ${command}'`)
|
|
121
116
|
const result = await sudoSpawn(command, options);
|
|
122
117
|
|
|
123
118
|
process.send(<IpcMessageV2>{
|
package/src/plugin-tester.ts
CHANGED
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
import unionBy from 'lodash.unionby';
|
|
9
9
|
|
|
10
10
|
import { PluginProcess } from './plugin-process.js';
|
|
11
|
+
import { splitUserConfig } from './utils.js';
|
|
11
12
|
|
|
12
13
|
export class PluginTester {
|
|
13
14
|
static async fullTest(
|
|
@@ -15,6 +16,7 @@ export class PluginTester {
|
|
|
15
16
|
configs: ResourceConfig[],
|
|
16
17
|
options?: {
|
|
17
18
|
skipUninstall?: boolean,
|
|
19
|
+
skipImport?: boolean,
|
|
18
20
|
validatePlan?: (plans: PlanResponseData[]) => Promise<void> | void
|
|
19
21
|
validateApply?: (plans: PlanResponseData[]) => Promise<void> | void,
|
|
20
22
|
validateDestroy?: (plans: PlanResponseData[]) => Promise<void> | void,
|
|
@@ -45,7 +47,10 @@ export class PluginTester {
|
|
|
45
47
|
}
|
|
46
48
|
|
|
47
49
|
console.info(chalk.cyan('Testing validate...'))
|
|
48
|
-
const validate = await plugin.validate({ configs
|
|
50
|
+
const validate = await plugin.validate({ configs: configs.map((c) => {
|
|
51
|
+
const { coreParameters, parameters } = splitUserConfig(c)
|
|
52
|
+
return { core: coreParameters, parameters };
|
|
53
|
+
}) });
|
|
49
54
|
|
|
50
55
|
const invalidConfigs = validate.resourceValidations.filter((v) => !v.isValid)
|
|
51
56
|
if (invalidConfigs.length > 0) {
|
|
@@ -55,8 +60,11 @@ export class PluginTester {
|
|
|
55
60
|
console.info(chalk.cyan('Testing plan...'))
|
|
56
61
|
const plans = [];
|
|
57
62
|
for (const config of configs) {
|
|
63
|
+
const { coreParameters, parameters } = splitUserConfig(config);
|
|
64
|
+
|
|
58
65
|
plans.push(await plugin.plan({
|
|
59
|
-
|
|
66
|
+
core: coreParameters,
|
|
67
|
+
desired: parameters,
|
|
60
68
|
isStateful: false,
|
|
61
69
|
state: undefined,
|
|
62
70
|
}));
|
|
@@ -80,21 +88,25 @@ export class PluginTester {
|
|
|
80
88
|
plugin.kill();
|
|
81
89
|
}
|
|
82
90
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
91
|
+
if (!options?.skipImport) {
|
|
92
|
+
const importPlugin = new PluginProcess(pluginPath);
|
|
93
|
+
try {
|
|
94
|
+
console.info(chalk.cyan('Testing import...'))
|
|
86
95
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
importResults.push(importResult);
|
|
91
|
-
}
|
|
96
|
+
const importResults = [];
|
|
97
|
+
for (const config of configs) {
|
|
98
|
+
const { coreParameters, parameters } = splitUserConfig(config);
|
|
92
99
|
|
|
93
|
-
|
|
94
|
-
|
|
100
|
+
const importResult = await importPlugin.import({ core: coreParameters, parameters })
|
|
101
|
+
importResults.push(importResult);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (options?.validateImport) {
|
|
105
|
+
await options.validateImport(importResults.map((r) => r.result[0]));
|
|
106
|
+
}
|
|
107
|
+
} finally {
|
|
108
|
+
importPlugin.kill();
|
|
95
109
|
}
|
|
96
|
-
} finally {
|
|
97
|
-
importPlugin.kill();
|
|
98
110
|
}
|
|
99
111
|
|
|
100
112
|
if (options?.testModify) {
|
|
@@ -105,8 +117,11 @@ export class PluginTester {
|
|
|
105
117
|
|
|
106
118
|
const modifyPlans = [];
|
|
107
119
|
for (const config of options.testModify.modifiedConfigs) {
|
|
120
|
+
const { coreParameters, parameters } = splitUserConfig(config);
|
|
121
|
+
|
|
108
122
|
modifyPlans.push(await modifyPlugin.plan({
|
|
109
|
-
|
|
123
|
+
core: coreParameters,
|
|
124
|
+
desired: parameters,
|
|
110
125
|
isStateful: false,
|
|
111
126
|
state: undefined,
|
|
112
127
|
}));
|
|
@@ -153,9 +168,12 @@ ${JSON.stringify(modifyPlans, null, 2)}`)
|
|
|
153
168
|
|
|
154
169
|
const plans = [];
|
|
155
170
|
for (const config of configs) {
|
|
171
|
+
const { coreParameters, parameters } = splitUserConfig(config);
|
|
172
|
+
|
|
156
173
|
plans.push(await destroyPlugin.plan({
|
|
174
|
+
core: coreParameters,
|
|
157
175
|
isStateful: true,
|
|
158
|
-
state:
|
|
176
|
+
state: parameters,
|
|
159
177
|
desired: undefined
|
|
160
178
|
}))
|
|
161
179
|
}
|
package/src/utils.ts
ADDED
|
@@ -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
|
+
}
|
|
@@ -41,10 +41,14 @@ describe('Plugin tester integration tests', () => {
|
|
|
41
41
|
it('Can validate a config', async () => {
|
|
42
42
|
const result = await plugin.validate({
|
|
43
43
|
configs: [{
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
44
|
+
core: {
|
|
45
|
+
type: 'test',
|
|
46
|
+
},
|
|
47
|
+
parameters: {
|
|
48
|
+
propA: 'a',
|
|
49
|
+
propB: 2,
|
|
50
|
+
propC: 'c',
|
|
51
|
+
}
|
|
48
52
|
}]
|
|
49
53
|
})
|
|
50
54
|
|
|
@@ -55,8 +59,10 @@ describe('Plugin tester integration tests', () => {
|
|
|
55
59
|
|
|
56
60
|
it('Can generate a plan', async () => {
|
|
57
61
|
const result = await plugin.plan({
|
|
58
|
-
|
|
62
|
+
core: {
|
|
59
63
|
type: 'test',
|
|
64
|
+
},
|
|
65
|
+
desired: {
|
|
60
66
|
propA: 'a',
|
|
61
67
|
propB: 10,
|
|
62
68
|
propC: 'c',
|
|
@@ -74,8 +80,10 @@ describe('Plugin tester integration tests', () => {
|
|
|
74
80
|
|
|
75
81
|
it('Can generate a plan', async () => {
|
|
76
82
|
const result = await plugin.plan({
|
|
77
|
-
|
|
83
|
+
core: {
|
|
78
84
|
type: 'test',
|
|
85
|
+
},
|
|
86
|
+
desired: {
|
|
79
87
|
propA: 'a',
|
|
80
88
|
propB: 10,
|
|
81
89
|
propC: 'c',
|
|
@@ -93,8 +101,10 @@ describe('Plugin tester integration tests', () => {
|
|
|
93
101
|
|
|
94
102
|
it('Can apply a plan', async () => {
|
|
95
103
|
const plan = await plugin.plan({
|
|
96
|
-
|
|
104
|
+
core: {
|
|
97
105
|
type: 'test',
|
|
106
|
+
},
|
|
107
|
+
desired: {
|
|
98
108
|
propA: 'a',
|
|
99
109
|
propB: 10,
|
|
100
110
|
propC: 'c',
|
|
@@ -109,8 +119,10 @@ describe('Plugin tester integration tests', () => {
|
|
|
109
119
|
|
|
110
120
|
it('Handles errors that are thrown', async () => {
|
|
111
121
|
expect(async () => plugin.plan({
|
|
112
|
-
|
|
122
|
+
core: {
|
|
113
123
|
type: 'test',
|
|
124
|
+
},
|
|
125
|
+
desired: {
|
|
114
126
|
propA: 'a',
|
|
115
127
|
propB: 10,
|
|
116
128
|
propC: 'c',
|