@codifycli/plugin-test 1.0.0-beta1
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/.eslintignore +1 -0
- package/.eslintrc.json +30 -0
- package/.github/workflows/unit-test-ci.yaml +24 -0
- package/.prettierrc.json +1 -0
- package/CLAUDE.md +126 -0
- package/README.md +315 -0
- package/codify.json +9 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/plugin-process.d.ts +19 -0
- package/dist/plugin-process.js +119 -0
- package/dist/plugin-process.js.map +1 -0
- package/dist/plugin-tester.d.ts +20 -0
- package/dist/plugin-tester.js +210 -0
- package/dist/plugin-tester.js.map +1 -0
- package/dist/shell.d.ts +12 -0
- package/dist/shell.js +37 -0
- package/dist/shell.js.map +1 -0
- package/dist/spawn.d.ts +16 -0
- package/dist/spawn.js +71 -0
- package/dist/spawn.js.map +1 -0
- package/dist/test-utils.d.ts +44 -0
- package/dist/test-utils.js +123 -0
- package/dist/test-utils.js.map +1 -0
- package/dist/utils.d.ts +6 -0
- package/dist/utils.js +34 -0
- package/dist/utils.js.map +1 -0
- package/package.json +56 -0
- package/src/index.ts +3 -0
- package/src/plugin-process.ts +161 -0
- package/src/plugin-tester.ts +281 -0
- package/src/shell.ts +45 -0
- package/src/spawn.ts +101 -0
- package/src/test-utils.test.ts +83 -0
- package/src/test-utils.ts +147 -0
- package/src/utils.ts +42 -0
- package/test/plugin-tester.test.ts +350 -0
- package/test/test-plugin.ts +215 -0
- package/tsconfig.json +24 -0
- package/tsconfig.test.json +10 -0
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CreatePlan,
|
|
3
|
+
DestroyPlan,
|
|
4
|
+
ModifyPlan,
|
|
5
|
+
ParameterChange,
|
|
6
|
+
Plugin,
|
|
7
|
+
Resource,
|
|
8
|
+
ResourceSettings,
|
|
9
|
+
runPlugin
|
|
10
|
+
} from '@codifycli/plugin-core';
|
|
11
|
+
import { OS, StringIndexedObject } from '@codifycli/schemas';
|
|
12
|
+
import * as fs from 'node:fs';
|
|
13
|
+
|
|
14
|
+
export interface TestConfig extends StringIndexedObject {
|
|
15
|
+
propA: string;
|
|
16
|
+
propB: number;
|
|
17
|
+
propC: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface TestConfig2 extends StringIndexedObject {
|
|
21
|
+
propA: string;
|
|
22
|
+
propB: string[];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
export class TestResource extends Resource<TestConfig> {
|
|
27
|
+
getSettings(): ResourceSettings<TestConfig> {
|
|
28
|
+
return {
|
|
29
|
+
id: 'test',
|
|
30
|
+
operatingSystems: [OS.Linux, OS.Darwin],
|
|
31
|
+
allowMultiple: true,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
async refresh(parameters: Partial<TestConfig>): Promise<Partial<TestConfig> | null> {
|
|
36
|
+
if (parameters.propD) {
|
|
37
|
+
throw new Error('Prop D is included');
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return {
|
|
41
|
+
propA: 'a',
|
|
42
|
+
propB: 10,
|
|
43
|
+
propC: 'c',
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async create(plan: CreatePlan<TestConfig>): Promise<void> {
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async destroy(plan: DestroyPlan<TestConfig>): Promise<void> {
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export class TestResource2 extends Resource<TestConfig2> {
|
|
55
|
+
getSettings(): ResourceSettings<TestConfig2> {
|
|
56
|
+
return {
|
|
57
|
+
id: 'test2',
|
|
58
|
+
operatingSystems: [OS.Linux, OS.Darwin],
|
|
59
|
+
parameterSettings: {
|
|
60
|
+
propB: { type: 'array' }
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
async refresh(parameters: Partial<TestConfig2>): Promise<Partial<TestConfig2> | null> {
|
|
66
|
+
if (parameters.propD) {
|
|
67
|
+
throw new Error('Prop D is included');
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return {
|
|
71
|
+
propA: 'a',
|
|
72
|
+
propB: ['first', 'second', 'third']
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
async create(plan: CreatePlan<TestConfig2>): Promise<void> {
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
async destroy(plan: DestroyPlan<TestConfig2>): Promise<void> {
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export class TestUninstallResource extends Resource<TestConfig> {
|
|
84
|
+
first = true;
|
|
85
|
+
getSettings(): ResourceSettings<TestConfig> {
|
|
86
|
+
return {
|
|
87
|
+
id: 'test-uninstall',
|
|
88
|
+
operatingSystems: [OS.Linux, OS.Darwin],
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
async create(plan: CreatePlan<TestConfig>): Promise<void> {
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
async destroy(plan: DestroyPlan<TestConfig>): Promise<void> {
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
async refresh(parameters: Partial<TestConfig>): Promise<Array<Partial<TestConfig>> | Partial<TestConfig> | null> {
|
|
99
|
+
if (this.first) {
|
|
100
|
+
this.first = false;
|
|
101
|
+
return parameters;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export class TestModifyResource extends Resource<TestConfig> {
|
|
109
|
+
getSettings(): ResourceSettings<TestConfig> {
|
|
110
|
+
return {
|
|
111
|
+
id: 'test-modify',
|
|
112
|
+
operatingSystems: [OS.Linux, OS.Darwin],
|
|
113
|
+
parameterSettings: {
|
|
114
|
+
propA: { type: 'string', canModify: true },
|
|
115
|
+
propB: { type: 'string', canModify: true },
|
|
116
|
+
propC: { type: 'string', canModify: true }
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
async refresh(parameters: Partial<TestConfig>): Promise<Array<Partial<TestConfig>> | Partial<TestConfig> | null> {
|
|
122
|
+
if (parameters === null) {
|
|
123
|
+
return null;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (parameters.propA === 'Modify') {
|
|
127
|
+
parameters.propA = 'Modify__';
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return parameters;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
async modify(pc: ParameterChange<TestConfig>, plan: ModifyPlan<TestConfig>): Promise<void> {
|
|
134
|
+
return super.modify(pc, plan);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
async create(plan: CreatePlan<TestConfig>): Promise<void> {}
|
|
138
|
+
|
|
139
|
+
async destroy(plan: DestroyPlan<TestConfig>): Promise<void> {}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export class TestDestroyResource extends Resource<TestConfig> {
|
|
143
|
+
private name: string;
|
|
144
|
+
|
|
145
|
+
getSettings(): ResourceSettings<TestConfig> {
|
|
146
|
+
return {
|
|
147
|
+
id: 'test-destroy',
|
|
148
|
+
operatingSystems: [OS.Linux, OS.Darwin],
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
async refresh(parameters: Partial<TestConfig>): Promise<Array<Partial<TestConfig>> | Partial<TestConfig> | null> {
|
|
153
|
+
return fs.existsSync(`/tmp/${this.getSettings().id}`) ? parameters : null;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
async modify(pc: ParameterChange<TestConfig>, plan: ModifyPlan<TestConfig>): Promise<void> {
|
|
157
|
+
return super.modify(pc, plan);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
async create(plan: CreatePlan<TestConfig>): Promise<void> {
|
|
161
|
+
if (!this.name && plan.coreParameters.name) {
|
|
162
|
+
this.name = plan.coreParameters.name;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
fs.writeFileSync(`/tmp/${this.getSettings().id}`, ' ');
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
async destroy(plan: DestroyPlan<TestConfig>): Promise<void> {
|
|
169
|
+
fs.rmSync(`/tmp/${this.getSettings().id}`);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
export class WindowsOnlyResource extends Resource<TestConfig> {
|
|
174
|
+
private name: string;
|
|
175
|
+
|
|
176
|
+
getSettings(): ResourceSettings<TestConfig> {
|
|
177
|
+
return {
|
|
178
|
+
id: 'windows-only',
|
|
179
|
+
operatingSystems: [OS.Windows],
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
async refresh(parameters: Partial<TestConfig>): Promise<Array<Partial<TestConfig>> | Partial<TestConfig> | null> {
|
|
184
|
+
return {};
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
async modify(pc: ParameterChange<TestConfig>, plan: ModifyPlan<TestConfig>): Promise<void> {
|
|
188
|
+
return super.modify(pc, plan);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
async create(plan: CreatePlan<TestConfig>): Promise<void> {}
|
|
192
|
+
|
|
193
|
+
async destroy(plan: DestroyPlan<TestConfig>): Promise<void> {}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
export class TestDestroyResource2 extends TestDestroyResource {
|
|
197
|
+
getSettings(): ResourceSettings<TestConfig> {
|
|
198
|
+
return {
|
|
199
|
+
id: 'test-destroy-2',
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
runPlugin(Plugin.create(
|
|
205
|
+
'default',
|
|
206
|
+
[
|
|
207
|
+
new TestResource(),
|
|
208
|
+
new TestResource2(),
|
|
209
|
+
new TestUninstallResource(),
|
|
210
|
+
new TestModifyResource(),
|
|
211
|
+
new TestDestroyResource(),
|
|
212
|
+
new TestDestroyResource2(),
|
|
213
|
+
new WindowsOnlyResource(),
|
|
214
|
+
]
|
|
215
|
+
));
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"module": "NodeNext",
|
|
4
|
+
"moduleResolution": "NodeNext",
|
|
5
|
+
"sourceMap": true,
|
|
6
|
+
"esModuleInterop": true,
|
|
7
|
+
"resolveJsonModule": true,
|
|
8
|
+
"alwaysStrict": true,
|
|
9
|
+
"noImplicitAny": true,
|
|
10
|
+
"strictNullChecks": true,
|
|
11
|
+
"declaration": true,
|
|
12
|
+
"emitDecoratorMetadata": true,
|
|
13
|
+
"experimentalDecorators": true,
|
|
14
|
+
"rootDir": "src",
|
|
15
|
+
"outDir": "./dist",
|
|
16
|
+
},
|
|
17
|
+
"exclude": [
|
|
18
|
+
"node_modules",
|
|
19
|
+
"src/**/*.test.ts"
|
|
20
|
+
],
|
|
21
|
+
"include": [
|
|
22
|
+
"src/**/*.ts"
|
|
23
|
+
]
|
|
24
|
+
}
|