Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(integ-runner): update workflow doesn't support resource replacement #24720

Merged
merged 3 commits into from
Mar 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 23 additions & 5 deletions packages/@aws-cdk/integ-runner/lib/runner/integ-test-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,23 +285,41 @@ export class IntegTestRunner extends IntegRunner {
lookups: this.expectedTestSuite?.enableLookups,
});
}
// now deploy the "actual" test. If there are any assertions
// deploy the assertion stack as well
// now deploy the "actual" test.
this.cdk.deploy({
...deployArgs,
lookups: this.actualTestSuite.enableLookups,
stacks: [
...actualTestCase.stacks,
...actualTestCase.assertionStack ? [actualTestCase.assertionStack] : [],
],
rollback: false,
output: path.relative(this.directory, this.cdkOutDir),
...actualTestCase?.cdkCommandOptions?.deploy?.args,
...actualTestCase.assertionStack ? { outputsFile: path.relative(this.directory, path.join(this.cdkOutDir, 'assertion-results.json')) } : undefined,
context: this.getContext(actualTestCase?.cdkCommandOptions?.deploy?.args?.context),
app: this.cdkApp,
});

// If there are any assertions
// deploy the assertion stack as well
// This is separate from the above deployment because we want to
// set `rollback: false`. This allows the assertion stack to deploy all the
// assertions instead of failing at the first failed assertion
// combining it with the above deployment would prevent any replacement updates
if (actualTestCase.assertionStack) {
this.cdk.deploy({
...deployArgs,
lookups: this.actualTestSuite.enableLookups,
stacks: [
actualTestCase.assertionStack,
],
rollback: false,
output: path.relative(this.directory, this.cdkOutDir),
...actualTestCase?.cdkCommandOptions?.deploy?.args,
outputsFile: path.relative(this.directory, path.join(this.cdkOutDir, 'assertion-results.json')),
context: this.getContext(actualTestCase?.cdkCommandOptions?.deploy?.args?.context),
app: this.cdkApp,
});
}

if (actualTestCase.hooks?.postDeploy) {
actualTestCase.hooks.postDeploy.forEach(cmd => {
exec(chunks(cmd), {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ describe('IntegTest runIntegTests', () => {
});

// THEN
expect(cdkMock.mocks.deploy).toHaveBeenCalledTimes(2);
expect(cdkMock.mocks.deploy).toHaveBeenCalledTimes(3);
expect(cdkMock.mocks.destroy).toHaveBeenCalledTimes(1);
expect(cdkMock.mocks.synthFast).toHaveBeenCalledTimes(1);
expect(cdkMock.mocks.deploy).toHaveBeenCalledWith({
Expand Down Expand Up @@ -83,7 +83,6 @@ describe('IntegTest runIntegTests', () => {
}),
versionReporting: false,
lookups: false,
rollback: false,
stacks: ['test-stack', 'new-test-stack'],
});
expect(cdkMock.mocks.destroy).toHaveBeenCalledWith({
Expand Down Expand Up @@ -130,7 +129,6 @@ describe('IntegTest runIntegTests', () => {
context: expect.not.objectContaining({
[AVAILABILITY_ZONE_FALLBACK_CONTEXT_KEY]: ['test-region-1a', 'test-region-1b', 'test-region-1c'],
}),
rollback: false,
lookups: false,
stacks: ['stack1'],
output: 'cdk-integ.out.xxxxx.integ-test1.js.snapshot',
Expand Down Expand Up @@ -176,7 +174,6 @@ describe('IntegTest runIntegTests', () => {
}),
versionReporting: false,
lookups: true,
rollback: false,
stacks: ['test-stack'],
output: 'cdk-integ.out.xxxxx.test-with-snapshot-assets-diff.js.snapshot',
profile: undefined,
Expand Down Expand Up @@ -206,6 +203,52 @@ describe('IntegTest runIntegTests', () => {
});
});

test('with an assertion stack', () => {
// WHEN
const integTest = new IntegTestRunner({
cdk: cdkMock.cdk,
test: new IntegTest({
fileName: 'test/test-data/xxxxx.test-with-snapshot.js',
discoveryRoot: 'test/test-data',
}),
});
integTest.runIntegTestCase({
testCaseName: 'xxxxx.test-with-snapshot',
});

// THEN
expect(cdkMock.mocks.deploy).toHaveBeenCalledTimes(3);
expect(cdkMock.mocks.destroy).toHaveBeenCalledTimes(1);
expect(cdkMock.mocks.synthFast).toHaveBeenCalledTimes(1);
expect(cdkMock.mocks.deploy).toHaveBeenNthCalledWith(1, expect.objectContaining({
app: 'xxxxx.test-with-snapshot.js.snapshot',
context: expect.any(Object),
stacks: ['test-stack'],
}));
expect(cdkMock.mocks.deploy).toHaveBeenNthCalledWith(2, expect.not.objectContaining({
rollback: false,
}));
expect(cdkMock.mocks.deploy).toHaveBeenNthCalledWith(3, expect.objectContaining({
app: 'node xxxxx.test-with-snapshot.js',
stacks: ['Bundling/DefaultTest/DeployAssert'],
rollback: false,
}));
expect(cdkMock.mocks.destroy).toHaveBeenCalledWith({
app: 'node xxxxx.test-with-snapshot.js',
pathMetadata: false,
assetMetadata: false,
context: expect.not.objectContaining({
'vpc-provider:account=12345678:filter.isDefault=true:region=test-region:returnAsymmetricSubnets=true': expect.objectContaining({
vpcId: 'vpc-60900905',
}),
}),
versionReporting: false,
force: true,
all: true,
output: 'cdk-integ.out.xxxxx.test-with-snapshot.js.snapshot',
});
});

test('no clean', () => {
// WHEN
const integTest = new IntegTestRunner({
Expand Down Expand Up @@ -298,7 +341,6 @@ describe('IntegTest runIntegTests', () => {
}),
}),
profile: 'test-profile',
rollback: false,
lookups: false,
stacks: ['stack1'],
output: 'cdk-integ.out.xxxxx.integ-test1.js.snapshot',
Expand Down Expand Up @@ -564,7 +606,7 @@ describe('IntegTest runIntegTests', () => {
});

// THEN
expect(cdkMock.mocks.deploy).toHaveBeenCalledTimes(2);
expect(cdkMock.mocks.deploy).toHaveBeenCalledTimes(3);
expect(cdkMock.mocks.destroy).toHaveBeenCalledTimes(1);
expect(cdkMock.mocks.synthFast).toHaveBeenCalledTimes(1);
expect(cdkMock.mocks.deploy).toHaveBeenCalledWith(expect.objectContaining({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
"testCases": {
"xxxxx.test-with-snapshot": {
"stacks": ["test-stack", "new-test-stack"],
"assertionStack": "Bundling/DefaultTest/DeployAssert",
"assertionStackName": "BundlingDefaultTestDeployAssertAACA0CAF",
"diffAssets": true,
"allowDestroy": [
"AWS::IAM::Role"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
"testCases": {
"xxxxx.test-with-snapshot": {
"stacks": ["test-stack"],
"assertionStack": "Bundling/DefaultTest/DeployAssert",
"assertionStackName": "BundlingDefaultTestDeployAssertAACA0CAF",
"diffAssets": true,
"allowDestroy": [
"AWS::IAM::Role"
Expand Down