From f2d77d336d535ef718813b4ed6b88b5d2af05cb9 Mon Sep 17 00:00:00 2001 From: kaizen3031593 <36202692+kaizen3031593@users.noreply.github.com> Date: Wed, 18 Aug 2021 20:17:08 -0400 Subject: [PATCH] revert(cli): 'deploy' and 'diff' silently does nothing when given unknown stack name (#16125) Broke integration tests when `synth`ing without providing a stack name reverts aws/aws-cdk#16073 --- packages/aws-cdk/lib/cdk-toolkit.ts | 10 +++------- packages/aws-cdk/test/cdk-toolkit.test.ts | 8 -------- packages/aws-cdk/test/diff.test.ts | 10 ---------- 3 files changed, 3 insertions(+), 25 deletions(-) diff --git a/packages/aws-cdk/lib/cdk-toolkit.ts b/packages/aws-cdk/lib/cdk-toolkit.ts index 8edefe66fc333..55ca1c6e24903 100644 --- a/packages/aws-cdk/lib/cdk-toolkit.ts +++ b/packages/aws-cdk/lib/cdk-toolkit.ts @@ -397,7 +397,7 @@ export class CdkToolkit { defaultBehavior: DefaultSelection.OnlySingle, }); - await this.validateStacks(stacks, selector.patterns); + await this.validateStacks(stacks); return stacks; } @@ -415,7 +415,7 @@ export class CdkToolkit { ? allStacks.filter(art => art.validateOnSynth ?? false) : new StackCollection(assembly, []); - await this.validateStacks(selectedForDiff.concat(autoValidateStacks), stackNames); + await this.validateStacks(selectedForDiff.concat(autoValidateStacks)); return selectedForDiff; } @@ -435,11 +435,7 @@ export class CdkToolkit { /** * Validate the stacks for errors and warnings according to the CLI's current settings */ - private async validateStacks(stacks: StackCollection, stackNames: string[]) { - if (stacks.stackCount == 0) { - throw new Error(`No stacks match the name(s) ${stackNames}`); - } - + private async validateStacks(stacks: StackCollection) { stacks.processMetadataMessages({ ignoreErrors: this.props.ignoreErrors, strict: this.props.strict, diff --git a/packages/aws-cdk/test/cdk-toolkit.test.ts b/packages/aws-cdk/test/cdk-toolkit.test.ts index f4573637ee5f4..8f53405b749e4 100644 --- a/packages/aws-cdk/test/cdk-toolkit.test.ts +++ b/packages/aws-cdk/test/cdk-toolkit.test.ts @@ -39,14 +39,6 @@ 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('makes correct CloudFormation calls', () => { test('without options', async () => { // GIVEN diff --git a/packages/aws-cdk/test/diff.test.ts b/packages/aws-cdk/test/diff.test.ts index e14ebe9bd9779..c1bcd11c78caa 100644 --- a/packages/aws-cdk/test/diff.test.ts +++ b/packages/aws-cdk/test/diff.test.ts @@ -121,16 +121,6 @@ test('throws an error during diffs on stack with error metadata', async () => { })).rejects.toThrow(/Found errors/); }); -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'); -}); - class StringWritable extends Writable { public data: string; private readonly _decoder: NodeStringDecoder;