Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(integ-tests): Add IntegTestCase #19829

Merged
merged 43 commits into from
Apr 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
32f2a3f
chore(integ-runner): add a manifest writer
otaviomacedo Apr 7, 2022
b915908
Moved writer to a new package
otaviomacedo Apr 8, 2022
86ea9dd
feat(integ-tests): added `IntegTestCase` construct
otaviomacedo Apr 8, 2022
b2e0a80
Simplified snapshot dir logic and removed the stack
otaviomacedo Apr 11, 2022
e769393
Added README
otaviomacedo Apr 11, 2022
1aec060
chore(release): 1.152.0
Apr 6, 2022
1dd2d8b
fix(eks): malformed command when installing helm chart from OCI artif…
tsahiduek Apr 7, 2022
57642e8
chore: add mistakenly dropped cfn-parse.ts to core (#19804)
kaizencc Apr 7, 2022
4794a34
fix(aws-cloudfront): Add sslSupportMethod (#19737)
dayjournal Apr 7, 2022
64c1422
feat(cfnspec): cloudformation spec v66.0.0 (#19812)
robertd Apr 8, 2022
2867d1e
docs: fix word order in template READMEs (#19808)
ralph-tice Apr 8, 2022
aa69529
chore: add new style integration test snapshots (#19802)
corymhall Apr 8, 2022
bdcadfc
docs(cfnspec): update CloudFormation documentation (#19819)
aws-cdk-automation Apr 8, 2022
78eaf9f
fix(core): exportValue does not work on number attributes (#19818)
rix0rrr Apr 8, 2022
1878008
chore: fix typo in warning (#19810)
rcollette Apr 8, 2022
1bca40a
chore(rds): add missing Aurora PG versions (#19811)
robertd Apr 8, 2022
2e32550
fix(autoscaling): update validation on maxInstanceLifetime (#19584)
jungseoklee Apr 8, 2022
a1ba867
chore: Builds now work with Windows Subsystem for Linux (WSL). (#17513)
Litee Apr 8, 2022
973f6ff
chore: switch to using the new integ-runner (#19826)
corymhall Apr 8, 2022
7bca49f
feat(iotevents): support comparison operators (#19329)
yamatatsu Apr 8, 2022
87ca3ab
fix(rds): MySQL 8.0 uses wrong Parameter for S3 export (#19775)
skinny85 Apr 8, 2022
9e05478
feat(apigatewayv2): set throttling on stages (#19776)
peterwoodworth Apr 8, 2022
200c51d
chore(cloudfront): Add `trustedSigners` to V2. (#19839)
comcalvi Apr 9, 2022
10fe28f
chore: npm-check-updates && yarn upgrade (#19788)
aws-cdk-automation Apr 9, 2022
b940e5d
chore(docs): add missing word / fix typo (#19849)
ZackKanter Apr 11, 2022
ab3c740
feat: check for accidental exposure of secrets (#19543)
rix0rrr Apr 11, 2022
b0109b2
docs(cfnspec): update CloudFormation documentation (#19854)
aws-cdk-automation Apr 11, 2022
375cdb0
chore(deps): Bump hmarr/auto-approve-action from 2.2.0 to 2.2.1 (#19855)
dependabot[bot] Apr 11, 2022
3b3a6d2
chore(deps): Bump aws-actions/stale-issue-cleanup from 3 to 5 (#19856)
dependabot[bot] Apr 11, 2022
415cfe9
feat(cli): glob-style key matching to context --reset (#19840)
gillisandrew Apr 11, 2022
e7846c6
Added tsconfig.json
otaviomacedo Apr 11, 2022
1e204ab
Added jsii config
otaviomacedo Apr 11, 2022
09cf3c1
Merge branch 'master' into otaviom/integ-test-case-construct
otaviomacedo Apr 11, 2022
77928e6
Merge branch 'master' into otaviom/integ-test-case-construct
otaviomacedo Apr 11, 2022
eaad71b
Fixed README
otaviomacedo Apr 11, 2022
ec0177d
Added newline at the end of README
otaviomacedo Apr 12, 2022
e85a27a
Added integ-tests to aws-cdk-lib's dependencies
otaviomacedo Apr 12, 2022
2e2aa6e
Added @aws-cdk/integ-tests to monocdk's dependencies
otaviomacedo Apr 12, 2022
2210580
Make the README snippets compile
otaviomacedo Apr 12, 2022
9b1c83f
Changed the API to have stacks instead of ids
otaviomacedo Apr 12, 2022
6baf6ab
Added documentation
otaviomacedo Apr 12, 2022
fb4f15d
Removed THIRD_PARTY_LICENSES
otaviomacedo Apr 12, 2022
8db678f
Merge branch 'master' into otaviom/integ-test-case-construct
mergify[bot] Apr 12, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
import { DeployOptions, DestroyOptions } from './commands';

/**
* Represents an integration test test case
* The set of options to control the workflow of the test runner
*/
export interface TestCase {
/**
* Stacks that should be tested as part of this test case
* The stackNames will be passed as args to the cdk commands
* so dependent stacks will be automatically deployed unless
* `exclusively` is passed
*/
readonly stacks: string[];

export interface TestOptions {
/**
* Run update workflow on this test case
* This should only be set to false to test scenarios
Expand All @@ -22,54 +14,67 @@ export interface TestCase {
readonly stackUpdateWorkflow?: boolean;

/**
* Additional options to use for each CDK command
*
* @default - runner default options
*/
* Additional options to use for each CDK command
*
* @default - runner default options
*/
readonly cdkCommandOptions?: CdkCommands;

/**
* Additional commands to run at predefined points in the test workflow
*
* e.g. { postDeploy: ['yarn', 'test'] }
*
* @default - no hooks
*/
* Additional commands to run at predefined points in the test workflow
*
* e.g. { postDeploy: ['yarn', 'test'] }
*
* @default - no hooks
*/
readonly hooks?: Hooks;

/**
* Whether or not to include asset hashes in the diff
* Asset hashes can introduces a lot of unneccessary noise into tests,
* but there are some cases where asset hashes _should_ be included. For example
* any tests involving custom resources or bundling
*
* @default false
*/
* Whether or not to include asset hashes in the diff
* Asset hashes can introduces a lot of unneccessary noise into tests,
* but there are some cases where asset hashes _should_ be included. For example
* any tests involving custom resources or bundling
*
* @default false
*/
readonly diffAssets?: boolean;

/**
* List of CloudFormation resource types in this stack that can
* be destroyed as part of an update without failing the test.
*
* This list should only include resources that for this specific
* integration test we are sure will not cause errors or an outage if
* destroyed. For example, maybe we know that a new resource will be created
* first before the old resource is destroyed which prevents any outage.
*
* e.g. ['AWS::IAM::Role']
*
* @default - do not allow destruction of any resources on update
*/
* List of CloudFormation resource types in this stack that can
* be destroyed as part of an update without failing the test.
*
* This list should only include resources that for this specific
* integration test we are sure will not cause errors or an outage if
* destroyed. For example, maybe we know that a new resource will be created
* first before the old resource is destroyed which prevents any outage.
*
* e.g. ['AWS::IAM::Role']
*
* @default - do not allow destruction of any resources on update
*/
readonly allowDestroy?: string[];

/**
* Limit deployment to these regions
*
* @default - can run in any region
*/
* Limit deployment to these regions
*
* @default - can run in any region
*/
readonly regions?: string[];
}

/**
* Represents an integration test case
*/
export interface TestCase extends TestOptions {
/**
* Stacks that should be tested as part of this test case
* The stackNames will be passed as args to the cdk commands
* so dependent stacks will be automatically deployed unless
* `exclusively` is passed
*/
readonly stacks: string[];
}

/**
* Commands to run at predefined points during the
* integration test workflow
Expand Down
93 changes: 3 additions & 90 deletions packages/@aws-cdk/integ-runner/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,98 +146,11 @@ Test Results:
Tests: 1 passed, 1 total
```


### integ.json schema

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

### defining an integration test

In most cases an integration test will be an instance of a stack

```ts
import { Function, FunctionOptions } from '../lib';

interface MyIntegTestProps extends StackOptions {
functionProps?: FunctionOptions;
}
class MyIntegTest extends Stack {
constructor(scope: Construct, id: string, props: MyIntegTestProps) {
super(scope, id, props);

new Function(this, 'Handler', {
runtime: Runtime.NODEJS_12_X,
handler: 'index.handler',
code: Code.fromAsset(path.join(__dirname, 'lambda-handler')),
...props.functionProps,
});
}
}
```
### Defining an integration test

You would then use the `IntegTest` construct to create your test cases

```ts
new IntegTeset(app, 'ArmTest', {
stacks: [
new MyIntegTest(app, 'Stack1', {
functionProps: {
architecture: lambda.Architecture.ARM_64,
},
}),
],
diffAssets: true,
update: true,
cdkCommandOptions: {
deploy: {
args: {
requireApproval: RequireApproval.NEVER,
json: true,
},
},
destroy: {
args: {
force: true,
},
},
},
});

new IntegTeset(app, 'AmdTest', {
stacks: [
new MyIntegTest(app, 'Stack2', {
functionProps: {
architecture: lambda.Architecture.X86_64,
},
}),
],
});
```

This will synthesize an `integ.json` file with the following contents

```json
{
"ArmTest": {
"stacks": ["Stack1"],
"diffAssets": true,
"update": true,
"cdkCommands": {
"deploy": {
"args": {
"requireApproval": "never",
"json": true
}
},
"destroy": {
"args": {
"force": true
}
}
}
},
"AmdTest": {
"stacks": ["Stack2"]
}
}
```
See the `@aws-cdk/integ-tests` module for information on how to define
integration tests for the runner to exercise.
3 changes: 3 additions & 0 deletions packages/@aws-cdk/integ-tests/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const baseConfig = require('@aws-cdk/cdk-build-tools/config/eslintrc');
baseConfig.parserOptions.project = __dirname + '/tsconfig.json';
module.exports = baseConfig;
19 changes: 19 additions & 0 deletions packages/@aws-cdk/integ-tests/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
*.js
tsconfig.json
*.js.map
*.d.ts
*.generated.ts
dist
lib/generated/resources.ts
.jsii

.LAST_BUILD
.nyc_output
coverage
nyc.config.js
.LAST_PACKAGE
*.snk
!.eslintrc.js

junit.xml
!jest.config.js
28 changes: 28 additions & 0 deletions packages/@aws-cdk/integ-tests/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Don't include original .ts files when doing `npm pack`
*.ts
!*.d.ts
coverage
.nyc_output
*.tgz

dist
.LAST_PACKAGE
.LAST_BUILD
!*.js

# Include .jsii
!.jsii

*.snk

*.tsbuildinfo

tsconfig.json
.eslintrc.js

# exclude cdk artifacts
**/cdk.out
junit.xml
test/
jest.config.js
!*.lit.ts
Loading