Skip to content

Commit a1473ae

Browse files
author
Elad Ben-Israel
committed
Add integration test
1 parent 26b4dfe commit a1473ae

4 files changed

Lines changed: 76 additions & 0 deletions

File tree

packages/aws-cdk/test/integ/cli/app/app.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const iam = require('@aws-cdk/aws-iam');
66
const sns = require('@aws-cdk/aws-sns');
77
const lambda = require('@aws-cdk/aws-lambda');
88
const docker = require('@aws-cdk/aws-ecr-assets');
9+
const { StackWithNestedStack } = require('./nested-stack');
910

1011
const stackPrefix = process.env.STACK_NAME_PREFIX || 'cdk-toolkit-integration';
1112

@@ -179,4 +180,6 @@ if (process.env.ENABLE_VPC_TESTING) { // Gating so we don't do context fetching
179180

180181
new ConditionalResourceStack(app, `${stackPrefix}-conditional-resource`)
181182

183+
new StackWithNestedStack(app, `${stackPrefix}-with-nested-stack`);
184+
182185
app.synth();
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const cfn = require('@aws-cdk/aws-cloudformation');
2+
const sns = require('@aws-cdk/aws-sns');
3+
const { Stack } = require('@aws-cdk/core');
4+
5+
class StackWithNestedStack extends Stack {
6+
constructor(scope, id) {
7+
super(scope, id);
8+
new MyNestedStack(this, 'MyNested');
9+
}
10+
}
11+
12+
class MyNestedStack extends cfn.NestedStack {
13+
constructor(scope, id) {
14+
super(scope, id);
15+
16+
new sns.Topic(this, 'MyTopic');
17+
}
18+
}
19+
20+
exports.StackWithNestedStack = StackWithNestedStack;

packages/aws-cdk/test/integ/cli/common.bash

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ function prepare_fixture() {
7878
@aws-cdk/aws-lambda \
7979
@aws-cdk/aws-ssm \
8080
@aws-cdk/aws-ecr-assets \
81+
@aws-cdk/aws-cloudformation \
8182
@aws-cdk/aws-ec2
8283

8384
echo "| setup complete at: $PWD"
@@ -91,6 +92,7 @@ function cleanup() {
9192
cleanup_stack ${STACK_NAME_PREFIX}-test-1
9293
cleanup_stack ${STACK_NAME_PREFIX}-test-2
9394
cleanup_stack ${STACK_NAME_PREFIX}-iam-test
95+
cleanup_stack ${STACK_NAME_PREFIX}-with-nested-stack
9496
}
9597

9698
function setup() {
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
scriptdir=$(cd $(dirname $0) && pwd)
4+
source ${scriptdir}/common.bash
5+
# ----------------------------------------------------------
6+
# this test verifies that deployment is skipped when the template did not
7+
# change, and that `--force` can be used to override this behavior.
8+
9+
setup
10+
11+
# we are using a stack with a nested stack because CFN will always attempt to
12+
# update a nested stack, which will allow us to verify that updates are actually
13+
# skipped unless --force is specified.
14+
stack_name="${STACK_NAME_PREFIX}-with-nested-stack"
15+
16+
get_last_changeset() {
17+
aws cloudformation describe-stacks --stack-name ${stack_name} --query 'Stacks[0].ChangeSetId'
18+
}
19+
20+
# deploy once
21+
echo "============================================================"
22+
echo " deploying stack"
23+
echo "============================================================"
24+
cdk deploy -v ${stack_name}
25+
changeset1=$(get_last_changeset)
26+
echo "changeset1=${changeset1}"
27+
28+
echo "============================================================"
29+
echo " deploying the same stack again (no change)"
30+
echo "============================================================"
31+
cdk deploy -v ${stack_name}
32+
changeset2=$(get_last_changeset)
33+
if [ "${changeset2}" != "${changeset1}" ]; then
34+
echo "TEST FAILED: expected the 'cdk deploy' will skip deployment because the app did not change"
35+
exit 1
36+
fi
37+
38+
echo "============================================================"
39+
echo " deploying the same stack again (no change, --force)"
40+
echo "============================================================"
41+
cdk deploy --force -v ${stack_name}
42+
changeset3=$(get_last_changeset)
43+
if [ "${changeset3}" == "${changeset1}" ]; then
44+
echo "TEST FAILED: expected --force to create a new changeset"
45+
exit 1
46+
fi
47+
48+
# destroy
49+
cdk destroy -f ${stack_name}
50+
51+
echo "✅ success"

0 commit comments

Comments
 (0)