Skip to content

Commit ad249c9

Browse files
authored
feat(integ-tests): Add IntegTestCase (#19829)
Adds a new construct, `IntegTestCase`, to allow integration test authors to define tests with which they can control the test execution workflow. In future iterations, it will also allow authors to register live infrastructure assertions. ---- ### All Submissions: * [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md) ### Adding new Unconventional Dependencies: * [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md/#adding-new-unconventional-dependencies) ### New Features * [ ] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/master/INTEGRATION_TESTS.md)? * [ ] Did you use `cdk-integ` to deploy the infrastructure and generate the snapshot (i.e. `cdk-integ` without `--dry-run`)? *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 42e5d08 commit ad249c9

File tree

17 files changed

+682
-133
lines changed

17 files changed

+682
-133
lines changed

packages/@aws-cdk/cloud-assembly-schema/lib/integ-tests/test-case.ts

+48-43
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,9 @@
11
import { DeployOptions, DestroyOptions } from './commands';
22

33
/**
4-
* Represents an integration test test case
4+
* The set of options to control the workflow of the test runner
55
*/
6-
export interface TestCase {
7-
/**
8-
* Stacks that should be tested as part of this test case
9-
* The stackNames will be passed as args to the cdk commands
10-
* so dependent stacks will be automatically deployed unless
11-
* `exclusively` is passed
12-
*/
13-
readonly stacks: string[];
14-
6+
export interface TestOptions {
157
/**
168
* Run update workflow on this test case
179
* This should only be set to false to test scenarios
@@ -22,54 +14,67 @@ export interface TestCase {
2214
readonly stackUpdateWorkflow?: boolean;
2315

2416
/**
25-
* Additional options to use for each CDK command
26-
*
27-
* @default - runner default options
28-
*/
17+
* Additional options to use for each CDK command
18+
*
19+
* @default - runner default options
20+
*/
2921
readonly cdkCommandOptions?: CdkCommands;
3022

3123
/**
32-
* Additional commands to run at predefined points in the test workflow
33-
*
34-
* e.g. { postDeploy: ['yarn', 'test'] }
35-
*
36-
* @default - no hooks
37-
*/
24+
* Additional commands to run at predefined points in the test workflow
25+
*
26+
* e.g. { postDeploy: ['yarn', 'test'] }
27+
*
28+
* @default - no hooks
29+
*/
3830
readonly hooks?: Hooks;
3931

4032
/**
41-
* Whether or not to include asset hashes in the diff
42-
* Asset hashes can introduces a lot of unneccessary noise into tests,
43-
* but there are some cases where asset hashes _should_ be included. For example
44-
* any tests involving custom resources or bundling
45-
*
46-
* @default false
47-
*/
33+
* Whether or not to include asset hashes in the diff
34+
* Asset hashes can introduces a lot of unneccessary noise into tests,
35+
* but there are some cases where asset hashes _should_ be included. For example
36+
* any tests involving custom resources or bundling
37+
*
38+
* @default false
39+
*/
4840
readonly diffAssets?: boolean;
4941

5042
/**
51-
* List of CloudFormation resource types in this stack that can
52-
* be destroyed as part of an update without failing the test.
53-
*
54-
* This list should only include resources that for this specific
55-
* integration test we are sure will not cause errors or an outage if
56-
* destroyed. For example, maybe we know that a new resource will be created
57-
* first before the old resource is destroyed which prevents any outage.
58-
*
59-
* e.g. ['AWS::IAM::Role']
60-
*
61-
* @default - do not allow destruction of any resources on update
62-
*/
43+
* List of CloudFormation resource types in this stack that can
44+
* be destroyed as part of an update without failing the test.
45+
*
46+
* This list should only include resources that for this specific
47+
* integration test we are sure will not cause errors or an outage if
48+
* destroyed. For example, maybe we know that a new resource will be created
49+
* first before the old resource is destroyed which prevents any outage.
50+
*
51+
* e.g. ['AWS::IAM::Role']
52+
*
53+
* @default - do not allow destruction of any resources on update
54+
*/
6355
readonly allowDestroy?: string[];
6456

6557
/**
66-
* Limit deployment to these regions
67-
*
68-
* @default - can run in any region
69-
*/
58+
* Limit deployment to these regions
59+
*
60+
* @default - can run in any region
61+
*/
7062
readonly regions?: string[];
7163
}
7264

65+
/**
66+
* Represents an integration test case
67+
*/
68+
export interface TestCase extends TestOptions {
69+
/**
70+
* Stacks that should be tested as part of this test case
71+
* The stackNames will be passed as args to the cdk commands
72+
* so dependent stacks will be automatically deployed unless
73+
* `exclusively` is passed
74+
*/
75+
readonly stacks: string[];
76+
}
77+
7378
/**
7479
* Commands to run at predefined points during the
7580
* integration test workflow

packages/@aws-cdk/integ-runner/README.md

+3-90
Original file line numberDiff line numberDiff line change
@@ -146,98 +146,11 @@ Test Results:
146146
Tests: 1 passed, 1 total
147147
```
148148

149-
150149
### integ.json schema
151150

152151
See [@aws-cdk/cloud-assembly-schema/lib/integ-tests/schema.ts](../cloud-assembly-schema/lib/integ-tests/schema.ts)
153152

154-
### defining an integration test
155-
156-
In most cases an integration test will be an instance of a stack
157-
158-
```ts
159-
import { Function, FunctionOptions } from '../lib';
160-
161-
interface MyIntegTestProps extends StackOptions {
162-
functionProps?: FunctionOptions;
163-
}
164-
class MyIntegTest extends Stack {
165-
constructor(scope: Construct, id: string, props: MyIntegTestProps) {
166-
super(scope, id, props);
167-
168-
new Function(this, 'Handler', {
169-
runtime: Runtime.NODEJS_12_X,
170-
handler: 'index.handler',
171-
code: Code.fromAsset(path.join(__dirname, 'lambda-handler')),
172-
...props.functionProps,
173-
});
174-
}
175-
}
176-
```
153+
### Defining an integration test
177154

178-
You would then use the `IntegTest` construct to create your test cases
179-
180-
```ts
181-
new IntegTeset(app, 'ArmTest', {
182-
stacks: [
183-
new MyIntegTest(app, 'Stack1', {
184-
functionProps: {
185-
architecture: lambda.Architecture.ARM_64,
186-
},
187-
}),
188-
],
189-
diffAssets: true,
190-
update: true,
191-
cdkCommandOptions: {
192-
deploy: {
193-
args: {
194-
requireApproval: RequireApproval.NEVER,
195-
json: true,
196-
},
197-
},
198-
destroy: {
199-
args: {
200-
force: true,
201-
},
202-
},
203-
},
204-
});
205-
206-
new IntegTeset(app, 'AmdTest', {
207-
stacks: [
208-
new MyIntegTest(app, 'Stack2', {
209-
functionProps: {
210-
architecture: lambda.Architecture.X86_64,
211-
},
212-
}),
213-
],
214-
});
215-
```
216-
217-
This will synthesize an `integ.json` file with the following contents
218-
219-
```json
220-
{
221-
"ArmTest": {
222-
"stacks": ["Stack1"],
223-
"diffAssets": true,
224-
"update": true,
225-
"cdkCommands": {
226-
"deploy": {
227-
"args": {
228-
"requireApproval": "never",
229-
"json": true
230-
}
231-
},
232-
"destroy": {
233-
"args": {
234-
"force": true
235-
}
236-
}
237-
}
238-
},
239-
"AmdTest": {
240-
"stacks": ["Stack2"]
241-
}
242-
}
243-
```
155+
See the `@aws-cdk/integ-tests` module for information on how to define
156+
integration tests for the runner to exercise.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const baseConfig = require('@aws-cdk/cdk-build-tools/config/eslintrc');
2+
baseConfig.parserOptions.project = __dirname + '/tsconfig.json';
3+
module.exports = baseConfig;
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
*.js
2+
tsconfig.json
3+
*.js.map
4+
*.d.ts
5+
*.generated.ts
6+
dist
7+
lib/generated/resources.ts
8+
.jsii
9+
10+
.LAST_BUILD
11+
.nyc_output
12+
coverage
13+
nyc.config.js
14+
.LAST_PACKAGE
15+
*.snk
16+
!.eslintrc.js
17+
18+
junit.xml
19+
!jest.config.js
+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Don't include original .ts files when doing `npm pack`
2+
*.ts
3+
!*.d.ts
4+
coverage
5+
.nyc_output
6+
*.tgz
7+
8+
dist
9+
.LAST_PACKAGE
10+
.LAST_BUILD
11+
!*.js
12+
13+
# Include .jsii
14+
!.jsii
15+
16+
*.snk
17+
18+
*.tsbuildinfo
19+
20+
tsconfig.json
21+
.eslintrc.js
22+
23+
# exclude cdk artifacts
24+
**/cdk.out
25+
junit.xml
26+
test/
27+
jest.config.js
28+
!*.lit.ts

0 commit comments

Comments
 (0)