Skip to content

Commit

Permalink
fix(cli): Fix various init templates & their tests (#5693)
Browse files Browse the repository at this point in the history
* fix(cli): init tests should run for each template

* fix(cli): fix init templates for sample-app & lib
  • Loading branch information
netroy authored and mergify[bot] committed Jan 15, 2020
1 parent c02741e commit a85da79
Show file tree
Hide file tree
Showing 17 changed files with 35 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace HelloCdk
namespace %name.PascalCased%

open Amazon.CDK
open Amazon.CDK.AWS.SNS
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
open Amazon.CDK
open %name.PascalCased%Stack
open %name.PascalCased%

[<EntryPoint>]
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
Original file line number Diff line number Diff line change
Expand Up @@ -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")));
}
}
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


setuptools.setup(
name="%name%",
name="%name.PythonModule%",
version="0.0.1",

description="A sample CDK Python app",
Expand All @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
2 changes: 1 addition & 1 deletion packages/aws-cdk/test/integ/init/common.bash
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/aws-cdk/test/integ/init/test-csharp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ for template in $templates; do

setup

cdk init -l csharp -t $template
cdk init -l csharp $template
cdk synth
done
2 changes: 1 addition & 1 deletion packages/aws-cdk/test/integ/init/test-fsharp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ for template in $templates; do

setup

cdk init -l fsharp -t $template
cdk init -l fsharp $template
cdk synth
done
2 changes: 1 addition & 1 deletion packages/aws-cdk/test/integ/init/test-java.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ for template in $templates; do

setup

cdk init -l java -t $template
cdk init -l java $template
cdk synth
done
2 changes: 1 addition & 1 deletion packages/aws-cdk/test/integ/init/test-javascript.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ for template in $templates; do

setup

cdk init -l javascript -t $template
cdk init -l javascript $template
cdk synth
done
7 changes: 7 additions & 0 deletions packages/aws-cdk/test/integ/init/test-python-stackname.sh
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion packages/aws-cdk/test/integ/init/test-python.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions packages/aws-cdk/test/integ/init/test-typescript.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit a85da79

Please sign in to comment.