Skip to content

Commit

Permalink
fix: java and python templates are broken (aws#17357)
Browse files Browse the repository at this point in the history
There are two problems.

### Python

The `app` template doesn't define any tests (it does, but they are commented out), this makes `pytest` fail during our integ tests:

```console
============================= test session starts ==============================
970 | platform linux -- Python 3.7.3, pytest-6.2.5, py-1.11.0, pluggy-1.0.0
971 | rootdir: /tmp/cdk-init-test
972 | collected 0 items
973 |  
974 | ============================ no tests ran in 0.01s =============================
975 | + run_traps
976 | + for cmd in "${TRAPS[@]}"
977 | + echo 'cleanup: kill 121'
978 | cleanup: kill 121
979 | + eval 'kill 121'
980 | ++ kill 121
981 | + for cmd in "${TRAPS[@]}"
982 | + echo 'cleanup: clean_up_nuget_config'
983 | cleanup: clean_up_nuget_config
984 | + eval clean_up_nuget_config
985 | ++ clean_up_nuget_config
986 | ++ log 'Restoring NuGet configuration'
987 | ++ echo '\| Restoring NuGet configuration'
988 | \| Restoring NuGet configuration
989 | ++ '[' -f /root/.nuget/NuGet/NuGet.Config.bak ']'
990 | ++ log '-> Removing /root/.nuget/NuGet/NuGet.Config'
991 | ++ echo '\| -> Removing /root/.nuget/NuGet/NuGet.Config'
992 | \| -> Removing /root/.nuget/NuGet/NuGet.Config
993 | ++ rm -f /root/.nuget/NuGet/NuGet.Config
994 |  
995 | [Container] 2021/11/05 05:05:43 Command did not exit successfully /bin/bash /tmp/scriptdir/cdk/init-templates/dispatch.sh exit status 5
996 | [Container] 2021/11/05 05:05:43 Phase complete: BUILD State: FAILED
997 | [Container] 2021/11/05 05:05:43 Phase context status code: COMMAND_EXECUTION_ERROR Message: Error while executing command: /bin/bash /tmp/scriptdir/cdk/init-templates/dispatch.sh. Reason: exit status 5
998 | [Container] 2021/11/05 05:05:43 Entering phase POST_BUILD
999 | [Container] 2021/11/05 05:05:43 Phase complete: POST_BUILD State: SUCCEEDED
1000 | [Container] 2021/11/05 05:05:43 Phase context status code:  Message:
1001

<br class="Apple-interchange-newline">
```

Solution is to uncomment the test method signature and making it an empty test, just like we do with typescript. 

### Java

`Map.of` doesn't exist in Java 8 and we are getting complication errors during `mvn package`:

```console
[INFO] -------------------------------------------------------------
--
1018 | [ERROR] COMPILATION ERROR :
1019 | [INFO] -------------------------------------------------------------
1020 | [ERROR] /tmp/cdk-init-test/src/test/java/com/myorg/CdkInitTestStackTest.java:[21,62] cannot find symbol
1021 | symbol:   method of(java.lang.String,int)
1022 | location: interface java.util.Map
1023 | [INFO] 1 error
```

Solution is to replace `Map.of` with `new HashMap` that is supported everywhere. 

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
iliapolo authored and TikiTDO committed Feb 21, 2022
1 parent 9850be8 commit 71b5b73
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 19 deletions.
1 change: 1 addition & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -978,3 +978,4 @@ $ node --inspect-brk /path/to/aws-cdk/node_modules/.bin/jest -i -t 'TESTNAME'
* [Workshop](https://github.com/aws-samples/aws-cdk-intro-workshop): source for https://cdkworkshop.com
* [Developer Guide](https://github.com/awsdocs/aws-cdk-guide): markdown source for developer guide
* [jsii](https://github.com/aws/jsii): the technology we use for multi-language support. If you are looking to help us support new languages, start there.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// import software.amazon.awscdk.assertions.Template;
// import java.io.IOException;

// import java.util.Map;
// import java.util.HashMap;

// import org.junit.jupiter.api.Test;

Expand All @@ -19,8 +19,8 @@

// Template template = Template.fromStack(stack);

// template.hasResourceProperties("AWS::SQS::Queue", Map.of(
// "VisibilityTimeout", 300
// ));
// template.hasResourceProperties("AWS::SQS::Queue", new HashMap<String, Number>() {{
// put("VisibilityTimeout", 300);
// }});
// }
// }
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
aws-cdk.core>=%cdk-version%,
aws-cdk.assertions>=%cdk-version%,
aws-cdk.core>=%cdk-version%
aws-cdk.assertions>=%cdk-version%
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@

# example tests. To run these tests, uncomment this file along with the example
# resource in %name.PythonModule%/%name.PythonModule%_stack.py
# def test_sqs_queue_created():
def test_sqs_queue_created():
# app = core.App()
# stack = %name.PascalCased%Stack(app, "%name.StackName%")
# template = assertions.Template.from_stack(stack)

# template.has_resource_properties("AWS::SQS::Queue", {
# "VisibilityTimeout": 300
# })
pass
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import software.amazon.awscdk.assertions.Match;
import java.io.IOException;

import java.util.Map;
import java.util.HashMap;

import org.junit.jupiter.api.Test;

Expand All @@ -18,9 +18,9 @@ public void testStack() throws IOException {

Template template = Template.fromStack(stack);

template.hasResourceProperties("AWS::SQS::Queue", Map.of(
"VisibilityTimeout", 300
));
template.hasResourceProperties("AWS::SQS::Queue", new HashMap<String, Number>() {{
put("VisibilityTimeout", 300);
}});
template.resourceCountIs("AWS::SNS::Topic", 1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// import software.amazon.awscdk.assertions.alpha.Template;
// import java.io.IOException;

// import java.util.Map;
// import java.util.HashMap;

// import org.junit.jupiter.api.Test;

Expand All @@ -19,8 +19,8 @@

// Template template = Template.fromStack(stack);

// template.hasResourceProperties("AWS::SQS::Queue", Map.of(
// "VisibilityTimeout", 300
// ));
// template.hasResourceProperties("AWS::SQS::Queue", new HashMap<String, Number>() {{
// put("VisibilityTimeout", 300);
// }});
// }
// }
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import software.amazon.awscdk.assertions.alpha.Match;
import java.io.IOException;

import java.util.Map;
import java.util.HashMap;

import org.junit.jupiter.api.Test;

Expand All @@ -18,9 +18,9 @@ public void testStack() throws IOException {

Template template = Template.fromStack(stack);

template.hasResourceProperties("AWS::SQS::Queue", Map.of(
"VisibilityTimeout", 300
));
template.hasResourceProperties("AWS::SQS::Queue", new HashMap<String, Number>() {{
put("VisibilityTimeout", 300);
}});

template.resourceCountIs("AWS::SNS::Topic", 1);
}
Expand Down

0 comments on commit 71b5b73

Please sign in to comment.