@@ -5,7 +5,6 @@ import * as lambda from '../../aws-lambda';
55import * as cdk from '../../core' ;
66import { App , Stack } from '../../core' ;
77import * as ecs from '../lib' ;
8- import { stringifyHookDetails } from '../lib/deployment-lifecycle-hook-target' ;
98
109describe ( 'DeploymentLifecycleHookTarget' , ( ) => {
1110 let stack : cdk . Stack ;
@@ -337,124 +336,5 @@ describe('DeploymentLifecycleHookTarget', () => {
337336 Template . fromStack ( stack ) ;
338337 } ) . toThrow ( / h o o k D e t a i l s m u s t b e a J S O N o b j e c t , g o t : a r r a y / ) ;
339338 } ) ;
340-
341- test ( 'throws error for primitive string hookDetails' , ( ) => {
342- const hookTarget = new ecs . DeploymentLifecycleLambdaTarget ( lambdaFunction , 'PreScaleUpHook' , {
343- lifecycleStages : [ ecs . DeploymentLifecycleStage . PRE_SCALE_UP ] ,
344- hookDetails : 'just a string' ,
345- } ) ;
346-
347- const service = new ecs . FargateService ( stack , 'FargateService' , {
348- cluster,
349- taskDefinition,
350- } ) ;
351-
352- service . addLifecycleHook ( hookTarget ) ;
353-
354- // GIVEN & WHEN & THEN
355- expect ( ( ) => {
356- Template . fromStack ( stack ) ;
357- } ) . toThrow ( / h o o k D e t a i l s m u s t b e a J S O N o b j e c t , g o t : s t r i n g / ) ;
358- } ) ;
359-
360- test ( 'throws error for primitive number hookDetails' , ( ) => {
361- const hookTarget = new ecs . DeploymentLifecycleLambdaTarget ( lambdaFunction , 'PreScaleUpHook' , {
362- lifecycleStages : [ ecs . DeploymentLifecycleStage . PRE_SCALE_UP ] ,
363- hookDetails : 42 ,
364- } ) ;
365-
366- const service = new ecs . FargateService ( stack , 'FargateService' , {
367- cluster,
368- taskDefinition,
369- } ) ;
370-
371- service . addLifecycleHook ( hookTarget ) ;
372-
373- // GIVEN & WHEN & THEN
374- expect ( ( ) => {
375- Template . fromStack ( stack ) ;
376- } ) . toThrow ( / h o o k D e t a i l s m u s t b e a J S O N o b j e c t , g o t : n u m b e r / ) ;
377- } ) ;
378-
379- test ( 'throws error for null hookDetails' , ( ) => {
380- const hookTarget = new ecs . DeploymentLifecycleLambdaTarget ( lambdaFunction , 'PreScaleUpHook' , {
381- lifecycleStages : [ ecs . DeploymentLifecycleStage . PRE_SCALE_UP ] ,
382- hookDetails : null ,
383- } ) ;
384-
385- const service = new ecs . FargateService ( stack , 'FargateService' , {
386- cluster,
387- taskDefinition,
388- } ) ;
389-
390- service . addLifecycleHook ( hookTarget ) ;
391-
392- // GIVEN & WHEN & THEN
393- Template . fromStack ( stack ) . hasResourceProperties ( 'AWS::ECS::Service' , {
394- DeploymentConfiguration : {
395- LifecycleHooks : [
396- {
397- LifecycleStages : [ 'PRE_SCALE_UP' ] ,
398- HookTargetArn : {
399- 'Fn::GetAtt' : [
400- Match . stringLikeRegexp ( 'TestFunction' ) ,
401- 'Arn' ,
402- ] ,
403- } ,
404- } ,
405- ] ,
406- } ,
407- } ) ;
408- } ) ;
409-
410- test ( 'throws error for undefined hookDetails' , ( ) => {
411- const hookTarget = new ecs . DeploymentLifecycleLambdaTarget ( lambdaFunction , 'PreScaleUpHook' , {
412- lifecycleStages : [ ecs . DeploymentLifecycleStage . PRE_SCALE_UP ] ,
413- } ) ;
414-
415- const service = new ecs . FargateService ( stack , 'FargateService' , {
416- cluster,
417- taskDefinition,
418- } ) ;
419-
420- service . addLifecycleHook ( hookTarget ) ;
421-
422- // GIVEN & WHEN & THEN
423- Template . fromStack ( stack ) . hasResourceProperties ( 'AWS::ECS::Service' , {
424- DeploymentConfiguration : {
425- LifecycleHooks : [
426- {
427- LifecycleStages : [ 'PRE_SCALE_UP' ] ,
428- HookTargetArn : {
429- 'Fn::GetAtt' : [
430- Match . stringLikeRegexp ( 'TestFunction' ) ,
431- 'Arn' ,
432- ] ,
433- } ,
434- } ,
435- ] ,
436- } ,
437- } ) ;
438- } ) ;
439- } ) ;
440-
441- describe ( 'stringifyHookDetails function' , ( ) => {
442- test ( 'validates and stringifies object directly' , ( ) => {
443- const objectInput = { environment : 'production' , timeout : 300 } ;
444- expect ( ( ) => stringifyHookDetails ( stack , objectInput ) ) . not . toThrow ( ) ;
445- expect ( stringifyHookDetails ( stack , objectInput ) ) . toBe ( '{"environment":"production","timeout":300}' ) ;
446- } ) ;
447-
448- test ( 'rejects primitive string value' , ( ) => {
449- expect ( ( ) => stringifyHookDetails ( stack , 'just a string' ) ) . toThrow ( / h o o k D e t a i l s m u s t b e a J S O N o b j e c t , g o t : s t r i n g / ) ;
450- } ) ;
451-
452- test ( 'rejects primitive number value' , ( ) => {
453- expect ( ( ) => stringifyHookDetails ( stack , 42 ) ) . toThrow ( / h o o k D e t a i l s m u s t b e a J S O N o b j e c t , g o t : n u m b e r / ) ;
454- } ) ;
455-
456- test ( 'rejects primitive boolean value' , ( ) => {
457- expect ( ( ) => stringifyHookDetails ( stack , true ) ) . toThrow ( / h o o k D e t a i l s m u s t b e a J S O N o b j e c t , g o t : b o o l e a n / ) ;
458- } ) ;
459339 } ) ;
460340} ) ;
0 commit comments