1
1
const run = require ( '.' ) ;
2
2
const core = require ( '@actions/core' ) ;
3
3
const { 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' ) ;
5
5
const fs = require ( 'fs' ) ;
6
6
const path = require ( 'path' ) ;
7
7
@@ -16,6 +16,8 @@ const mockEcsUpdateService = jest.fn();
16
16
const mockEcsDescribeServices = jest . fn ( ) ;
17
17
const mockCodeDeployCreateDeployment = jest . fn ( ) ;
18
18
const mockCodeDeployGetDeploymentGroup = jest . fn ( ) ;
19
+ const mockRunTask = jest . fn ( ) ;
20
+ const mockEcsDescribeTasks = jest . fn ( ) ;
19
21
const config = {
20
22
region : ( ) => Promise . resolve ( 'fake-region' ) ,
21
23
} ;
@@ -33,7 +35,9 @@ describe('Deploy to ECS', () => {
33
35
config,
34
36
registerTaskDefinition : mockEcsRegisterTaskDef ,
35
37
updateService : mockEcsUpdateService ,
36
- describeServices : mockEcsDescribeServices
38
+ describeServices : mockEcsDescribeServices ,
39
+ describeTasks : mockEcsDescribeTasks ,
40
+ runTask : mockRunTask ,
37
41
} ;
38
42
39
43
const mockCodeDeployClient = {
@@ -109,7 +113,6 @@ describe('Deploy to ECS', () => {
109
113
} )
110
114
) ;
111
115
112
-
113
116
mockRunTask . mockImplementation (
114
117
( ) => Promise . resolve ( {
115
118
failures : [ ] ,
@@ -153,6 +156,8 @@ describe('Deploy to ECS', () => {
153
156
154
157
ECS . mockImplementation ( ( ) => mockEcsClient ) ;
155
158
159
+ waitUntilTasksStopped . mockImplementation ( ( ) => Promise . resolve ( { } ) ) ;
160
+
156
161
waitUntilServicesStable . mockImplementation ( ( ) => Promise . resolve ( { } ) ) ;
157
162
158
163
CodeDeploy . mockImplementation ( ( ) => mockCodeDeployClient ) ;
@@ -779,9 +784,8 @@ describe('Deploy to ECS', () => {
779
784
} ) ;
780
785
781
786
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' ,
785
789
revision : {
786
790
revisionType : 'AppSpecContent' ,
787
791
appSpecContent : {
@@ -1108,6 +1112,7 @@ describe('Deploy to ECS', () => {
1108
1112
. mockReturnValueOnce ( '' ) // wait-for-service-stability
1109
1113
. mockReturnValueOnce ( '' ) // wait-for-minutes
1110
1114
. mockReturnValueOnce ( '' ) // force-new-deployment
1115
+ . mockReturnValueOnce ( '' ) // desired-count
1111
1116
. mockReturnValueOnce ( 'true' ) ; // run-task
1112
1117
1113
1118
await run ( ) ;
@@ -1128,6 +1133,7 @@ describe('Deploy to ECS', () => {
1128
1133
. mockReturnValueOnce ( '' ) // wait-for-service-stability
1129
1134
. mockReturnValueOnce ( '' ) // wait-for-minutes
1130
1135
. mockReturnValueOnce ( '' ) // force-new-deployment
1136
+ . mockReturnValueOnce ( '' ) // desired-count
1131
1137
. mockReturnValueOnce ( 'true' ) // run-task
1132
1138
. mockReturnValueOnce ( 'false' ) // wait-for-task-stopped
1133
1139
. mockReturnValueOnce ( 'someJoe' ) // run-task-started-by
@@ -1161,6 +1167,7 @@ describe('Deploy to ECS', () => {
1161
1167
. mockReturnValueOnce ( '' ) // wait-for-service-stability
1162
1168
. mockReturnValueOnce ( '' ) // wait-for-minutes
1163
1169
. mockReturnValueOnce ( '' ) // force-new-deployment
1170
+ . mockReturnValueOnce ( '' ) // desired-count
1164
1171
. mockReturnValueOnce ( 'true' ) // run-task
1165
1172
. mockReturnValueOnce ( 'true' ) ; // wait-for-task-stopped
1166
1173
@@ -1171,14 +1178,7 @@ describe('Deploy to ECS', () => {
1171
1178
expect ( core . setOutput ) . toHaveBeenNthCalledWith ( 1 , 'task-definition-arn' , 'task:def:arn' )
1172
1179
expect ( mockRunTask ) . toHaveBeenCalledTimes ( 1 ) ;
1173
1180
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 ) ;
1182
1182
} ) ;
1183
1183
1184
1184
test ( 'error caught if AppSpec file is not formatted correctly' , async ( ) => {
0 commit comments