Skip to content

Commit

Permalink
chore: some cli tests still rely on legacy behavior and fail in v2 (#…
Browse files Browse the repository at this point in the history
…15633)

A similar case to #15565 in which CLI tests assume stacks can be selected by ID and then fail when they land in v2-main. 

To detect this upstream (on `master`), I added an environment variable that explicitly disables the legacy behavior in cx-api and use it in the CLI tests to ensure that tests are executed without legacy behavior enabled.


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
Elad Ben-Israel authored Jul 18, 2021
1 parent 9c4e51c commit fc68df4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
7 changes: 6 additions & 1 deletion packages/aws-cdk/lib/api/cxapp/cloud-assembly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,15 @@ export class CloudAssembly {
private selectMatchingStacks(stacks: cxapi.CloudFormationStackArtifact[],
patterns: string[],
extend: ExtendedStackSelection = ExtendedStackSelection.None): StackCollection {

// cli tests use this to ensure tests do not depend on legacy behavior
// (otherwise they will fail in v2)
const disableLegacy = process.env.CXAPI_DISABLE_SELECT_BY_ID === '1';

const matchingPattern = (pattern: string) => (stack: cxapi.CloudFormationStackArtifact) => {
if (minimatch(stack.hierarchicalId, pattern)) {
return true;
} else if (stack.id === pattern && semver.major(versionNumber()) < 2) {
} else if (!disableLegacy && stack.id === pattern && semver.major(versionNumber()) < 2) {
warning('Selecting stack by identifier "%s". This identifier is deprecated and will be removed in v2. Please use "%s" instead.', colors.bold(stack.id), colors.bold(stack.hierarchicalId));
warning('Run "cdk ls" to see a list of all stack identifiers');
return true;
Expand Down
7 changes: 5 additions & 2 deletions packages/aws-cdk/test/api/cloud-assembly.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ import * as cxschema from '@aws-cdk/cloud-assembly-schema';
import { DefaultSelection } from '../../lib/api/cxapp/cloud-assembly';
import { MockCloudExecutable } from '../util';

// behave like v2
process.env.CXAPI_DISABLE_SELECT_BY_ID = '1';

test('do not throw when selecting stack without errors', async () => {
// GIVEN
const cxasm = await testCloudAssembly();

// WHEN
const selected = await cxasm.selectStacks( { patterns: ['withouterrors'] }, {
const selected = await cxasm.selectStacks( { patterns: ['withouterrorsNODEPATH'] }, {
defaultBehavior: DefaultSelection.AllStacks,
});
selected.processMetadataMessages();
Expand Down Expand Up @@ -100,7 +103,7 @@ test('select behavior: repeat', async () => {
const cxasm = await testCloudAssembly();

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

Expand Down

0 comments on commit fc68df4

Please sign in to comment.