@@ -126,19 +126,6 @@ describe('tests', () => {
126
126
} ) ;
127
127
} ) ;
128
128
129
- test ( 'Throws error for unacceptable protocol' , ( ) => {
130
- const stack = new cdk . Stack ( ) ;
131
- const vpc = new ec2 . Vpc ( stack , 'Vpc' ) ;
132
-
133
- expect ( ( ) => {
134
- new elbv2 . NetworkTargetGroup ( stack , 'Group' , {
135
- vpc,
136
- port : 80 ,
137
- protocol : elbv2 . Protocol . HTTPS ,
138
- } ) ;
139
- } ) . toThrow ( ) ;
140
- } ) ;
141
-
142
129
test ( 'Throws error for invalid health check interval' , ( ) => {
143
130
const app = new cdk . App ( ) ;
144
131
const stack = new cdk . Stack ( app , 'Stack' ) ;
@@ -157,42 +144,243 @@ describe('tests', () => {
157
144
} ) . toThrow ( / H e a l t h c h e c k i n t e r v a l ' 5 ' n o t s u p p o r t e d . M u s t b e o n e o f t h e f o l l o w i n g v a l u e s ' 1 0 , 3 0 ' ./ ) ;
158
145
} ) ;
159
146
160
- test ( 'Throws error for invalid health check protocol' , ( ) => {
161
- const app = new cdk . App ( ) ;
162
- const stack = new cdk . Stack ( app , 'Stack' ) ;
163
- const vpc = new ec2 . Vpc ( stack , 'Vpc' ) ;
147
+ test . each ( [ elbv2 . Protocol . UDP , elbv2 . Protocol . TCP_UDP , elbv2 . Protocol . TLS ] ) (
148
+ 'Throws validation error, when `healthCheck` has `protocol` set to %s' ,
149
+ ( protocol ) => {
150
+ // GIVEN
151
+ const app = new cdk . App ( ) ;
152
+ const stack = new cdk . Stack ( app , 'Stack' ) ;
153
+ const vpc = new ec2 . Vpc ( stack , 'VPC' , { } ) ;
164
154
165
- new elbv2 . NetworkTargetGroup ( stack , 'Group' , {
166
- vpc,
167
- port : 80 ,
168
- healthCheck : {
169
- protocol : elbv2 . Protocol . UDP ,
170
- } ,
155
+ // WHEN
156
+ new elbv2 . NetworkTargetGroup ( stack , 'TargetGroup' , {
157
+ vpc,
158
+ port : 80 ,
159
+ healthCheck : {
160
+ protocol : protocol ,
161
+ } ,
162
+ } ) ;
163
+
164
+ // THEN
165
+ expect ( ( ) => {
166
+ app . synth ( ) ;
167
+ } ) . toThrow ( `Health check protocol '${ protocol } ' is not supported. Must be one of [HTTP, HTTPS, TCP]` ) ;
171
168
} ) ;
172
169
173
- expect ( ( ) => {
174
- app . synth ( ) ;
175
- } ) . toThrow ( / H e a l t h c h e c k p r o t o c o l ' U D P ' i s n o t s u p p o r t e d . M u s t b e o n e o f \[ H T T P , H T T P S , T C P \] / ) ;
176
- } ) ;
170
+ test . each ( [ elbv2 . Protocol . UDP , elbv2 . Protocol . TCP_UDP , elbv2 . Protocol . TLS ] ) (
171
+ 'Throws validation error, when `configureHealthCheck()` has `protocol` set to %s' ,
172
+ ( protocol ) => {
173
+ // GIVEN
174
+ const app = new cdk . App ( ) ;
175
+ const stack = new cdk . Stack ( app , 'Stack' ) ;
176
+ const vpc = new ec2 . Vpc ( stack , 'VPC' , { } ) ;
177
+ const tg = new elbv2 . NetworkTargetGroup ( stack , 'TargetGroup' , {
178
+ vpc,
179
+ port : 80 ,
180
+ } ) ;
177
181
178
- test ( 'Throws error for health check path property when protocol does not support it' , ( ) => {
179
- const app = new cdk . App ( ) ;
180
- const stack = new cdk . Stack ( app , 'Stack' ) ;
181
- const vpc = new ec2 . Vpc ( stack , 'Vpc' ) ;
182
+ // WHEN
183
+ tg . configureHealthCheck ( {
184
+ protocol : protocol ,
185
+ } ) ;
182
186
183
- new elbv2 . NetworkTargetGroup ( stack , 'Group' , {
184
- vpc,
185
- port : 80 ,
186
- healthCheck : {
187
+ // THEN
188
+ expect ( ( ) => {
189
+ app . synth ( ) ;
190
+ } ) . toThrow ( `Health check protocol '${ protocol } ' is not supported. Must be one of [HTTP, HTTPS, TCP]` ) ;
191
+ } ) ;
192
+
193
+ test . each ( [ elbv2 . Protocol . HTTP , elbv2 . Protocol . HTTPS , elbv2 . Protocol . TCP ] ) (
194
+ 'Does not throw validation error, when `healthCheck` has `protocol` set to %s' ,
195
+ ( protocol ) => {
196
+ // GIVEN
197
+ const app = new cdk . App ( ) ;
198
+ const stack = new cdk . Stack ( app , 'Stack' ) ;
199
+ const vpc = new ec2 . Vpc ( stack , 'VPC' , { } ) ;
200
+
201
+ // WHEN
202
+ new elbv2 . NetworkTargetGroup ( stack , 'TargetGroup' , {
203
+ vpc,
204
+ port : 80 ,
205
+ healthCheck : {
206
+ protocol : protocol ,
207
+ } ,
208
+ } ) ;
209
+
210
+ // THEN
211
+ expect ( ( ) => {
212
+ app . synth ( ) ;
213
+ } ) . not . toThrowError ( ) ;
214
+ } ) ;
215
+
216
+ test . each ( [ elbv2 . Protocol . HTTP , elbv2 . Protocol . HTTPS , elbv2 . Protocol . TCP ] ) (
217
+ 'Does not throw validation error, when `configureHealthCheck()` has `protocol` set to %s' ,
218
+ ( protocol ) => {
219
+ // GIVEN
220
+ const app = new cdk . App ( ) ;
221
+ const stack = new cdk . Stack ( app , 'Stack' ) ;
222
+ const vpc = new ec2 . Vpc ( stack , 'VPC' , { } ) ;
223
+ const tg = new elbv2 . NetworkTargetGroup ( stack , 'TargetGroup' , {
224
+ vpc,
225
+ port : 80 ,
226
+ } ) ;
227
+
228
+ // WHEN
229
+ tg . configureHealthCheck ( {
230
+ protocol : protocol ,
231
+ } ) ;
232
+
233
+ // THEN
234
+ expect ( ( ) => {
235
+ app . synth ( ) ;
236
+ } ) . not . toThrowError ( ) ;
237
+ } ) ;
238
+
239
+ test . each ( [ elbv2 . Protocol . TCP , elbv2 . Protocol . HTTPS ] ) (
240
+ 'Does not throw a validation error, when `healthCheck` has `protocol` set to %s and `interval` is equal to `timeout`' ,
241
+ ( protocol ) => {
242
+ // GIVEN
243
+ const app = new cdk . App ( ) ;
244
+ const stack = new cdk . Stack ( app , 'Stack' ) ;
245
+ const vpc = new ec2 . Vpc ( stack , 'VPC' , { } ) ;
246
+
247
+ // WHEN
248
+ new elbv2 . NetworkTargetGroup ( stack , 'TargetGroup' , {
249
+ vpc,
250
+ port : 80 ,
251
+ healthCheck : {
252
+ interval : cdk . Duration . seconds ( 10 ) ,
253
+ timeout : cdk . Duration . seconds ( 10 ) ,
254
+ protocol : protocol ,
255
+ } ,
256
+ } ) ;
257
+
258
+ // THEN
259
+ expect ( ( ) => {
260
+ app . synth ( ) ;
261
+ } ) . not . toThrowError ( ) ;
262
+ } ) ;
263
+
264
+ test . each ( [ elbv2 . Protocol . TCP , elbv2 . Protocol . HTTPS ] ) (
265
+ 'Does not throw a validation error, when `configureHealthCheck()` has `protocol` set to %s and `interval` is equal to `timeout`' ,
266
+ ( protocol ) => {
267
+ // GIVEN
268
+ const app = new cdk . App ( ) ;
269
+ const stack = new cdk . Stack ( app , 'Stack' ) ;
270
+ const vpc = new ec2 . Vpc ( stack , 'VPC' , { } ) ;
271
+ const tg = new elbv2 . NetworkTargetGroup ( stack , 'TargetGroup' , {
272
+ vpc,
273
+ port : 80 ,
274
+ } ) ;
275
+
276
+ // WHEN
277
+ tg . configureHealthCheck ( {
278
+ interval : cdk . Duration . seconds ( 10 ) ,
279
+ timeout : cdk . Duration . seconds ( 10 ) ,
280
+ protocol : protocol ,
281
+ } ) ;
282
+
283
+ // THEN
284
+ expect ( ( ) => {
285
+ app . synth ( ) ;
286
+ } ) . not . toThrowError ( ) ;
287
+ } ) ;
288
+
289
+ test . each ( [ elbv2 . Protocol . UDP , elbv2 . Protocol . TCP_UDP , elbv2 . Protocol . TLS ] ) (
290
+ 'Throws validation error,`healthCheck` has `protocol` set to %s and `path` is provided' ,
291
+ ( protocol ) => {
292
+ // GIVEN
293
+ const app = new cdk . App ( ) ;
294
+ const stack = new cdk . Stack ( app , 'Stack' ) ;
295
+ const vpc = new ec2 . Vpc ( stack , 'VPC' , { } ) ;
296
+
297
+ // WHEN
298
+ new elbv2 . NetworkTargetGroup ( stack , 'TargetGroup' , {
299
+ vpc,
300
+ port : 80 ,
301
+ healthCheck : {
302
+ path : '/my-path' ,
303
+ protocol : protocol ,
304
+ } ,
305
+ } ) ;
306
+
307
+ // THEN
308
+ expect ( ( ) => {
309
+ app . synth ( ) ;
310
+ } ) . toThrow ( `'${ protocol } ' health checks do not support the path property. Must be one of [HTTP, HTTPS]` ) ;
311
+ } ) ;
312
+
313
+ test . each ( [ elbv2 . Protocol . UDP , elbv2 . Protocol . TCP_UDP , elbv2 . Protocol . TLS ] ) (
314
+ 'Throws validation error, when `configureHealthCheck()` has `protocol` set to %s and `path` is provided' ,
315
+ ( protocol ) => {
316
+ // GIVEN
317
+ const app = new cdk . App ( ) ;
318
+ const stack = new cdk . Stack ( app , 'Stack' ) ;
319
+ const vpc = new ec2 . Vpc ( stack , 'VPC' , { } ) ;
320
+ const tg = new elbv2 . NetworkTargetGroup ( stack , 'TargetGroup' , {
321
+ vpc,
322
+ port : 80 ,
323
+ } ) ;
324
+
325
+ // WHEN
326
+ tg . configureHealthCheck ( {
187
327
path : '/my-path' ,
188
- protocol : elbv2 . Protocol . TCP ,
189
- } ,
328
+ protocol : protocol ,
329
+ } ) ;
330
+
331
+ // THEN
332
+ expect ( ( ) => {
333
+ app . synth ( ) ;
334
+ } ) . toThrow ( `'${ protocol } ' health checks do not support the path property. Must be one of [HTTP, HTTPS]` ) ;
190
335
} ) ;
191
336
192
- expect ( ( ) => {
193
- app . synth ( ) ;
194
- } ) . toThrow ( / ' T C P ' h e a l t h c h e c k s d o n o t s u p p o r t t h e p a t h p r o p e r t y . M u s t b e o n e o f \[ H T T P , H T T P S \] / ) ;
195
- } ) ;
337
+ test . each ( [ elbv2 . Protocol . HTTP , elbv2 . Protocol . HTTPS ] ) (
338
+ 'Does not throw validation error, when `healthCheck` has `protocol` set to %s and `path` is provided' ,
339
+ ( protocol ) => {
340
+ // GIVEN
341
+ const app = new cdk . App ( ) ;
342
+ const stack = new cdk . Stack ( app , 'Stack' ) ;
343
+ const vpc = new ec2 . Vpc ( stack , 'VPC' , { } ) ;
344
+
345
+ // WHEN
346
+ new elbv2 . NetworkTargetGroup ( stack , 'TargetGroup' , {
347
+ vpc,
348
+ port : 80 ,
349
+ healthCheck : {
350
+ path : '/my-path' ,
351
+ protocol : protocol ,
352
+ } ,
353
+ } ) ;
354
+
355
+ // THEN
356
+ expect ( ( ) => {
357
+ app . synth ( ) ;
358
+ } ) . not . toThrowError ( ) ;
359
+ } ) ;
360
+
361
+ test . each ( [ elbv2 . Protocol . HTTP , elbv2 . Protocol . HTTPS ] ) (
362
+ 'Does not throw validation error, when `configureHealthCheck()` has `protocol` set to %s and `path` is provided' ,
363
+ ( protocol ) => {
364
+ // GIVEN
365
+ const app = new cdk . App ( ) ;
366
+ const stack = new cdk . Stack ( app , 'Stack' ) ;
367
+ const vpc = new ec2 . Vpc ( stack , 'VPC' , { } ) ;
368
+ const tg = new elbv2 . NetworkTargetGroup ( stack , 'TargetGroup' , {
369
+ vpc,
370
+ port : 80 ,
371
+ } ) ;
372
+
373
+ // WHEN
374
+ tg . configureHealthCheck ( {
375
+ path : '/my-path' ,
376
+ protocol : protocol ,
377
+ } ) ;
378
+
379
+ // THEN
380
+ expect ( ( ) => {
381
+ app . synth ( ) ;
382
+ } ) . not . toThrowError ( ) ;
383
+ } ) ;
196
384
197
385
test ( 'Throws error for invalid health check healthy threshold' , ( ) => {
198
386
const app = new cdk . App ( ) ;
0 commit comments