11const run = require ( '.' ) ;
22const core = require ( '@actions/core' ) ;
33const { CodeDeploy, waitUntilDeploymentSuccessful } = require ( '@aws-sdk/client-codedeploy' ) ;
4- const { ECS , waitUntilServicesStable } = require ( '@aws-sdk/client-ecs' ) ;
4+ const { ECS , waitUntilServicesStable, waitUntilTasksStopped } = require ( '@aws-sdk/client-ecs' ) ;
55const fs = require ( 'fs' ) ;
66const path = require ( 'path' ) ;
77
@@ -16,6 +16,8 @@ const mockEcsUpdateService = jest.fn();
1616const mockEcsDescribeServices = jest . fn ( ) ;
1717const mockCodeDeployCreateDeployment = jest . fn ( ) ;
1818const mockCodeDeployGetDeploymentGroup = jest . fn ( ) ;
19+ const mockRunTask = jest . fn ( ) ;
20+ const mockEcsDescribeTasks = jest . fn ( ) ;
1921const config = {
2022 region : ( ) => Promise . resolve ( 'fake-region' ) ,
2123} ;
@@ -33,7 +35,9 @@ describe('Deploy to ECS', () => {
3335 config,
3436 registerTaskDefinition : mockEcsRegisterTaskDef ,
3537 updateService : mockEcsUpdateService ,
36- describeServices : mockEcsDescribeServices
38+ describeServices : mockEcsDescribeServices ,
39+ describeTasks : mockEcsDescribeTasks ,
40+ runTask : mockRunTask ,
3741 } ;
3842
3943 const mockCodeDeployClient = {
@@ -109,7 +113,6 @@ describe('Deploy to ECS', () => {
109113 } )
110114 ) ;
111115
112-
113116 mockRunTask . mockImplementation (
114117 ( ) => Promise . resolve ( {
115118 failures : [ ] ,
@@ -153,6 +156,8 @@ describe('Deploy to ECS', () => {
153156
154157 ECS . mockImplementation ( ( ) => mockEcsClient ) ;
155158
159+ waitUntilTasksStopped . mockImplementation ( ( ) => Promise . resolve ( { } ) ) ;
160+
156161 waitUntilServicesStable . mockImplementation ( ( ) => Promise . resolve ( { } ) ) ;
157162
158163 CodeDeploy . mockImplementation ( ( ) => mockCodeDeployClient ) ;
@@ -779,9 +784,8 @@ describe('Deploy to ECS', () => {
779784 } ) ;
780785
781786 expect ( mockCodeDeployCreateDeployment ) . toHaveBeenNthCalledWith ( 1 , {
782- applicationName : 'Custom-Application' ,
783- deploymentGroupName : 'Custom-Deployment-Group' ,
784- description : 'Custom-DeploymentCustom-DeploymentCustom-DeploymentCustom-DeploymentCustom-DeploymentCustom-DeploymentCustom-DeploymentCustom-DeploymentCustom-DeploymentCustom-DeploymentCustom-DeploymentCustom-DeploymentCustom-DeploymentCustom-DeploymentCustom-DeploymentCustom-DeploymentCustom-DeploymentCustom-DeploymentCustom-DeploymentCustom-DeploymentCustom-DeploymentCustom-DeploymentCustom-DeploymentCustom-DeploymentCustom-DeploymentCustom-DeploymentCustom-DeploymentCustom-DeploymentCustom-DeploymentCustom-DeploymentC…' ,
787+ applicationName : 'MyApplication' ,
788+ deploymentGroupName : 'MyDeploymentGroup' ,
785789 revision : {
786790 revisionType : 'AppSpecContent' ,
787791 appSpecContent : {
@@ -1108,6 +1112,7 @@ describe('Deploy to ECS', () => {
11081112 . mockReturnValueOnce ( '' ) // wait-for-service-stability
11091113 . mockReturnValueOnce ( '' ) // wait-for-minutes
11101114 . mockReturnValueOnce ( '' ) // force-new-deployment
1115+ . mockReturnValueOnce ( '' ) // desired-count
11111116 . mockReturnValueOnce ( 'true' ) ; // run-task
11121117
11131118 await run ( ) ;
@@ -1128,6 +1133,7 @@ describe('Deploy to ECS', () => {
11281133 . mockReturnValueOnce ( '' ) // wait-for-service-stability
11291134 . mockReturnValueOnce ( '' ) // wait-for-minutes
11301135 . mockReturnValueOnce ( '' ) // force-new-deployment
1136+ . mockReturnValueOnce ( '' ) // desired-count
11311137 . mockReturnValueOnce ( 'true' ) // run-task
11321138 . mockReturnValueOnce ( 'false' ) // wait-for-task-stopped
11331139 . mockReturnValueOnce ( 'someJoe' ) // run-task-started-by
@@ -1161,6 +1167,7 @@ describe('Deploy to ECS', () => {
11611167 . mockReturnValueOnce ( '' ) // wait-for-service-stability
11621168 . mockReturnValueOnce ( '' ) // wait-for-minutes
11631169 . mockReturnValueOnce ( '' ) // force-new-deployment
1170+ . mockReturnValueOnce ( '' ) // desired-count
11641171 . mockReturnValueOnce ( 'true' ) // run-task
11651172 . mockReturnValueOnce ( 'true' ) ; // wait-for-task-stopped
11661173
@@ -1171,14 +1178,7 @@ describe('Deploy to ECS', () => {
11711178 expect ( core . setOutput ) . toHaveBeenNthCalledWith ( 1 , 'task-definition-arn' , 'task:def:arn' )
11721179 expect ( mockRunTask ) . toHaveBeenCalledTimes ( 1 ) ;
11731180 expect ( core . setOutput ) . toHaveBeenNthCalledWith ( 2 , 'run-task-arn' , [ "arn:aws:ecs:fake-region:account_id:task/arn" ] )
1174- expect ( mockEcsWaiter ) . toHaveBeenNthCalledWith ( 1 , 'tasksStopped' , {
1175- tasks : [ 'arn:aws:ecs:fake-region:account_id:task/arn' ] ,
1176- cluster : 'somecluster' ,
1177- "$waiter" : {
1178- "delay" : 15 ,
1179- "maxAttempts" : 120 ,
1180- } ,
1181- } ) ;
1181+ expect ( waitUntilTasksStopped ) . toHaveBeenCalledTimes ( 1 ) ;
11821182 } ) ;
11831183
11841184 test ( 'error caught if AppSpec file is not formatted correctly' , async ( ) => {
0 commit comments