You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CONTRIBUTING.md
+8-16Lines changed: 8 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -256,7 +256,7 @@ Work your magic. Here are some guidelines:
256
256
257
257
Integration tests perform a few functions in the CDK code base -
258
258
1. Acts as a regression detector. It does this by running `cdk synth` on the integration test and comparing it against
259
-
the `*.expected.json` file. This highlights how a change affects the synthesized stacks.
259
+
the `*.integ.snapshot` directory. This highlights how a change affects the synthesized stacks.
260
260
2. Allows for a way to verify if the stacks are still valid CloudFormation templates, as part of an intrusive change.
261
261
This is done by running `yarn integ` which will run `cdk deploy` across all of the integration tests in that package. If you are developing a new integration test or for some other reason want to work on a single integration test over and over again without running through all the integration tests you can do so using `yarn integ integ.test-name.js`
262
262
Remember to set up AWS credentials before doing this.
@@ -275,9 +275,10 @@ new features unless there is a good reason why one is not needed.
275
275
4. Adding a new supported version (e.g. a new [AuroraMysqlEngineVersion](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_rds.AuroraMysqlEngineVersion.html))
276
276
5. Adding any functionality via a [Custom Resource](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.custom_resources-readme.html)
277
277
278
-
To the extent possible, include a section (like below) in the integration test file that specifies how the successfully
279
-
deployed stack can be verified for correctness. Correctness here implies that the resources have been set up correctly.
280
-
The steps here are usually AWS CLI commands but they need not be.
278
+
All integration tests going forward should use the [IntegTest](https://github.com/aws/aws-cdk/tree/main/packages/%40aws-cdk/integ-tests)
279
+
construct. Over time we will be updating all of our existing tests to use this construct. It
280
+
allows for more control over configuring each tests as well as the ability to perform
281
+
assertions against the deployed infrastructure.
281
282
282
283
```ts
283
284
/*
@@ -288,8 +289,8 @@ The steps here are usually AWS CLI commands but they need not be.
@@ -223,7 +228,52 @@ but it will not validate that the Lambda function can be invoked. Because of thi
223
228
to deploy the Lambda Function _and_ then rerun the assertions to ensure that the function can still be invoked.
224
229
225
230
### Assertions
226
-
...Coming soon...
231
+
232
+
Sometimes it is necessary to perform some form of _assertion_ against the deployed infrastructure to validate that the
233
+
test succeeds. A good example of this is the `@aws-cdk/aws-stepfunctions-tasks` module which creates integrations between
234
+
AWS StepFunctions and other AWS services.
235
+
236
+
If we look at the [integ.put-events.ts](https://github.com/aws/aws-cdk/blob/main/packages/%40aws-cdk/aws-stepfunctions-tasks/test/eventbridge/integ.put-events.ts)
237
+
integration test we can see that we are creating an `@aws-cdk/aws-events.EventBus` along with a `@aws-cdk/aws-stepfunctions.StateMachine`
238
+
which will send an event to the `EventBus`. In a typical integration test we would just deploy the test and the fact that the
239
+
infrastructure deployed successfully would be enough of a validation that the test succeeded. In this case though, we ideally
240
+
want to validate that the _integration_ connecting `StepFunctions` to the `EventBus` has been setup correctly, and the only
241
+
way to do that is to actually trigger the `StateMachine` and validate that it was successful.
Not every test requires an assertion. We typically do not need to assert CloudFormation behavior. For example, if we create an S3 Bucket
269
+
with Encryption, we do not need to assert that Encryption is set on the bucket. We can trust that the CloudFormation behavior works.
270
+
Some things you should look for in deciding if the test needs an assertion:
271
+
272
+
- Integrations between services (i.e. integration libraries like `@aws-cdk/aws-lambda-destinations`, `@aws-cdk/aws-stepfunctions-tasks`, etc)
273
+
- Anything that bundles or deploys custom code (i.e. does a Lambda function bundled with `@aws-cdk/aws-lambda-nodejs` still invoke or did we break bundling behavior)
274
+
- IAM/Networking connections.
275
+
- This one is a bit of a judgement call. Most things do not need assertions, but sometimes we handle complicated configurations involving IAM permissions or
0 commit comments