1
1
import '@aws-cdk/assert-internal/jest' ;
2
- import { objectLike } from '@aws-cdk/assert-internal' ;
2
+ import { ABSENT , objectLike } from '@aws-cdk/assert-internal' ;
3
3
import * as iam from '@aws-cdk/aws-iam' ;
4
4
import * as s3 from '@aws-cdk/aws-s3' ;
5
- import { App , Duration , Lazy , Stack } from '@aws-cdk/core' ;
5
+ import { Duration , Lazy , Stack } from '@aws-cdk/core' ;
6
6
import * as synthetics from '../lib' ;
7
7
8
8
test ( 'Basic canary properties work' , ( ) => {
9
9
// GIVEN
10
- const stack = new Stack ( new App ( ) , 'canaries' ) ;
10
+ const stack = new Stack ( ) ;
11
11
12
12
// WHEN
13
13
new synthetics . Canary ( stack , 'Canary' , {
@@ -36,7 +36,7 @@ test('Basic canary properties work', () => {
36
36
37
37
test ( 'Canary can have generated name' , ( ) => {
38
38
// GIVEN
39
- const stack = new Stack ( new App ( ) , 'canaries' ) ;
39
+ const stack = new Stack ( ) ;
40
40
41
41
// WHEN
42
42
new synthetics . Canary ( stack , 'Canary' , {
@@ -49,13 +49,13 @@ test('Canary can have generated name', () => {
49
49
50
50
// THEN
51
51
expect ( stack ) . toHaveResourceLike ( 'AWS::Synthetics::Canary' , {
52
- Name : 'canariescanary8dfb794 ' ,
52
+ Name : 'canary ' ,
53
53
} ) ;
54
54
} ) ;
55
55
56
56
test ( 'Name validation does not fail when using Tokens' , ( ) => {
57
57
// GIVEN
58
- const stack = new Stack ( new App ( ) , 'canaries' ) ;
58
+ const stack = new Stack ( ) ;
59
59
60
60
// WHEN
61
61
new synthetics . Canary ( stack , 'Canary' , {
@@ -73,7 +73,7 @@ test('Name validation does not fail when using Tokens', () => {
73
73
74
74
test ( 'Throws when name is specified incorrectly' , ( ) => {
75
75
// GIVEN
76
- const stack = new Stack ( new App ( ) , 'canaries' ) ;
76
+ const stack = new Stack ( ) ;
77
77
78
78
// THEN
79
79
expect ( ( ) => new synthetics . Canary ( stack , 'Canary' , {
@@ -89,7 +89,7 @@ test('Throws when name is specified incorrectly', () => {
89
89
90
90
test ( 'Throws when name has more than 21 characters' , ( ) => {
91
91
// GIVEN
92
- const stack = new Stack ( new App ( ) , 'canaries' ) ;
92
+ const stack = new Stack ( ) ;
93
93
94
94
// THEN
95
95
expect ( ( ) => new synthetics . Canary ( stack , 'Canary' , {
@@ -105,7 +105,7 @@ test('Throws when name has more than 21 characters', () => {
105
105
106
106
test ( 'An existing role can be specified instead of auto-created' , ( ) => {
107
107
// GIVEN
108
- const stack = new Stack ( new App ( ) , 'canaries' ) ;
108
+ const stack = new Stack ( ) ;
109
109
110
110
const role = new iam . Role ( stack , 'role' , {
111
111
assumedBy : new iam . ServicePrincipal ( 'lambda.amazonaws.com' ) ,
@@ -131,7 +131,7 @@ test('An existing role can be specified instead of auto-created', () => {
131
131
132
132
test ( 'An existing bucket and prefix can be specified instead of auto-created' , ( ) => {
133
133
// GIVEN
134
- const stack = new Stack ( new App ( ) , 'canaries' ) ;
134
+ const stack = new Stack ( ) ;
135
135
const bucket = new s3 . Bucket ( stack , 'mytestbucket' ) ;
136
136
const prefix = 'canary' ;
137
137
@@ -153,7 +153,7 @@ test('An existing bucket and prefix can be specified instead of auto-created', (
153
153
154
154
test ( 'Runtime can be specified' , ( ) => {
155
155
// GIVEN
156
- const stack = new Stack ( new App ( ) , 'canaries' ) ;
156
+ const stack = new Stack ( ) ;
157
157
158
158
// WHEN
159
159
new synthetics . Canary ( stack , 'Canary' , {
@@ -170,9 +170,54 @@ test('Runtime can be specified', () => {
170
170
} ) ;
171
171
} ) ;
172
172
173
+ test ( 'environment variables can be specified' , ( ) => {
174
+ // GIVEN
175
+ const stack = new Stack ( ) ;
176
+ const environmentVariables = {
177
+ TEST_KEY_1 : 'TEST_VALUE_1' ,
178
+ TEST_KEY_2 : 'TEST_VALUE_2' ,
179
+ } ;
180
+
181
+ // WHEN
182
+ new synthetics . Canary ( stack , 'Canary' , {
183
+ runtime : synthetics . Runtime . SYNTHETICS_1_0 ,
184
+ test : synthetics . Test . custom ( {
185
+ handler : 'index.handler' ,
186
+ code : synthetics . Code . fromInline ( '/* Synthetics handler code */' ) ,
187
+ } ) ,
188
+ environmentVariables : environmentVariables ,
189
+ } ) ;
190
+
191
+ // THEN
192
+ expect ( stack ) . toHaveResourceLike ( 'AWS::Synthetics::Canary' , {
193
+ RunConfig : {
194
+ EnvironmentVariables : environmentVariables ,
195
+ } ,
196
+ } ) ;
197
+ } ) ;
198
+
199
+ test ( 'environment variables are skipped if not provided' , ( ) => {
200
+ // GIVEN
201
+ const stack = new Stack ( ) ;
202
+
203
+ // WHEN
204
+ new synthetics . Canary ( stack , 'Canary' , {
205
+ runtime : synthetics . Runtime . SYNTHETICS_1_0 ,
206
+ test : synthetics . Test . custom ( {
207
+ handler : 'index.handler' ,
208
+ code : synthetics . Code . fromInline ( '/* Synthetics handler code */' ) ,
209
+ } ) ,
210
+ } ) ;
211
+
212
+ // THEN
213
+ expect ( stack ) . toHaveResourceLike ( 'AWS::Synthetics::Canary' , {
214
+ RunConfig : ABSENT ,
215
+ } ) ;
216
+ } ) ;
217
+
173
218
test ( 'Runtime can be customized' , ( ) => {
174
219
// GIVEN
175
- const stack = new Stack ( new App ( ) , 'canaries' ) ;
220
+ const stack = new Stack ( ) ;
176
221
177
222
// WHEN
178
223
new synthetics . Canary ( stack , 'Canary' , {
@@ -191,7 +236,7 @@ test('Runtime can be customized', () => {
191
236
192
237
test ( 'Schedule can be set with Rate' , ( ) => {
193
238
// GIVEN
194
- const stack = new Stack ( new App ( ) , 'canaries' ) ;
239
+ const stack = new Stack ( ) ;
195
240
196
241
// WHEN
197
242
new synthetics . Canary ( stack , 'Canary' , {
@@ -211,7 +256,7 @@ test('Schedule can be set with Rate', () => {
211
256
212
257
test ( 'Schedule can be set to 1 minute' , ( ) => {
213
258
// GIVEN
214
- const stack = new Stack ( new App ( ) , 'canaries' ) ;
259
+ const stack = new Stack ( ) ;
215
260
216
261
// WHEN
217
262
new synthetics . Canary ( stack , 'Canary' , {
@@ -231,7 +276,7 @@ test('Schedule can be set to 1 minute', () => {
231
276
232
277
test ( 'Schedule can be set with Expression' , ( ) => {
233
278
// GIVEN
234
- const stack = new Stack ( new App ( ) , 'canaries' ) ;
279
+ const stack = new Stack ( ) ;
235
280
236
281
// WHEN
237
282
new synthetics . Canary ( stack , 'Canary' , {
@@ -251,7 +296,7 @@ test('Schedule can be set with Expression', () => {
251
296
252
297
test ( 'Schedule can be set to run once' , ( ) => {
253
298
// GIVEN
254
- const stack = new Stack ( new App ( ) , 'canaries' ) ;
299
+ const stack = new Stack ( ) ;
255
300
256
301
// WHEN
257
302
new synthetics . Canary ( stack , 'Canary' , {
@@ -271,7 +316,7 @@ test('Schedule can be set to run once', () => {
271
316
272
317
test ( 'Throws when rate above 60 minutes' , ( ) => {
273
318
// GIVEN
274
- const stack = new Stack ( new App ( ) , 'canaries' ) ;
319
+ const stack = new Stack ( ) ;
275
320
276
321
// THEN
277
322
expect ( ( ) => new synthetics . Canary ( stack , 'Canary' , {
@@ -287,7 +332,7 @@ test('Throws when rate above 60 minutes', () => {
287
332
288
333
test ( 'Throws when rate above is not a whole number of minutes' , ( ) => {
289
334
// GIVEN
290
- const stack = new Stack ( new App ( ) , 'canaries' ) ;
335
+ const stack = new Stack ( ) ;
291
336
292
337
// THEN
293
338
expect ( ( ) => new synthetics . Canary ( stack , 'Canary' , {
@@ -303,7 +348,7 @@ test('Throws when rate above is not a whole number of minutes', () => {
303
348
304
349
test ( 'Can share artifacts bucket between canaries' , ( ) => {
305
350
// GIVEN
306
- const stack = new Stack ( new App ( ) , 'canaries' ) ;
351
+ const stack = new Stack ( ) ;
307
352
308
353
// WHEN
309
354
const canary1 = new synthetics . Canary ( stack , 'Canary1' , {
@@ -331,7 +376,7 @@ test('Can share artifacts bucket between canaries', () => {
331
376
332
377
test ( 'can specify custom test' , ( ) => {
333
378
// GIVEN
334
- const stack = new Stack ( new App ( ) , 'canaries' ) ;
379
+ const stack = new Stack ( ) ;
335
380
336
381
// WHEN
337
382
new synthetics . Canary ( stack , 'Canary' , {
@@ -355,4 +400,4 @@ test('can specify custom test', () => {
355
400
};` ,
356
401
} ,
357
402
} ) ;
358
- } ) ;
403
+ } ) ;
0 commit comments