Skip to content

Commit 8d80e1c

Browse files
committed
fix tests
1 parent 52dd75e commit 8d80e1c

File tree

2 files changed

+21
-17
lines changed

2 files changed

+21
-17
lines changed

index.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const path = require('path');
22
const core = require('@actions/core');
33
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');
55
const yaml = require('yaml');
66
const fs = require('fs');
77
const crypto = require('crypto');
@@ -49,14 +49,18 @@ async function runTask(ecs, clusterName, taskDefArn, waitForMinutes) {
4949
containerOverrides: containerOverrides
5050
},
5151
launchType: launchType,
52-
networkConfiguration: awsvpcConfiguration === {} ? {} : { awsvpcConfiguration: awsvpcConfiguration }
52+
networkConfiguration: Object.keys(awsvpcConfiguration).length === 0 ? {} : { awsvpcConfiguration: awsvpcConfiguration }
5353
});
5454

5555
core.debug(`Run task response ${JSON.stringify(runTaskResponse)}`)
5656

5757
const taskArns = runTaskResponse.tasks.map(task => task.taskArn);
5858
core.setOutput('run-task-arn', taskArns);
59-
core.info(`Task running: https://console.aws.amazon.com/ecs/home?region=${aws.config.region}#/clusters/${clusterName}/tasks`);
59+
60+
const region = await ecs.config.region();
61+
const consoleHostname = region.startsWith('cn') ? 'console.amazonaws.cn' : 'console.aws.amazon.com';
62+
63+
core.info(`Task running: https://${consoleHostname}/ecs/home?region=${region}#/clusters/${clusterName}/tasks`);
6064

6165
if (runTaskResponse.failures && runTaskResponse.failures.length > 0) {
6266
const failure = runTaskResponse.failures[0];

index.test.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const run = require('.');
22
const core = require('@actions/core');
33
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');
55
const fs = require('fs');
66
const path = require('path');
77

@@ -16,6 +16,8 @@ const mockEcsUpdateService = jest.fn();
1616
const mockEcsDescribeServices = jest.fn();
1717
const mockCodeDeployCreateDeployment = jest.fn();
1818
const mockCodeDeployGetDeploymentGroup = jest.fn();
19+
const mockRunTask = jest.fn();
20+
const mockEcsDescribeTasks = jest.fn();
1921
const 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

Comments
 (0)