Skip to content

Commit 49322b3

Browse files
committed
Added tests to check when a task fails whne it tries to stop and when a service proceeds that failed task
1 parent 3859ae5 commit 49322b3

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

index.test.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const mockEcsDescribeServices = jest.fn();
1717
const mockCodeDeployCreateDeployment = jest.fn();
1818
const mockCodeDeployGetDeploymentGroup = jest.fn();
1919
const mockRunTask = jest.fn();
20+
const mockWaitUntilTasksStopped = jest.fn().mockRejectedValue(new Error('failed'));
2021
const mockEcsDescribeTasks = jest.fn();
2122
const config = {
2223
region: () => Promise.resolve('fake-region'),
@@ -38,6 +39,7 @@ describe('Deploy to ECS', () => {
3839
describeServices: mockEcsDescribeServices,
3940
describeTasks: mockEcsDescribeTasks,
4041
runTask: mockRunTask,
42+
waitUntilTasksStopped: mockWaitUntilTasksStopped,
4143
};
4244

4345
const mockCodeDeployClient = {
@@ -1255,6 +1257,42 @@ describe('Deploy to ECS', () => {
12551257
expect(waitUntilTasksStopped).toHaveBeenCalledTimes(1);
12561258
});
12571259

1260+
1261+
test('error is caught if run task fails with (wait-for-task-stopped: true)', async () => {
1262+
mockEcsDescribeTasks.mockImplementation(
1263+
() => Promise.resolve({
1264+
failures: [{
1265+
reason: 'TASK_FAILED',
1266+
arn: "arn:aws:ecs:us-east-1:111122223333:task-definition/TaskFamilyName:* is TASK_FAILED"
1267+
}],
1268+
tasks: [],
1269+
executionStoppedAt: 1
1270+
1271+
})
1272+
);
1273+
1274+
await run();
1275+
expect(core.setFailed).toHaveBeenCalledTimes(0);
1276+
expect(mockEcsDescribeTasks).toHaveBeenCalledTimes(0);
1277+
1278+
});
1279+
1280+
test('error is caught if run task fails with (wait-for-task-stopped: true) and with service', async () => {
1281+
mockEcsDescribeTasks.mockImplementation(
1282+
() => Promise.resolve({
1283+
failures: [{
1284+
reason: 'SERVICE_FAILED',
1285+
arn: "arn:aws:ecs:us-east-1:111122223333:service/ServiceName"
1286+
}],
1287+
services: [],
1288+
})
1289+
);
1290+
1291+
await run();
1292+
expect(core.setFailed).toHaveBeenCalledTimes(0);
1293+
expect(mockEcsDescribeTasks).toHaveBeenCalledTimes(0);
1294+
});
1295+
12581296
test('error caught if AppSpec file is not formatted correctly', async () => {
12591297
mockEcsDescribeServices.mockImplementation(
12601298
() => Promise.resolve({

0 commit comments

Comments
 (0)