Skip to content

Commit

Permalink
fix(cli): stack glob patterns only select one stack (#15071)
Browse files Browse the repository at this point in the history

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
otaviomacedo committed Jun 10, 2021
1 parent 632d518 commit fcd2a6e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
5 changes: 2 additions & 3 deletions packages/aws-cdk/lib/api/cxapp/cloud-assembly.ts
Expand Up @@ -3,6 +3,7 @@ import * as colors from 'colors/safe';
import * as minimatch from 'minimatch';
import * as semver from 'semver';
import { error, print, warning } from '../../logging';
import { flatten } from '../../util';
import { versionNumber } from '../../version';

export enum DefaultSelection {
Expand Down Expand Up @@ -135,9 +136,7 @@ export class CloudAssembly {
return false;
};

const matchedStacks = patterns
.map(pattern => stacks.find(matchingPattern(pattern)))
.filter(s => s != null) as cxapi.CloudFormationStackArtifact[];
const matchedStacks = flatten(patterns.map(pattern => stacks.filter(matchingPattern(pattern))));

return this.extendStacks(matchedStacks, stacks, extend);
}
Expand Down
13 changes: 13 additions & 0 deletions packages/aws-cdk/test/api/cloud-assembly.test.ts
Expand Up @@ -42,6 +42,19 @@ test('select all top level stacks in the presence of nested assemblies', async (
expect(x.stackIds).toContain('withouterrors');
});

test('select stacks by glob pattern', async () => {
// GIVEN
const cxasm = await testCloudAssembly();

// WHEN
const x = await cxasm.selectStacks({ patterns: ['with*'] }, { defaultBehavior: DefaultSelection.AllStacks });

// THEN
expect(x.stackCount).toBe(2);
expect(x.stackIds).toContain('witherrors');
expect(x.stackIds).toContain('withouterrors');
});

test('select behavior: all', async () => {
// GIVEN
const cxasm = await testCloudAssembly();
Expand Down

0 comments on commit fcd2a6e

Please sign in to comment.