Skip to content

Commit

Permalink
nested stack test
Browse files Browse the repository at this point in the history
  • Loading branch information
comcalvi committed Jan 3, 2024
1 parent c264294 commit 7ebc5ce
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions packages/aws-cdk/test/diff.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { CloudFormationStackArtifact } from '@aws-cdk/cx-api';
import { instanceMockFrom, MockCloudExecutable } from './util';
import { Deployments } from '../lib/api/deployments';
import { CdkToolkit } from '../lib/cdk-toolkit';
import * as cfn from '../lib/api/util/cloudformation';

let cloudExecutable: MockCloudExecutable;
let cloudFormation: jest.Mocked<Deployments>;
Expand Down Expand Up @@ -332,6 +333,46 @@ Resources

expect(exitCode).toBe(0);
});

test('diff falls back to non-changeset diff for nested stacks', async () => {
// GIVEN
const changeSetSpy = jest.spyOn(cfn, 'waitForChangeSet');
const buffer = new StringWritable();

// WHEN
const exitCode = await toolkit.diff({
stackNames: ['Parent'],
stream: buffer,
changeSet: true,
});

// THEN
const plainTextOutput = buffer.data.replace(/\x1B\[[0-?]*[ -/]*[@-~]/g, '')

Check warning

Code scanning / CodeQL

Overly permissive regular expression range Medium test

Suspicious character range that is equivalent to \[0-9:;<=>?\].
.replace(/[ \t]+$/mg, '');
expect(plainTextOutput.trim()).toEqual(`Stack Parent
Resources
[~] AWS::CloudFormation::Stack AdditionChild
└─ [~] Resources
└─ [~] .SomeResource:
└─ [+] Added: .Properties
[~] AWS::CloudFormation::Stack DeletionChild
└─ [~] Resources
└─ [~] .SomeResource:
└─ [-] Removed: .Properties
[~] AWS::CloudFormation::Stack ChangedChild
└─ [~] Resources
└─ [~] .SomeResource:
└─ [~] .Properties:
└─ [~] .Prop:
├─ [-] old-value
└─ [+] new-value
✨ Number of stacks with differences: 4`);

expect(exitCode).toBe(0);
expect(changeSetSpy).not.toHaveBeenCalled();
});
});

class StringWritable extends Writable {
Expand Down

0 comments on commit 7ebc5ce

Please sign in to comment.