-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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(cli): add Cloud Assembly backwards compat tests #4625
Conversation
Make sure that the CLI will continue to be able to load old cloud assemblies. We do this by using the CLI feature that it can directly load Cloud Assemblies through its `--app` argument, hard copying a couple of cloud assemblies into the test set and trying to synth those. In addition to adding a test for loading v0.36.0 assemblies, also add tests for 2 common context provider requests (AZs and VPC), to make sure new CLIs will continue to be able to handle these context lookup requests. Fixes #4475, pre-emptively adds a regression test for #4544.
Thanks so much for taking the time to contribute to the AWS CDK ❤️ We will shortly assign someone to review this pull request and help get it
|
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Am I right in assuming that at least one test case will need to be added here for every cx-api version bump? If so, should we enforce that, i.e. fail if cx-api version is > 1.10?
add tests for 2 common context provider requests (AZs and VPC)
I'm not familiar with these, so someone familiar should take a look as well.
tmpdir=$(dirname $(mktemp -u)) | ||
casmdir=$tmpdir/cdk-integ-cx |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could just be casmdir=$(mktemp -d)
. Everything else should work AFAICT
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But no. I want a predictable dir, for the following reasons:
- If I do a random dir every time, I have to clean it up after every test.
- If I have to clean it up after every test, I can't inspect the state of the directory after a failing test.
Instead, I have a directory that's the same every time which gets reset every time.
This is just a complex way of writing casmdir=/tmp/cdk-integ-cx
, but in a way that is compatible across systems where the tempdir doesn't necessarily live at /tmp
(for example MacOS or Windows).
echo "ASSEMBLY ${1}" | ||
rm -rf $casmdir | ||
mkdir -p $casmdir | ||
cp -R $1/* $casmdir |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you instead do a mktemp each time, instead of clobbering, we would retain (temporarily) all of the artifacts, making it easier to debug when they fail.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure I follow. If a test succeeds, the artifacts can be clobbered, if a test fails they won't be?
for template in $casmdir/*.js; do | ||
node $template > ${template%.js} | ||
done |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid loops in bash where possible; they are not very efficient but more importantly unnatural to shell scripting.
Instead use pipes. Something like, ls -1 $casmdir/*.js | xargs -I{} node {} ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't make me do that.
This is readable, writable and clear. All that find
and xargs
magic makes it horrible and unreadable. I dare you to write the same command with xargs
, including the shell redirect to individual files. Show me what it looks like and we'll compare quality.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the records, for
loops have been natural to my shell scripting since longer than I can remember...
# tempdir. Evaluate .js files found their (interpret them | ||
# as templates). | ||
function prepare_cloud_assembly() { | ||
echo "ASSEMBLY ${1}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor: Ideally assign $1 at the top to a local var with an appropriate name and then use them
local sourcedir=$1
Better readability when there are no named parameters.
# Echo the TEST_ACCOUNT, TEST_REGION vars to make bash abort if they're not set. | ||
echo "Running backwards compatibility test (account ${TEST_ACCOUNT}, region ${TEST_REGION})" | ||
|
||
for assembly in ${scriptdir}/cloud-assemblies/*; do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment as the for loop, but I understand you might want to keep this one for readability.
If it were up to me, I would group what is in the loop into a function and then use pipes and xargs. I'll leave it to you to decide.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this code can be conveniently rewritten to use xargs.
@@ -0,0 +1 @@ | |||
{"version":"0.36.0"} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A bit confused - Isn't cdk.out
a directory that contains the manifest and template?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it is. I think this file exists for backwards compatibility with some old version. Elad will know.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that is correct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed. It is there since old CLIs would look for this file name in the output directory. The version
field here will tell them that they can't do anything besides yelling. I assume we can probably get rid of it by now...
cat $stderrfile >&2 | ||
echo "There was an error executing the context provider!" >&2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think the messaging include which test case failed; and we should include it.
Also, it's good practice to put a sample of the output when tests fail into the PR description; just to validate that the messaging looks good.
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really like this approach! How can we make sure that whenever we do a bump of the protocol version we add another "old" cloud assembly to the list?
@@ -0,0 +1 @@ | |||
{"version":"0.36.0"} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed. It is there since old CLIs would look for this file name in the output directory. The version
field here will tell them that they can't do anything besides yelling. I assume we can probably get rid of it by now...
@@ -0,0 +1 @@ | |||
{"version":"0.36.0"} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that is correct.
Thank you for contributing! Your pull request is now being automatically merged. |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
Make sure that the CLI will continue to be able to load old cloud
assemblies. We do this by using the CLI feature that it can directly
load Cloud Assemblies through its
--app
argument, hard copyinga couple of cloud assemblies into the test set and trying to synth
those.
In addition to adding a test for loading v0.36.0 assemblies, also
add tests for 2 common context provider requests (AZs and VPC),
to make sure new CLIs will continue to be able to handle these
context lookup requests.
Fixes #4475, pre-emptively adds a regression test for #4544.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license