aws / aws-cdk

The AWS Cloud Development Kit is a framework for defining cloud infrastructure in code
https://aws.amazon.com/cdk
Apache License 2.0
11.66k stars 3.92k forks source link

(integ_tests_alpha): Support non-TypeScript tests #21169

Open tomeszmh opened 2 years ago

tomeszmh commented 2 years ago

Describe the bug

I have written a simple integration test case to my stack in Python, but I am not able to run it. I used integ-runner and tried with cdk deploy --app "python integration_test.py" but it seems none of them are working. Is this feature available only with ts library?

Many thanks

Expected Behavior

Able to run my tests.

Current Behavior

yarn's integ-runner cli uses *ts files to run tests, so with my python code it will not compile

with cdk deploy --app "python integ_tests.py" the stack deployed, but nothing happened

Reproduction Steps

app = App()

stack = Stack(app, "stack",env=default_env)
integ = IntegTest(app, "Integ", test_cases=[stack])

invoke = integ.assertions.invoke_function(
    function_name=stack.writer_lambda.function_name
)
invoke.expect(ExpectedResult.object_like({
    "Payload": "200"
}))

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.28.0 (build ba233f0)

Framework Version

No response

Node.js Version

16.15.1

OS

Mac OS 12.3.1

Language

Python

Language Version

3.9.4

Other information

No response

rix0rrr commented 2 years ago

This might be true. It probably wouldn't be too hard to add support for this, although it might get complex for other languages as we don't necessarily know the CDK app's interpreter (as the integ tests are lacking a cdk.json).

GroovyDan commented 2 years ago

+1 for python support

tomeszmh commented 1 year ago

Any news on this one?

mrgrain commented 1 year ago

Support for --app and --test-regex already landed. As well as support for config files so you don't have to type these all the time. With that, it's already possible to run any language integration test. We are still working on ready-to-use presets.

tomeszmh commented 1 year ago

Thanks a lot!

And is it possible to change the generated SingletonFunctionRole's Path attribute, or add another execution role for the lambda?

I have created an AwsApiCall, but I cannot see any possibility to parameterize the resources created inside the AwsApiCall object.

mrgrain commented 1 year ago

Thanks a lot!

And is it possible to change the generated SingletonFunctionRole's Path attribute, or add another execution role for the lambda?

I have created an AwsApiCall, but I cannot see any possibility to parameterize the resources created inside the AwsApiCall object.

Sounds possible. Please open a new issue for this so we can track it. Pull Requests are also welcome!

mrgrain commented 1 year ago

22058 will soon introduce language presets for js, ts and python.

These languages will still be unsupported due to lack of testing, but should be added asap:

{     
      // works but it's a bit ugly to need to have a project per test case - is there a better solution?
      csharp: ['dotnet run --project {filePath}', ['^Integ.*\\.csproj$']],
      fsharp: ['dotnet run --project {filePath}', ['^Integ.*\\.fsproj$']],
      // this doesn't work. See previous PR attempts for ideas
      java: ['mvn -e -q compile exec:java', ['^Integ.*\\.java$']],
}
mrgrain commented 1 year ago

Language preset for javascript typescript python and go have landed.

My experience with .NET and Java projects is limited so I'm looking for good ideas how these projects would expect integration tests to be structured.

Particularly for .NET it appears we need a different project per test because each integ tests needs to be in a Main. 🤔