From a85da79c0da05f57af84d388efe7775502cf0039 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E0=A4=95=E0=A4=B0=E0=A4=A4=E0=A5=8B=E0=A4=AB=E0=A5=8D?= =?UTF-8?q?=E0=A4=AB=E0=A5=87=E0=A4=B2=E0=A4=B8=E0=A5=8D=E0=A4=95=E0=A5=8D?= =?UTF-8?q?=E0=A4=B0=E0=A4=BF=E0=A4=AA=E0=A5=8D=E0=A4=9F=E2=84=A2?= Date: Wed, 15 Jan 2020 04:08:34 +0100 Subject: [PATCH] fix(cli): Fix various init templates & their tests (#5693) * fix(cli): init tests should run for each template * fix(cli): fix init templates for sample-app & lib --- .../%name.PascalCased%Stack.template.fs | 2 +- .../fsharp/src/%name.PascalCased%/Program.template.fs | 6 ++++-- .../com/myorg/%name.PascalCased%StackTest.template.java | 2 +- .../%name.PythonModule%_stack.template.py} | 0 .../python/{%name% => %name.PythonModule%}/__init__.py | 0 .../init-templates/sample-app/python/README.template.md | 4 ++-- .../lib/init-templates/sample-app/python/app.template.py | 4 ++-- .../init-templates/sample-app/python/setup.template.py | 6 +++--- ...late.py => test_%name.PythonModule%_stack.template.py} | 6 +++--- packages/aws-cdk/test/integ/init/common.bash | 2 +- packages/aws-cdk/test/integ/init/test-csharp.sh | 2 +- packages/aws-cdk/test/integ/init/test-fsharp.sh | 2 +- packages/aws-cdk/test/integ/init/test-java.sh | 2 +- packages/aws-cdk/test/integ/init/test-javascript.sh | 2 +- packages/aws-cdk/test/integ/init/test-python-stackname.sh | 7 +++++++ packages/aws-cdk/test/integ/init/test-python.sh | 2 +- packages/aws-cdk/test/integ/init/test-typescript.sh | 8 ++++++-- 17 files changed, 35 insertions(+), 22 deletions(-) rename packages/aws-cdk/lib/init-templates/sample-app/python/{%name%/%name%_stack.template.py => %name.PythonModule%/%name.PythonModule%_stack.template.py} (100%) rename packages/aws-cdk/lib/init-templates/sample-app/python/{%name% => %name.PythonModule%}/__init__.py (100%) rename packages/aws-cdk/lib/init-templates/sample-app/python/tests/unit/{test_%name%_stack.template.py => test_%name.PythonModule%_stack.template.py} (56%) create mode 100755 packages/aws-cdk/test/integ/init/test-python-stackname.sh diff --git a/packages/aws-cdk/lib/init-templates/sample-app/fsharp/src/%name.PascalCased%/%name.PascalCased%Stack.template.fs b/packages/aws-cdk/lib/init-templates/sample-app/fsharp/src/%name.PascalCased%/%name.PascalCased%Stack.template.fs index f78b30d675d0f..1582e37f4faaf 100644 --- a/packages/aws-cdk/lib/init-templates/sample-app/fsharp/src/%name.PascalCased%/%name.PascalCased%Stack.template.fs +++ b/packages/aws-cdk/lib/init-templates/sample-app/fsharp/src/%name.PascalCased%/%name.PascalCased%Stack.template.fs @@ -1,4 +1,4 @@ -namespace HelloCdk +namespace %name.PascalCased% open Amazon.CDK open Amazon.CDK.AWS.SNS diff --git a/packages/aws-cdk/lib/init-templates/sample-app/fsharp/src/%name.PascalCased%/Program.template.fs b/packages/aws-cdk/lib/init-templates/sample-app/fsharp/src/%name.PascalCased%/Program.template.fs index 77234df375089..dc618af3fbbf1 100644 --- a/packages/aws-cdk/lib/init-templates/sample-app/fsharp/src/%name.PascalCased%/Program.template.fs +++ b/packages/aws-cdk/lib/init-templates/sample-app/fsharp/src/%name.PascalCased%/Program.template.fs @@ -1,9 +1,11 @@ open Amazon.CDK -open %name.PascalCased%Stack +open %name.PascalCased% [] let main _ = let app = App(null) - %name.PascalCased%Stack(app, "%name.PascalCased%Stack", StackProps) |> ignore + + %name.PascalCased%Stack(app, "%name.PascalCased%Stack", StackProps()) |> ignore + app.Synth() |> ignore 0 diff --git a/packages/aws-cdk/lib/init-templates/sample-app/java/src/test/java/com/myorg/%name.PascalCased%StackTest.template.java b/packages/aws-cdk/lib/init-templates/sample-app/java/src/test/java/com/myorg/%name.PascalCased%StackTest.template.java index d9f09a46d7fef..aaca734f06d68 100644 --- a/packages/aws-cdk/lib/init-templates/sample-app/java/src/test/java/com/myorg/%name.PascalCased%StackTest.template.java +++ b/packages/aws-cdk/lib/init-templates/sample-app/java/src/test/java/com/myorg/%name.PascalCased%StackTest.template.java @@ -19,6 +19,6 @@ public void testStack() throws IOException { %name.PascalCased%Stack stack = new %name.PascalCased%Stack(app, "test"); JsonNode actual = JSON.valueToTree(app.synth().getStackArtifact(stack.getArtifactId()).getTemplate()); - assertThat(actual.asText(), CoreMatchers.both(CoreMatchers.containsString("AWS::SQS::Queue")).and(CoreMatchers.containsString("AWS::SNS::Topic"))); + assertThat(actual.toString(), CoreMatchers.both(CoreMatchers.containsString("AWS::SQS::Queue")).and(CoreMatchers.containsString("AWS::SNS::Topic"))); } } diff --git a/packages/aws-cdk/lib/init-templates/sample-app/python/%name%/%name%_stack.template.py b/packages/aws-cdk/lib/init-templates/sample-app/python/%name.PythonModule%/%name.PythonModule%_stack.template.py similarity index 100% rename from packages/aws-cdk/lib/init-templates/sample-app/python/%name%/%name%_stack.template.py rename to packages/aws-cdk/lib/init-templates/sample-app/python/%name.PythonModule%/%name.PythonModule%_stack.template.py diff --git a/packages/aws-cdk/lib/init-templates/sample-app/python/%name%/__init__.py b/packages/aws-cdk/lib/init-templates/sample-app/python/%name.PythonModule%/__init__.py similarity index 100% rename from packages/aws-cdk/lib/init-templates/sample-app/python/%name%/__init__.py rename to packages/aws-cdk/lib/init-templates/sample-app/python/%name.PythonModule%/__init__.py diff --git a/packages/aws-cdk/lib/init-templates/sample-app/python/README.template.md b/packages/aws-cdk/lib/init-templates/sample-app/python/README.template.md index 2716cd118afc4..b8084d113f854 100644 --- a/packages/aws-cdk/lib/init-templates/sample-app/python/README.template.md +++ b/packages/aws-cdk/lib/init-templates/sample-app/python/README.template.md @@ -1,13 +1,13 @@ # Welcome to your CDK Python project! -You should explore the contents of this project. It demonstrates a CDK app with an instance of a stack (`%name.PascalCased%Stack`) +You should explore the contents of this project. It demonstrates a CDK app with an instance of a stack (`%name.PythonModule%_stack`) which contains an Amazon SQS queue that is subscribed to an Amazon SNS topic. The `cdk.json` file tells the CDK Toolkit how to execute your app. This project is set up like a standard Python project. The initialization process also creates -a virtualenv within this project, stored under the .env directory. To create the virtualenv +a virtualenv within this project, stored under the .env directory. To create the virtualenv it assumes that there is a `python3` executable in your path with access to the `venv` package. If for any reason the automatic creation of the virtualenv fails, you can create the virtualenv manually once the init process completes. diff --git a/packages/aws-cdk/lib/init-templates/sample-app/python/app.template.py b/packages/aws-cdk/lib/init-templates/sample-app/python/app.template.py index 40c3c3526af30..580bbee9e069c 100644 --- a/packages/aws-cdk/lib/init-templates/sample-app/python/app.template.py +++ b/packages/aws-cdk/lib/init-templates/sample-app/python/app.template.py @@ -2,10 +2,10 @@ from aws_cdk import core -from %name%.%name%_stack import %name.PascalCased%Stack +from %name.PythonModule%.%name.PythonModule%_stack import %name.PascalCased%Stack app = core.App() -%name.PascalCased%Stack(app, "%name%", env={'region': 'us-west-2'}) +%name.PascalCased%Stack(app, "%name.StackName%", env={'region': 'us-west-2'}) app.synth() diff --git a/packages/aws-cdk/lib/init-templates/sample-app/python/setup.template.py b/packages/aws-cdk/lib/init-templates/sample-app/python/setup.template.py index 09829f28d4151..f7d9afb7473bc 100644 --- a/packages/aws-cdk/lib/init-templates/sample-app/python/setup.template.py +++ b/packages/aws-cdk/lib/init-templates/sample-app/python/setup.template.py @@ -6,7 +6,7 @@ setuptools.setup( - name="%name%", + name="%name.PythonModule%", version="0.0.1", description="A sample CDK Python app", @@ -15,8 +15,8 @@ author="author", - package_dir={"": "%name%"}, - packages=setuptools.find_packages(where="%name%"), + package_dir={"": "%name.PythonModule%"}, + packages=setuptools.find_packages(where="%name.PythonModule%"), install_requires=[ "aws-cdk.core", diff --git a/packages/aws-cdk/lib/init-templates/sample-app/python/tests/unit/test_%name%_stack.template.py b/packages/aws-cdk/lib/init-templates/sample-app/python/tests/unit/test_%name.PythonModule%_stack.template.py similarity index 56% rename from packages/aws-cdk/lib/init-templates/sample-app/python/tests/unit/test_%name%_stack.template.py rename to packages/aws-cdk/lib/init-templates/sample-app/python/tests/unit/test_%name.PythonModule%_stack.template.py index 5c441bd3ae13d..fab17d075ac44 100644 --- a/packages/aws-cdk/lib/init-templates/sample-app/python/tests/unit/test_%name%_stack.template.py +++ b/packages/aws-cdk/lib/init-templates/sample-app/python/tests/unit/test_%name.PythonModule%_stack.template.py @@ -2,13 +2,13 @@ import pytest from aws_cdk import core -from %name%.%name%_stack import %name.PascalCased%Stack +from %name%.%name.PythonModule%_stack import %name.PascalCased%Stack def get_template(): app = core.App() - %name.PascalCased%Stack(app, "%name%") - return json.dumps(app.synth().get_stack("%name%").template) + %name.PascalCased%Stack(app, "%name.StackName%") + return json.dumps(app.synth().get_stack("%name.StackName%").template) def test_sqs_queue_created(): diff --git a/packages/aws-cdk/test/integ/init/common.bash b/packages/aws-cdk/test/integ/init/common.bash index 1298b2b3f71fa..f41f02b5215e8 100644 --- a/packages/aws-cdk/test/integ/init/common.bash +++ b/packages/aws-cdk/test/integ/init/common.bash @@ -1,5 +1,5 @@ set -eu -init_test_dir=/tmp/cdk-init-test +init_test_dir="${init_test_dir:=/tmp/cdk-init-test}" function setup() { rm -rf $init_test_dir diff --git a/packages/aws-cdk/test/integ/init/test-csharp.sh b/packages/aws-cdk/test/integ/init/test-csharp.sh index 65b479812f77d..ea82e3b63f38c 100755 --- a/packages/aws-cdk/test/integ/init/test-csharp.sh +++ b/packages/aws-cdk/test/integ/init/test-csharp.sh @@ -21,6 +21,6 @@ for template in $templates; do setup - cdk init -l csharp -t $template + cdk init -l csharp $template cdk synth done diff --git a/packages/aws-cdk/test/integ/init/test-fsharp.sh b/packages/aws-cdk/test/integ/init/test-fsharp.sh index 146384fff0d25..f8ad463703672 100755 --- a/packages/aws-cdk/test/integ/init/test-fsharp.sh +++ b/packages/aws-cdk/test/integ/init/test-fsharp.sh @@ -21,6 +21,6 @@ for template in $templates; do setup - cdk init -l fsharp -t $template + cdk init -l fsharp $template cdk synth done diff --git a/packages/aws-cdk/test/integ/init/test-java.sh b/packages/aws-cdk/test/integ/init/test-java.sh index 81cf7deccf4ea..f27441809da3c 100755 --- a/packages/aws-cdk/test/integ/init/test-java.sh +++ b/packages/aws-cdk/test/integ/init/test-java.sh @@ -21,6 +21,6 @@ for template in $templates; do setup - cdk init -l java -t $template + cdk init -l java $template cdk synth done diff --git a/packages/aws-cdk/test/integ/init/test-javascript.sh b/packages/aws-cdk/test/integ/init/test-javascript.sh index d386eaafbad29..c161d35a5edd1 100755 --- a/packages/aws-cdk/test/integ/init/test-javascript.sh +++ b/packages/aws-cdk/test/integ/init/test-javascript.sh @@ -21,6 +21,6 @@ for template in $templates; do setup - cdk init -l javascript -t $template + cdk init -l javascript $template cdk synth done diff --git a/packages/aws-cdk/test/integ/init/test-python-stackname.sh b/packages/aws-cdk/test/integ/init/test-python-stackname.sh new file mode 100755 index 0000000000000..415c9bdb25cf2 --- /dev/null +++ b/packages/aws-cdk/test/integ/init/test-python-stackname.sh @@ -0,0 +1,7 @@ +#!/bin/bash +# Naming shim for backwards compatibility with legacy +# tests and canaries. +set -eu +scriptdir=$(cd $(dirname $0) && pwd) +init_test_dir=/tmp/cdkInitTest +source $scriptdir/test-python.sh diff --git a/packages/aws-cdk/test/integ/init/test-python.sh b/packages/aws-cdk/test/integ/init/test-python.sh index 0c6304f5c1c5f..33034466f05d0 100755 --- a/packages/aws-cdk/test/integ/init/test-python.sh +++ b/packages/aws-cdk/test/integ/init/test-python.sh @@ -21,7 +21,7 @@ for template in $templates; do setup - cdk init -l python -t $template + cdk init -l python $template source .env/bin/activate type -p pip diff --git a/packages/aws-cdk/test/integ/init/test-typescript.sh b/packages/aws-cdk/test/integ/init/test-typescript.sh index 0943ae90caa04..67a6cb2920729 100755 --- a/packages/aws-cdk/test/integ/init/test-typescript.sh +++ b/packages/aws-cdk/test/integ/init/test-typescript.sh @@ -21,9 +21,13 @@ for template in $templates; do setup - cdk init -l typescript -t $template + cdk init -l typescript $template npm ls # this will fail if we have unmet peer dependencies npm run build npm run test - cdk synth + + # Can't run `cdk synth` on libraries + if [[ $template != "lib" ]]; then + cdk synth + fi done