/
test-case.ts
198 lines (179 loc) · 4.75 KB
/
test-case.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
import { DeployOptions, DestroyOptions } from './commands';
/**
* The set of options to control the workflow of the test runner
*/
export interface TestOptions {
/**
* Run update workflow on this test case
* This should only be set to false to test scenarios
* that are not possible to test as part of the update workflow
*
* @default true
*/
readonly stackUpdateWorkflow?: boolean;
/**
* 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
*/
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
*/
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
*/
readonly allowDestroy?: string[];
/**
* 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[];
/**
* The name of the stack that contains assertions
*
* @default - no assertion stack
*/
readonly assertionStack?: string;
}
/**
* Commands to run at predefined points during the
* integration test workflow
*/
export interface Hooks {
/**
* Commands to run prior to deploying the cdk stacks
* in the integration test
*
* @default - no commands
*/
readonly preDeploy?: string[];
/**
* Commands to run prior after deploying the cdk stacks
* in the integration test
*
* @default - no commands
*/
readonly postDeploy?: string[];
/**
* Commands to run prior to destroying the cdk stacks
* in the integration test
*
* @default - no commands
*/
readonly preDestroy?: string[];
/**
* Commands to run after destroying the cdk stacks
* in the integration test
*
* @default - no commands
*/
readonly postDestroy?: string[];
}
/**
* Represents a cdk command
* i.e. `synth`, `deploy`, & `destroy`
*/
export interface CdkCommand {
/**
* Whether or not to run this command as part of the workflow
* This can be used if you only want to test some of the workflow
* for example enable `synth` and disable `deploy` & `destroy` in order
* to limit the test to synthesis
*
* @default true
*/
readonly enabled?: boolean;
/**
* If the runner should expect this command to fail
*
* @default false
*/
readonly expectError?: boolean;
/**
* This can be used in combination with `expectedError`
* to validate that a specific message is returned.
*
* @default - do not validate message
*/
readonly expectedMessage?: string;
}
/**
* Represents a cdk deploy command
*/
export interface DeployCommand extends CdkCommand {
/**
* Additional arguments to pass to the command
* This can be used to test specific CLI functionality
*
* @default - only default args are used
*/
readonly args?: DeployOptions;
}
/**
* Represents a cdk destroy command
*/
export interface DestroyCommand extends CdkCommand {
/**
* Additional arguments to pass to the command
* This can be used to test specific CLI functionality
*
* @default - only default args are used
*/
readonly args?: DestroyOptions;
}
/**
* Options for specific cdk commands that are run
* as part of the integration test workflow
*/
export interface CdkCommands {
/**
* Options to for the cdk deploy command
*
* @default - default deploy options
*/
readonly deploy?: DeployCommand;
/**
* Options to for the cdk destroy command
*
* @default - default destroy options
*/
readonly destroy?: DestroyCommand;
}