@@ -177,12 +177,7 @@ new IntegTest(app, 'Integ', { testCases: [stackUnderTest, testCaseWithAssets] })
177
177
178
178
This library also provides a utility to make assertions against the infrastructure that the integration test deploys.
179
179
180
- There are two main scenarios in which assertions are created.
181
-
182
- - Part of an integration test using ` integ-runner `
183
-
184
- In this case you would create an integration test using the ` IntegTest ` construct and then make assertions using the ` assert ` property.
185
- You should ** not** utilize the assertion constructs directly, but should instead use the ` methods ` on ` IntegTest.assert ` .
180
+ The easiest way to do this is to create a ` TestCase ` and then access the ` DeployAssert ` that is automatically created.
186
181
187
182
``` ts
188
183
declare const app: App ;
@@ -192,35 +187,31 @@ const integ = new IntegTest(app, 'Integ', { testCases: [stack] });
192
187
integ .assert .awsApiCall (' S3' , ' getObject' );
193
188
```
194
189
195
- - Part of a normal CDK deployment
190
+ ### DeployAssert
191
+
192
+ Assertions are created by using the ` DeployAssert ` construct. This construct creates it's own ` Stack ` separate from
193
+ any stacks that you create as part of your integration tests. This ` Stack ` is treated differently from other stacks
194
+ by the ` integ-runner ` tool. For example, this stack will not be diffed by the ` integ-runner ` .
196
195
197
- In this case you may be using assertions as part of a normal CDK deployment in order to make an assertion on the infrastructure
198
- before the deployment is considered successful. In this case you can utilize the assertions constructs directly.
196
+ Any assertions that you create should be created in the scope of ` DeployAssert ` . For example,
199
197
200
198
``` ts
201
- declare const myAppStack : Stack ;
199
+ declare const app : App ;
202
200
203
- new AwsApiCall (myAppStack , ' GetObject' , {
201
+ const assert = new DeployAssert (app );
202
+ new AwsApiCall (assert , ' GetObject' , {
204
203
service: ' S3' ,
205
204
api: ' getObject' ,
206
205
});
207
206
```
208
207
209
- ### DeployAssert
210
-
211
- Assertions are created by using the ` DeployAssert ` construct. This construct creates it's own ` Stack ` separate from
212
- any stacks that you create as part of your integration tests. This ` Stack ` is treated differently from other stacks
213
- by the ` integ-runner ` tool. For example, this stack will not be diffed by the ` integ-runner ` .
214
-
215
208
` DeployAssert ` also provides utilities to register your own assertions.
216
209
217
210
``` ts
218
211
declare const myCustomResource: CustomResource ;
219
- declare const stack: Stack ;
220
212
declare const app: App ;
221
-
222
- const integ = new IntegTest (app , ' Integ' , { testCases: [stack ] });
223
- integ .assert .assert (
213
+ const assert = new DeployAssert (app );
214
+ assert .assert (
224
215
' CustomAssertion' ,
225
216
ExpectedResult .objectLike ({ foo: ' bar' }),
226
217
ActualResult .fromCustomResource (myCustomResource , ' data' ),
@@ -237,12 +228,12 @@ AWS API call to receive some data. This library does this by utilizing CloudForm
237
228
which means that CloudFormation will call out to a Lambda Function which will
238
229
use the AWS JavaScript SDK to make the API call.
239
230
240
- This can be done by using the class directory (in the case of a normal deployment) :
231
+ This can be done by using the class directory:
241
232
242
233
``` ts
243
- declare const stack : Stack ;
234
+ declare const assert : DeployAssert ;
244
235
245
- new AwsApiCall (stack , ' MyAssertion' , {
236
+ new AwsApiCall (assert , ' MyAssertion' , {
246
237
service: ' SQS' ,
247
238
api: ' receiveMessage' ,
248
239
parameters: {
@@ -251,15 +242,12 @@ new AwsApiCall(stack, 'MyAssertion', {
251
242
});
252
243
```
253
244
254
- Or by using the ` awsApiCall ` method on ` DeployAssert ` (when writing integration tests) :
245
+ Or by using the ` awsApiCall ` method on ` DeployAssert ` :
255
246
256
247
``` ts
257
248
declare const app: App ;
258
- declare const stack: Stack ;
259
- const integ = new IntegTest (app , ' Integ' , {
260
- testCases: [stack ],
261
- });
262
- integ .assert .awsApiCall (' SQS' , ' receiveMessage' , {
249
+ const assert = new DeployAssert (app );
250
+ assert .awsApiCall (' SQS' , ' receiveMessage' , {
263
251
QueueUrl: ' url' ,
264
252
});
265
253
```
@@ -293,18 +281,21 @@ const message = integ.assert.awsApiCall('SQS', 'receiveMessage', {
293
281
WaitTimeSeconds: 20 ,
294
282
});
295
283
296
- message .assertAtPath (' Messages.0.Body' , ExpectedResult .objectLike ({
297
- requestContext: {
298
- condition: ' Success' ,
299
- },
300
- requestPayload: {
301
- status: ' OK' ,
302
- },
303
- responseContext: {
304
- statusCode: 200 ,
305
- },
306
- responsePayload: ' success' ,
307
- }));
284
+ new EqualsAssertion (integ .assert , ' ReceiveMessage' , {
285
+ actual: ActualResult .fromAwsApiCall (message , ' Messages.0.Body' ),
286
+ expected: ExpectedResult .objectLike ({
287
+ requestContext: {
288
+ condition: ' Success' ,
289
+ },
290
+ requestPayload: {
291
+ status: ' OK' ,
292
+ },
293
+ responseContext: {
294
+ statusCode: 200 ,
295
+ },
296
+ responsePayload: ' success' ,
297
+ }),
298
+ });
308
299
```
309
300
310
301
#### Match
@@ -314,6 +305,7 @@ can be used to construct the `ExpectedResult`.
314
305
315
306
``` ts
316
307
declare const message: AwsApiCall ;
308
+ declare const assert: DeployAssert ;
317
309
318
310
message .assert (ExpectedResult .objectLike ({
319
311
Messages: Match .arrayWith ([
0 commit comments