Skip to content

Commit

Permalink
cli-integ-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
go-to-k committed Oct 12, 2023
1 parent 6b4dbe2 commit 3dbc266
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1209,6 +1209,13 @@ integTest('hotswap deployment supports Lambda function\'s description and enviro
expect(deployOutput).toContain(`Lambda Function '${functionName}' hotswapped!`);
}));

integTest('cdk destroy fails when the stacks do not exist', withDefaultFixture(async (fixture) => {
const nonExistingStackName1 = 'non-existing-stack-1';
const nonExistingStackName2 = 'non-existing-stack-2';

await expect(fixture.cdkDestroy([nonExistingStackName1, nonExistingStackName2])).rejects.toThrow('exited with error');
}));

async function listChildren(parent: string, pred: (x: string) => Promise<boolean>) {
const ret = new Array<string>();
for (const child of await fs.readdir(parent, { encoding: 'utf-8' })) {
Expand Down
2 changes: 1 addition & 1 deletion packages/aws-cdk/lib/cdk-toolkit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,7 @@ export class CdkToolkit {
minimatch(stack.hierarchicalId, pattern) || (stack.id === pattern && semver.major(versionNumber()) < 2),
));
if (notExistPatterns.length > 0) {
throw new Error(`Stacks not exist: ${notExistPatterns.join(', ')}`);
throw new Error(`Cannot run cdk destroy on stack(s) ${selector.patterns.join(', ')}. ${notExistPatterns.join(', ')} not exist.`);
}

return stacks;
Expand Down
2 changes: 1 addition & 1 deletion packages/aws-cdk/test/cdk-toolkit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ describe('destroy', () => {
force: true,
fromDeploy: true,
});
}).rejects.toThrowError('Stacks not exist: Test-Stack-X, Test-Stack-Y');
}).rejects.toThrowError('Cannot run cdk destroy on stack(s) Test-Stack-A/Test-Stack-C, Test-Stack-X, Test-Stack-Y. Test-Stack-X, Test-Stack-Y not exist.');
});
});

Expand Down

0 comments on commit 3dbc266

Please sign in to comment.