Skip to content

Commit df76193

Browse files
committed
fix: Fixed tests and bug fixes
1 parent a28068d commit df76193

File tree

18 files changed

+111
-50
lines changed

18 files changed

+111
-50
lines changed

package-lock.json

Lines changed: 5 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"@types/semver": "^7.5.4",
4343
"@types/strip-ansi": "^5.2.1",
4444
"@typescript-eslint/eslint-plugin": "^8.16.0",
45-
"codify-plugin-lib": "^1.0.140",
45+
"codify-plugin-lib": "^1.0.151",
4646
"esbuild": "^0.24.0",
4747
"esbuild-plugin-copy": "^2.1.1",
4848
"eslint": "^8.51.0",

src/entities/resource-info.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ export class ResourceInfo implements GetResourceInfoResponseData {
2020
requiredParameters: null | string[];
2121
} | undefined;
2222

23-
allowMultiple?: {
24-
identifyingParameters: string[];
25-
};
23+
allowMultiple!: boolean;
2624

2725
private parametersCache?: ParameterInfo[];
2826

src/orchestrators/destroy.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ export class DestroyOrchestrator {
5050
const plan = await ctx.subprocess(ProcessName.PLAN, () =>
5151
pluginManager.plan(uninstallProject)
5252
)
53+
54+
plan.sortByEvalOrder(project.evaluationOrder);
55+
uninstallProject.removeNoopFromEvaluationOrder(plan);
56+
5357
reporter.displayPlan(plan);
5458

5559
// Short circuit and exit if every change is NOOP

src/plugins/plugin-manager.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,11 +198,35 @@ export class PluginManager {
198198

199199
/** Clean up any stranglers and child processes if the CLI is killed */
200200
private registerKillListeners(plugins: Plugin[]) {
201-
const kill = (code) => {
201+
const kill = (code: number | string) => {
202202
plugins.forEach((p) => {
203203
p.kill()
204204
})
205-
process.exit(code);
205+
206+
let exitCode = 0;
207+
switch (code) {
208+
case 'SIGTERM': {
209+
exitCode = 143;
210+
break;
211+
}
212+
213+
case 'SIGHUP': {
214+
exitCode = 129;
215+
break;
216+
}
217+
218+
case 'SIGINT': {
219+
exitCode = 130;
220+
break;
221+
}
222+
}
223+
224+
const parsedCode = typeof code === 'string' ? Number.parseInt(code, 10) : code;
225+
if (Number.isInteger(parsedCode)) {
226+
exitCode = parsedCode;
227+
}
228+
229+
process.exit(exitCode);
206230
}
207231

208232
process.on('exit', kill)

src/plugins/plugin.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,11 @@ export interface IPlugin {
3131
initialize(secureMode: boolean): Promise<InitializeResponseData>;
3232
validate(configs: ResourceConfig[]): Promise<ValidateResponseData>;
3333
getResourceInfo(type: string): Promise<GetResourceInfoResponseData>;
34+
match(resource: ResourceConfig, array: ResourceConfig[]): Promise<MatchResponseData>;
3435
import(config: ResourceJson): Promise<ImportResponseData>;
3536
plan(request: PlanRequestData): Promise<ResourcePlan>;
3637
apply(plan: ResourcePlan): Promise<void>;
38+
kill(): void;
3739
}
3840

3941
export class Plugin implements IPlugin {

src/utils/file-modification-calculator.test.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ describe('File modification calculator tests', () => {
5252
const result = await calculator.calculate([{
5353
modification: ModificationType.INSERT_OR_UPDATE,
5454
resource: modifiedResource,
55-
}])
55+
}], match)
5656

5757
console.log(result)
5858
console.log(result.diff)
@@ -89,7 +89,7 @@ describe('File modification calculator tests', () => {
8989
const result = await calculator.calculate([{
9090
modification: ModificationType.DELETE,
9191
resource: modifiedResource,
92-
}])
92+
}], match)
9393

9494
expect(result.newFile).to.eq('[\n' +
9595
' {\n' +
@@ -134,7 +134,7 @@ describe('File modification calculator tests', () => {
134134
const result = await calculator.calculate([{
135135
modification: ModificationType.DELETE,
136136
resource: modifiedResource,
137-
}])
137+
}], match)
138138

139139
expect(result.newFile).to.eq('[\n' +
140140
' {\n' +
@@ -175,7 +175,7 @@ describe('File modification calculator tests', () => {
175175
const result = await calculator.calculate([{
176176
modification: ModificationType.DELETE,
177177
resource: modifiedResource,
178-
}])
178+
}], match)
179179

180180
expect(result.newFile).to.eq('[\n' +
181181
' { "type": "resource2", "param2": ["a", "b", "c"] },\n' +
@@ -221,7 +221,7 @@ describe('File modification calculator tests', () => {
221221
const result = await calculator.calculate([{
222222
modification: ModificationType.INSERT_OR_UPDATE,
223223
resource: modifiedResource,
224-
}])
224+
}], match)
225225

226226
expect(result.newFile).to.eq('[\n' +
227227
' {\n' +
@@ -298,7 +298,7 @@ describe('File modification calculator tests', () => {
298298
const result = await calculator.calculate([{
299299
modification: ModificationType.INSERT_OR_UPDATE,
300300
resource: modifiedResource,
301-
}])
301+
}], match)
302302

303303
expect(result.newFile).to.eq('[\n' +
304304
' {\n' +
@@ -356,7 +356,7 @@ describe('File modification calculator tests', () => {
356356
const result = await calculator.calculate([{
357357
modification: ModificationType.INSERT_OR_UPDATE,
358358
resource: modifiedResource,
359-
}])
359+
}], match)
360360

361361
expect(result.newFile).to.eq('[\n' +
362362
' {\n' +
@@ -415,7 +415,7 @@ describe('File modification calculator tests', () => {
415415
}, {
416416
modification: ModificationType.INSERT_OR_UPDATE,
417417
resource: modifiedResource2,
418-
}])
418+
}], match)
419419

420420
expect(result.newFile).to.eq('[\n' +
421421
' {\n' +
@@ -491,7 +491,7 @@ describe('File modification calculator tests', () => {
491491
const result = await calculator.calculate([{
492492
modification: ModificationType.INSERT_OR_UPDATE,
493493
resource: modifiedResource,
494-
}])
494+
}], match)
495495

496496
// TODO: The result is currently wrong need to fix
497497
console.log(result);
@@ -522,6 +522,10 @@ describe('File modification calculator tests', () => {
522522
})
523523
})
524524

525+
async function match(resource: ResourceConfig, array: ResourceConfig[]): Promise<number> {
526+
return array.findIndex((r) => resource.isSame(r.type, r.name));
527+
}
528+
525529
function generateResourceInfo(type: string, requiredParameters?: string[]): ResourceInfo {
526530
return ResourceInfo.fromResponseData({
527531
plugin: 'plugin',

src/utils/file-modification-calculator.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,11 @@ export class FileModificationCalculator {
232232
const source = sourceMap.lookup(`/${sourceIndex}/${key}`);
233233
if ((Array.isArray(value) || typeof value === 'object') && source && source.value.line === source.valueEnd.line) {
234234
const { value, valueEnd } = parsedSourceMap.lookup(`#/${key}`)!
235-
content = this.splice(content, value.position, valueEnd.position - value.position, JSON.stringify(parsedContent[key], null, ' '))
235+
content = this.splice(
236+
content,
237+
value.position, valueEnd.position - value.position,
238+
JSON.stringify(parsedContent[key]).replaceAll('\n', '').replaceAll(/}$/g, ' }')
239+
)
236240
}
237241
}
238242

test/orchestrator/apply/apply.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ describe('Apply orchestrator tests', () => {
8989
expect(MockOs.get('xcode-tools')).toMatchObject({})
9090
});
9191

92-
it('Can apply a resource (recreate)', async () => {
92+
it('Can apply a resource (re-create)', async () => {
9393
const reporter = new MockReporter({
9494
validatePlan(plan: Plan) {
9595
// As always these values are from recreate.codify.json
@@ -99,8 +99,8 @@ describe('Apply orchestrator tests', () => {
9999
expect.objectContaining({
100100
name: 'propA',
101101
previousValue: 'current',
102-
newValue: 'newPropA',
103-
operation: 'modify'
102+
newValue: 'current',
103+
operation: 'noop'
104104
}),
105105
expect.objectContaining({
106106
name: 'propB',
@@ -139,7 +139,7 @@ describe('Apply orchestrator tests', () => {
139139
}, reporter)
140140

141141
expect(MockOs.get('mock')).to.toMatchObject({
142-
propA: 'newPropA',
142+
propA: 'current',
143143
propB: 0,
144144
array: ['a', 'b'],
145145
directory: '/home'
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
[
22
{ "type": "project", "plugins": { "default": "./test/orchestrator/mocks/plugin.ts" } },
3-
{ "type": "mock", "propA": "newPropA", "propB": 0, "directory": "/home", "array": ["a", "b"] }
3+
{ "type": "mock", "propA": "current", "propB": 0, "directory": "/home", "array": ["a", "b"] }
44
]

0 commit comments

Comments
 (0)