Skip to content

Commit

Permalink
integ tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bergjaak committed May 8, 2024
1 parent 99c87a1 commit a8c90d9
Show file tree
Hide file tree
Showing 4 changed files with 550 additions and 34 deletions.
7 changes: 4 additions & 3 deletions packages/@aws-cdk-testing/cli-integ/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,15 @@
"license": "Apache-2.0",
"devDependencies": {
"@aws-cdk/cdk-build-tools": "0.0.0",
"@types/semver": "^7.5.8",
"@types/yargs": "^15.0.19",
"@aws-cdk/pkglint": "0.0.0",
"@types/fs-extra": "^9.0.13",
"@types/glob": "^7.2.0",
"@types/npm": "^7.19.3",
"@aws-cdk/pkglint": "0.0.0"
"@types/semver": "^7.5.8",
"@types/yargs": "^15.0.19"
},
"dependencies": {
"@aws-sdk/client-ssm": "^3.569.0",
"@octokit/rest": "^18.12.0",
"aws-sdk": "^2.1610.0",
"axios": "^1.6.8",
Expand Down
18 changes: 18 additions & 0 deletions packages/@aws-cdk-testing/cli-integ/resources/cdk-apps/app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,22 @@ class SsoInstanceAccessControlConfig extends Stack {
}
}

class DiffFromChangeSetStack extends Stack {
constructor(scope, id) {
super(scope, id);

const queueNameFromParameter = ssm.StringParameter.valueForStringParameter(this, 'for-queue-name-defined-by-ssm-param');
new sqs.Queue(this, "DiffFromChangeSetQueue", {
queueName: queueNameFromParameter,
})

new ssm.StringParameter(this, 'DiffFromChangeSetSSMParam', {
parameterName: 'DiffFromChangeSetSSMParamName',
stringValue: queueNameFromParameter,
});
}
}

class ListMultipleDependentStack extends Stack {
constructor(scope, id) {
super(scope, id);
Expand Down Expand Up @@ -658,6 +674,8 @@ switch (stackSet) {

const failed = new FailedStack(app, `${stackPrefix}-failed`)

new DiffFromChangeSetStack(app, `${stackPrefix}-queue-name-defined-by-ssm-param`)

// A stack that depends on the failed stack -- used to test that '-e' does not deploy the failing stack
const dependsOnFailed = new OutputsStack(app, `${stackPrefix}-depends-on-failed`);
dependsOnFailed.addDependency(failed);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { promises as fs, existsSync } from 'fs';
import * as os from 'os';
import * as path from 'path';
import * as SSM from '@aws-sdk/client-ssm';
import { integTest, cloneDirectory, shell, withDefaultFixture, retry, sleep, randomInteger, withSamIntegrationFixture, RESOURCES_DIR, withCDKMigrateFixture, withExtendedTimeoutFixture } from '../../lib';

jest.setTimeout(2 * 60 * 60_000); // Includes the time to acquire locks, worst-case single-threaded runtime
Expand Down Expand Up @@ -944,6 +945,59 @@ integTest('cdk diff --quiet does not print \'There were no differences\' message
expect(diff).not.toContain('There were no differences');
}));

integTest('cdk diff picks up changes that are only present in changeset', withDefaultFixture(async (fixture) => {
// eslint-disable-next-line no-console
const ssmClient = new SSM.SSMClient();
await ssmClient.send(new SSM.PutParameterCommand(
{
Name: 'for-queue-name-defined-by-ssm-param',
Value: Math.floor(Math.random() * 100_000_000_000_001).toString(),
Overwrite: true,
Type: 'String',
},
));

// GIVEN
try {
await fixture.cdkDeploy('queue-name-defined-by-ssm-param');

// We want to change the ssm value. Then the CFN changeset will detect that the queue will be changed upon deploy.
const newRandomValueForSsmParam = Math.floor(Math.random() * 100_000_000_000_001).toString();
await ssmClient.send(new SSM.PutParameterCommand(
{
Name: 'for-queue-name-defined-by-ssm-param',
Value: newRandomValueForSsmParam,
Type: 'String',
Overwrite: true,
},
));

// WHEN
const diff = await fixture.cdk(['diff', fixture.fullStackName('queue-name-defined-by-ssm-param')]);

`
Resources
[~] AWS::SQS::Queue DiffFromChangeSetQueue DiffFromChangeSetQueue06622C07 replace
└─ [~] QueueName (requires replacement)
[~] AWS::SSM::Parameter DiffFromChangeSetSSMParam DiffFromChangeSetSSMParam92A9A723
└─ [~] Value
`;

// THEN
// the reason these aren't just 1 line is because the terminal output includes colors, which comes up like \u001b[4m\u001b[1mResources\u001b
// which is not very human friendly...
expect(diff).toContain('AWS::SQS::Queue');
expect(diff).toContain('DiffFromChangeSetQueue');
expect(diff).toContain('QueueName (requires replacement)');
expect(diff).toContain('AWS::SSM::Parameter');
expect(diff).toContain('DiffFromChangeSetSSMParam');
expect(diff).toContain('Value');
expect(diff).toContain('Number of stacks with differences: 1');
} finally {
await fixture.cdkDestroy('queue-name-defined-by-ssm-param');
}
}));

integTest('deploy stack with docker asset', withDefaultFixture(async (fixture) => {
await fixture.cdkDeploy('docker');
}));
Expand Down
Loading

0 comments on commit a8c90d9

Please sign in to comment.