-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(toolkit): multi-stack apps cannot be synthesized or deployed (#911)
Due to a recent cx protocol change (#868), some toolkit commands stopped respecting the "selected" stacks (the ones specified in the command line). "cdk synth" would always return the first stack, and "cdk deploy" would always deploy all stacks. Since we have test coverage gaps in the toolkit (#294), we did not discover this before we released. This change includes an initial set of integration tests for the toolkit. At the moment they should be manually executed when toolkit changes are made, but we will execute them in a pipeline. Fixes #910
- Loading branch information
1 parent
c23da91
commit 5511076
Showing
12 changed files
with
253 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# CDK toolkit integreation tests | ||
|
||
To run, just execute `./test.sh`. The test uses the default AWS credentials. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
!*.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
const cdk = require('@aws-cdk/cdk'); | ||
const sns = require('@aws-cdk/aws-sns'); | ||
|
||
class MyStack extends cdk.Stack { | ||
constructor(parent, id) { | ||
super(parent, id); | ||
new sns.Topic(this, 'topic'); | ||
} | ||
} | ||
|
||
class YourStack extends cdk.Stack { | ||
constructor(parent, id) { | ||
super(parent, id); | ||
new sns.Topic(this, 'topic1'); | ||
new sns.Topic(this, 'topic2'); | ||
} | ||
} | ||
|
||
const app = new cdk.App(); | ||
|
||
new MyStack(app, 'cdk-toolkit-integration-test-1'); | ||
new YourStack(app, 'cdk-toolkit-integration-test-2'); | ||
|
||
app.run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"app": "node app.js", | ||
"versionReporting": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
function cleanup_stack() { | ||
local stack_arn=$1 | ||
echo "| ensuring ${stack_arn} is cleaned up" | ||
if aws cloudformation describe-stacks --stack-name ${stack_arn} 2> /dev/null; then | ||
aws cloudformation delete-stack --stack-name ${stack_arn} | ||
fi | ||
} | ||
|
||
function cleanup() { | ||
cleanup_stack cdk-toolkit-integration-test-1 | ||
cleanup_stack cdk-toolkit-integration-test-2 | ||
} | ||
|
||
function setup() { | ||
cleanup | ||
cd app | ||
|
||
npm i --no-save @aws-cdk/cdk @aws-cdk/aws-sns | ||
} | ||
|
||
function fail() { | ||
echo "❌ $@" | ||
exit 1 | ||
} | ||
|
||
function assert_diff() { | ||
local test=$1 | ||
local actual=$2 | ||
local expected=$3 | ||
|
||
diff ${actual} ${expected} || { | ||
echo | ||
echo "+-----------" | ||
echo "| expected:" | ||
cat ${expected} | ||
echo "|--" | ||
echo | ||
echo "+-----------" | ||
echo "| actual:" | ||
cat ${actual} | ||
echo "|--" | ||
echo | ||
fail "assertion failed. ${test}" | ||
} | ||
} | ||
|
||
function assert() { | ||
local command="$1" | ||
|
||
local expected=$(mktemp) | ||
local actual=$(mktemp) | ||
|
||
echo "| running ${command}" | ||
|
||
$command > ${actual} || { | ||
fail "command ${command} non-zero exit code" | ||
} | ||
|
||
cat > ${expected} | ||
|
||
assert_diff "command: ${command}" "${actual}" "${expected}" | ||
} | ||
|
||
function assert_lines() { | ||
local data="$1" | ||
local expected="$2" | ||
echo "| assert that last command returned ${expected} line(s)" | ||
|
||
local lines="$(echo "${data}" | wc -l)" | ||
if [ "${lines}" -ne "${expected}" ]; then | ||
fail "response has ${lines} lines and we expected ${expected} lines to be returned" | ||
fi | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/bin/bash | ||
set -euo pipefail | ||
scriptdir=$(cd $(dirname $0) && pwd) | ||
source ${scriptdir}/common.bash | ||
# ---------------------------------------------------------- | ||
|
||
setup | ||
|
||
stack_arns=$(cdk deploy) | ||
echo "Stack deployed successfully" | ||
|
||
# verify that we only deployed a single stack (there's a single ARN in the output) | ||
lines="$(echo "${stack_arns}" | wc -l)" | ||
if [ "${lines}" -ne 2 ]; then | ||
fail "cdk deploy returned ${lines} arns and we expected 2" | ||
fi | ||
|
||
cdk destroy -f cdk-toolkit-integration-test-1 | ||
cdk destroy -f cdk-toolkit-integration-test-2 | ||
|
||
echo "✅ success" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#!/bin/bash | ||
set -euo pipefail | ||
scriptdir=$(cd $(dirname $0) && pwd) | ||
source ${scriptdir}/common.bash | ||
# ---------------------------------------------------------- | ||
|
||
setup | ||
|
||
stack_arn=$(cdk deploy cdk-toolkit-integration-test-2) | ||
echo "Stack deployed successfully" | ||
|
||
# verify that we only deployed a single stack (there's a single ARN in the output) | ||
assert_lines "${stack_arn}" 1 | ||
|
||
# verify the number of resources in the stack | ||
response_json=$(mktemp).json | ||
aws cloudformation describe-stack-resources --stack-name ${stack_arn} > ${response_json} | ||
resource_count=$(node -e "console.log(require('${response_json}').StackResources.length)") | ||
if [ "${resource_count}" -ne 2 ]; then | ||
fail "stack has ${resource_count} resources, and we expected two" | ||
fi | ||
|
||
# destroy | ||
cdk destroy -f cdk-toolkit-integration-test-2 | ||
|
||
echo "✅ success" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/bin/bash | ||
set -euo pipefail | ||
scriptdir=$(cd $(dirname $0) && pwd) | ||
source ${scriptdir}/common.bash | ||
# ---------------------------------------------------------- | ||
|
||
setup | ||
|
||
function cdk_diff() { | ||
cdk diff $1 2>&1 || true | ||
} | ||
|
||
assert_lines "$(cdk_diff cdk-toolkit-integration-test-1)" 1 | ||
assert_lines "$(cdk_diff cdk-toolkit-integration-test-2)" 2 | ||
|
||
echo "✅ success" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/bin/bash | ||
set -euo pipefail | ||
scriptdir=$(cd $(dirname $0) && pwd) | ||
source ${scriptdir}/common.bash | ||
# ---------------------------------------------------------- | ||
|
||
setup | ||
|
||
assert "cdk ls" <<HERE | ||
cdk-toolkit-integration-test-1 | ||
cdk-toolkit-integration-test-2 | ||
HERE | ||
|
||
echo "✅ success" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/bin/bash | ||
set -euo pipefail | ||
scriptdir=$(cd $(dirname $0) && pwd) | ||
source ${scriptdir}/common.bash | ||
# ---------------------------------------------------------- | ||
|
||
setup | ||
|
||
assert "cdk synth cdk-toolkit-integration-test-1" <<HERE | ||
Resources: | ||
topic69831491: | ||
Type: 'AWS::SNS::Topic' | ||
HERE | ||
|
||
assert "cdk synth cdk-toolkit-integration-test-2" <<HERE | ||
Resources: | ||
topic152D84A37: | ||
Type: 'AWS::SNS::Topic' | ||
topic2A4FB547F: | ||
Type: 'AWS::SNS::Topic' | ||
HERE | ||
|
||
echo "✅ success" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/bin/bash | ||
set -euo pipefail | ||
scriptdir=$(cd $(dirname $0) && pwd) | ||
|
||
toolkit_bin="${scriptdir}/../bin" | ||
|
||
if [ ! -x ${toolkit_bin}/cdk ]; then | ||
echo "Unable to find 'cdk' under ${toolkit_bin}" | ||
exit 1 | ||
fi | ||
|
||
# make sure "this" toolkit is in the path | ||
export PATH=${toolkit_bin}:$PATH | ||
|
||
cd ${scriptdir} | ||
for test in test-*.sh; do | ||
echo "============================================================================================" | ||
echo "${test}" | ||
echo "============================================================================================" | ||
/bin/bash ${test} | ||
done |