Skip to content

Commit

Permalink
Merge branch 'master' into assertions-hasoutput
Browse files Browse the repository at this point in the history
  • Loading branch information
kaizencc authored Sep 8, 2021
2 parents 9f3c090 + 74776f3 commit e3f8018
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
17 changes: 14 additions & 3 deletions packages/aws-cdk/lib/cdk-toolkit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,8 @@ export class CdkToolkit {
defaultBehavior: DefaultSelection.OnlySingle,
});

await this.validateStacks(stacks);
this.validateStacksSelected(stacks, selector.patterns);
this.validateStacks(stacks);

return stacks;
}
Expand All @@ -422,7 +423,8 @@ export class CdkToolkit {
? allStacks.filter(art => art.validateOnSynth ?? false)
: new StackCollection(assembly, []);

await this.validateStacks(selectedForDiff.concat(autoValidateStacks));
this.validateStacksSelected(selectedForDiff.concat(autoValidateStacks), stackNames);
this.validateStacks(selectedForDiff.concat(autoValidateStacks));

return selectedForDiff;
}
Expand All @@ -442,14 +444,23 @@ export class CdkToolkit {
/**
* Validate the stacks for errors and warnings according to the CLI's current settings
*/
private async validateStacks(stacks: StackCollection) {
private validateStacks(stacks: StackCollection) {
stacks.processMetadataMessages({
ignoreErrors: this.props.ignoreErrors,
strict: this.props.strict,
verbose: this.props.verbose,
});
}

/**
* Validate that if a user specified a stack name there exists at least 1 stack selected
*/
private validateStacksSelected(stacks: StackCollection, stackNames: string[]) {
if (stackNames.length != 0 && stacks.stackCount == 0) {
throw new Error(`No stacks match the name(s) ${stackNames}`);
}
}

/**
* Select a single stack by its name
*/
Expand Down
8 changes: 8 additions & 0 deletions packages/aws-cdk/test/cdk-toolkit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ function defaultToolkitSetup() {
}

describe('deploy', () => {
test('fails when no valid stack names are given', async () => {
// GIVEN
const toolkit = defaultToolkitSetup();

// WHEN
await expect(() => toolkit.deploy({ selector: { patterns: ['Test-Stack-D'] } })).rejects.toThrow('No stacks match the name(s) Test-Stack-D');
});

describe('with hotswap deployment', () => {
test("passes through the 'hotswap' option to CloudFormationDeployments.deployStack()", async () => {
// GIVEN
Expand Down
10 changes: 10 additions & 0 deletions packages/aws-cdk/test/diff.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,16 @@ test('exits with 1 with diffs and fail set to true', async () => {
expect(exitCode).toBe(1);
});

test('throws an error if no valid stack names given', async () => {
const buffer = new StringWritable();

// WHEN
await expect(() => toolkit.diff({
stackNames: ['X', 'Y', 'Z'],
stream: buffer,
})).rejects.toThrow('No stacks match the name(s) X,Y,Z');
});

test('exits with 1 with diff in first stack, but not in second stack and fail set to true', async () => {
// GIVEN
const buffer = new StringWritable();
Expand Down

0 comments on commit e3f8018

Please sign in to comment.