Skip to content

Commit 63dc038

Browse files
committed
Fix linting issues
1 parent c1cd3c3 commit 63dc038

11 files changed

Lines changed: 80 additions & 77 deletions

File tree

packages/cdk-blue-green-container-deployment/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@
8989
"@aws-cdk/assert": "^1.133.0",
9090
"aws-sdk": "^2.1033.0",
9191
"custom-resource-helper": "^1.0.15",
92-
"jest-cdk-snapshot": "^1.4.2"
92+
"jest-cdk-snapshot": "^1.4.2",
93+
"winston": "^3.3.3"
9394
},
9495
"externals": [
9596
"aws-sdk"
Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
import * as cdk from '@aws-cdk/core';
1+
import { expect as expectCDK, haveResource } from '@aws-cdk/assert';
22
import * as ecs from '@aws-cdk/aws-ecs';
33
import * as elb from '@aws-cdk/aws-elasticloadbalancingv2';
4+
import * as cdk from '@aws-cdk/core';
45

5-
import { expect as expectCDK, haveResource } from '@aws-cdk/assert';
6-
7-
import { EcsService, PropagateTags } from '../ecs-service';
86
import { DummyTaskDefinition } from '../dummy-task-definition';
7+
import { EcsService, PropagateTags } from '../ecs-service';
98

109
describe('EcsService', () => {
1110
const app = new cdk.App();
@@ -25,11 +24,13 @@ describe('EcsService', () => {
2524
taskDefinition,
2625
});
2726

28-
it('Creates a BlueGreenService custom resource', () => {
29-
expectCDK(stack).to(haveResource('Custom::BlueGreenService', {
30-
ServiceName: 'My Service',
31-
LaunchType: 'FARGATE'
32-
}));
27+
test('Creates a BlueGreenService custom resource', () => {
28+
expectCDK(stack).to(
29+
haveResource('Custom::BlueGreenService', {
30+
ServiceName: 'My Service',
31+
LaunchType: 'FARGATE',
32+
}),
33+
);
3334
});
3435
});
3536

@@ -46,15 +47,17 @@ describe('EcsService', () => {
4647
prodTargetGroup,
4748
testTargetGroup,
4849
taskDefinition,
49-
propagateTags: PropagateTags.SERVICE
50+
propagateTags: PropagateTags.SERVICE,
5051
});
5152

52-
it('enables tag propagation', () => {
53-
expectCDK(stack).to(haveResource('Custom::BlueGreenService', {
54-
ServiceName: 'My Service',
55-
LaunchType: 'FARGATE',
56-
PropagateTags: 'SERVICE'
57-
}));
53+
test('enables tag propagation', () => {
54+
expectCDK(stack).to(
55+
haveResource('Custom::BlueGreenService', {
56+
ServiceName: 'My Service',
57+
LaunchType: 'FARGATE',
58+
PropagateTags: 'SERVICE',
59+
}),
60+
);
5861
});
5962
});
6063

@@ -65,7 +68,7 @@ describe('EcsService', () => {
6568
const testTargetGroup = new elb.ApplicationTargetGroup(stack, 'TestTargetGroup', { vpc: cluster.vpc });
6669
const taskDefinition = new DummyTaskDefinition(stack, 'DummyTaskDefinition', { image: 'nginx' });
6770

68-
cdk.Tags.of(stack).add('Foo', 'Bar');
71+
cdk.Tags.of(stack).add('Foo', 'Bar');
6972

7073
new EcsService(stack, 'Service', {
7174
cluster,
@@ -75,15 +78,17 @@ describe('EcsService', () => {
7578
taskDefinition,
7679
});
7780

78-
it('adds Tags to the BlueGreenService', () => {
79-
expectCDK(stack).to(haveResource('Custom::BlueGreenService', {
80-
Tags: [
81-
{
82-
Key: 'Foo',
83-
Value: 'Bar'
84-
}
85-
]
86-
}));
81+
test('adds Tags to the BlueGreenService', () => {
82+
expectCDK(stack).to(
83+
haveResource('Custom::BlueGreenService', {
84+
Tags: [
85+
{
86+
Key: 'Foo',
87+
Value: 'Bar',
88+
},
89+
],
90+
}),
91+
);
8792
});
88-
})
93+
});
8994
});

packages/cdk-blue-green-container-deployment/src/__tests__/lambdas/__fixtures__/defaultContext.ts renamed to packages/cdk-blue-green-container-deployment/src/__tests__/lambdas/__fixtures__/default-context.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,14 @@ export const defaultContext = {
77
awsRequestId: 'foo',
88
logGroupName: 'foo',
99
logStreamName: 'foo',
10-
getRemainingTimeInMillis: () => 5000,
11-
done: () => {},
12-
fail: () => {},
13-
succeed: () => {},
10+
getRemainingTimeInMillis: (): number => 5000,
11+
done: (): void => {
12+
return;
13+
},
14+
fail: (): void => {
15+
return;
16+
},
17+
succeed: (): void => {
18+
return;
19+
},
1420
};

packages/cdk-blue-green-container-deployment/src/__tests__/lambdas/__fixtures__/defaultEcsServiceResourceProperties.ts renamed to packages/cdk-blue-green-container-deployment/src/__tests__/lambdas/__fixtures__/default-ecs-service-resource-properties.ts

File renamed without changes.

packages/cdk-blue-green-container-deployment/src/__tests__/lambdas/__fixtures__/defaultEvent.ts renamed to packages/cdk-blue-green-container-deployment/src/__tests__/lambdas/__fixtures__/default-event.ts

File renamed without changes.

packages/cdk-blue-green-container-deployment/src/__tests__/lambdas/__fixtures__/defaultLogger.ts renamed to packages/cdk-blue-green-container-deployment/src/__tests__/lambdas/__fixtures__/default-logger.ts

File renamed without changes.

packages/cdk-blue-green-container-deployment/src/__tests__/lambdas/ecs-deployment-group/index.test.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ jest.mock('aws-sdk', () => {
3535
});
3636

3737
import { handleCreate, handleUpdate } from '../../../lambdas/ecs-deployment-group';
38-
import { defaultContext } from '../__fixtures__/defaultContext';
39-
import { defaultEvent } from '../__fixtures__/defaultEvent';
40-
import { defaultLogger } from '../__fixtures__/defaultLogger';
38+
import { defaultContext } from '../__fixtures__/default-context';
39+
import { defaultEvent } from '../__fixtures__/default-event';
40+
import { defaultLogger } from '../__fixtures__/default-logger';
4141

4242
const defaultEcsDeploymentGroupProperties = {
4343
ApplicationName: 'TestApplicationName',
@@ -52,11 +52,11 @@ const defaultEcsDeploymentGroupProperties = {
5252
TargetGroupNames: ['Foo'],
5353
ProdTrafficListenerArn: 'arn:aws:elasticloadbalancing::012345678910:listener/app/MyApp/foo/prod',
5454
TestTrafficListenerArn: 'arn:aws:elasticloadbalancing::012345678910:listener/app/MyApp/foo/test',
55-
TerminationWaitTimeInMinutes: 5
55+
TerminationWaitTimeInMinutes: 5,
5656
};
5757

5858
describe('createHandler', () => {
59-
it('sends tags with create request', async () => {
59+
test('sends tags with create request', async () => {
6060
await handleCreate(
6161
{
6262
...defaultEvent,
@@ -84,7 +84,7 @@ describe('createHandler', () => {
8484
);
8585
});
8686

87-
it('returns the physical id and arn of the deployment group', async () => {
87+
test('returns the physical id and arn of the deployment group', async () => {
8888
const response = await handleCreate(
8989
{
9090
...defaultEvent,
@@ -100,7 +100,7 @@ describe('createHandler', () => {
100100
},
101101
{
102102
...defaultContext,
103-
invokedFunctionArn: 'arn:aws:lambda:eu-west-1:012345678910:function:MyCustomResourceHandler'
103+
invokedFunctionArn: 'arn:aws:lambda:eu-west-1:012345678910:function:MyCustomResourceHandler',
104104
},
105105
defaultLogger,
106106
);
@@ -109,15 +109,15 @@ describe('createHandler', () => {
109109
expect.objectContaining({
110110
physicalResourceId: 'TestDeploymentGroupName',
111111
responseData: {
112-
Arn: 'arn:aws:codedeploy:eu-west-1:012345678910:deploymentgroup:TestApplicationName/TestDeploymentGroupName'
112+
Arn: 'arn:aws:codedeploy:eu-west-1:012345678910:deploymentgroup:TestApplicationName/TestDeploymentGroupName',
113113
},
114114
}),
115115
);
116-
})
116+
});
117117
});
118118

119119
describe('updateHandler', () => {
120-
it('sends data update requests', async () => {
120+
test('sends data update requests', async () => {
121121
await handleUpdate(
122122
{
123123
...defaultEvent,
@@ -165,7 +165,7 @@ describe('updateHandler', () => {
165165
);
166166
});
167167

168-
it('returns the physical id and arn of the deployment group', async () => {
168+
test('returns the physical id and arn of the deployment group', async () => {
169169
const response = await handleUpdate(
170170
{
171171
...defaultEvent,
@@ -190,9 +190,9 @@ describe('updateHandler', () => {
190190
expect.objectContaining({
191191
physicalResourceId: 'TestDeploymentGroupName',
192192
responseData: {
193-
Arn: 'arn:aws:codedeploy:us-east-1:012345678910:deploymentgroup:TestApplicationName/TestDeploymentGroupName'
193+
Arn: 'arn:aws:codedeploy:us-east-1:012345678910:deploymentgroup:TestApplicationName/TestDeploymentGroupName',
194194
},
195195
}),
196196
);
197-
})
197+
});
198198
});

packages/cdk-blue-green-container-deployment/src/__tests__/lambdas/ecs-service/index.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ jest.mock('aws-sdk', () => {
3535
});
3636

3737
import { handleCreate, handleUpdate } from '../../../lambdas/ecs-service';
38-
import { defaultContext } from '../__fixtures__/defaultContext';
39-
import { defaultEcsServiceResourceProperties } from '../__fixtures__/defaultEcsServiceResourceProperties';
40-
import { defaultEvent } from '../__fixtures__/defaultEvent';
41-
import { defaultLogger } from '../__fixtures__/defaultLogger';
38+
import { defaultContext } from '../__fixtures__/default-context';
39+
import { defaultEcsServiceResourceProperties } from '../__fixtures__/default-ecs-service-resource-properties';
40+
import { defaultEvent } from '../__fixtures__/default-event';
41+
import { defaultLogger } from '../__fixtures__/default-logger';
4242

4343
afterEach(() => {
4444
mockCreateRequest.mockClear();
@@ -48,7 +48,7 @@ afterEach(() => {
4848
});
4949

5050
describe('createHandler', () => {
51-
it('sends tags with create request', async () => {
51+
test('sends tags with create request', async () => {
5252
const response = await handleCreate(
5353
{
5454
...defaultEvent,
@@ -84,7 +84,7 @@ describe('createHandler', () => {
8484
});
8585

8686
describe('updateHandler', () => {
87-
it('sends data update request', async () => {
87+
test('sends data update request', async () => {
8888
await handleUpdate(
8989
{
9090
...defaultEvent,
@@ -138,7 +138,7 @@ describe('updateHandler', () => {
138138
);
139139
});
140140

141-
it('does not delete keys if no old keys are deleted', async () => {
141+
test('does not delete keys if no old keys are deleted', async () => {
142142
await handleUpdate(
143143
{
144144
...defaultEvent,
@@ -189,7 +189,7 @@ describe('updateHandler', () => {
189189
);
190190
});
191191

192-
it('does not delete or create keys if no old keys or new keys are present', async () => {
192+
test('does not delete or create keys if no old keys or new keys are present', async () => {
193193
await handleUpdate(
194194
{
195195
...defaultEvent,

packages/cdk-blue-green-container-deployment/src/ecs-service.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -111,14 +111,7 @@ export class EcsService extends Construct implements IConnectable, IEcsService,
111111
serviceToken.addToRolePolicy(
112112
new PolicyStatement({
113113
effect: Effect.ALLOW,
114-
actions: [
115-
'ecs:CreateService',
116-
'ecs:UpdateService',
117-
'ecs:DeleteService',
118-
'ecs:DescribeServices',
119-
'ecs:TagResource',
120-
'ecs:UntagResource',
121-
],
114+
actions: ['ecs:CreateService', 'ecs:UpdateService', 'ecs:DeleteService', 'ecs:DescribeServices', 'ecs:TagResource', 'ecs:UntagResource'],
122115
resources: ['*'],
123116
}),
124117
);
@@ -183,4 +176,4 @@ export enum SchedulingStrategy {
183176
export enum PropagateTags {
184177
TASK_DEFINITION = 'TASK_DEFINITION',
185178
SERVICE = 'SERVICE',
186-
}
179+
}

packages/cdk-blue-green-container-deployment/src/lambdas/ecs-deployment-group/index.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ export const handleCreate: OnCreateHandler = async (event, context): Promise<Res
117117
return {
118118
physicalResourceId: deploymentGroupName,
119119
responseData: {
120-
Arn: arnForDeploymentGroup(applicationName, deploymentGroupName, context.invokedFunctionArn)
120+
Arn: arnForDeploymentGroup(applicationName, deploymentGroupName, context.invokedFunctionArn),
121121
},
122122
};
123123
};
@@ -165,8 +165,8 @@ export const handleUpdate: OnUpdateHandler = async (event, context): Promise<Res
165165
})
166166
.promise();
167167

168-
const newTagKeys: string[] = newProps.tags.map((t: any) => t.Key);
169-
const removableTagKeys: string[] = oldProps.tags.map((t: any) => t.Key).filter((t) => !newTagKeys.includes(t));
168+
const newTagKeys: string[] = newProps.tags.map((t: CodeDeploy.Tag) => t.Key as string);
169+
const removableTagKeys: string[] = oldProps.tags.map((t: CodeDeploy.Tag) => t.Key as string).filter((t) => !newTagKeys.includes(t));
170170

171171
if (removableTagKeys.length > 0) {
172172
await codeDeploy
@@ -189,7 +189,7 @@ export const handleUpdate: OnUpdateHandler = async (event, context): Promise<Res
189189
return {
190190
physicalResourceId: newProps.deploymentGroupName,
191191
responseData: {
192-
Arn: deploymentGroupArn
192+
Arn: deploymentGroupArn,
193193
},
194194
};
195195
};
@@ -206,21 +206,21 @@ const handleDelete: OnDeleteHandler = async (event): Promise<void> => {
206206
};
207207

208208
const extractArnParts = (invokedFunctionArn: string): ArnParts => {
209-
const matcher = invokedFunctionArn.match(/arn:(?<partition>\w+):lambda:(?<region>[\w\-]+):(?<accountId>\d+):.*/);
210-
if(!matcher || !matcher.groups || !matcher.groups.partition || !matcher.groups.region || !matcher.groups.accountId) {
211-
throw new Error(`Unable to extract necessary parts from function name. (${invokedFunctionArn}).`)
209+
const matcher = /arn:(?<partition>\w+):lambda:(?<region>[\w-]+):(?<accountId>\d+):.*/.exec(invokedFunctionArn);
210+
if (!matcher || !matcher.groups || !matcher.groups.partition || !matcher.groups.region || !matcher.groups.accountId) {
211+
throw new Error(`Unable to extract necessary parts from function name. (${invokedFunctionArn}).`);
212212
}
213213
return {
214214
awsPartition: matcher.groups.partition,
215215
awsRegion: matcher.groups.region,
216-
awsAccountId: matcher.groups.accountId
217-
}
218-
}
216+
awsAccountId: matcher.groups.accountId,
217+
};
218+
};
219219

220220
const arnForDeploymentGroup = (applicationName: string, deploymentGroupName: string, invokedFunctionArn: string): string => {
221221
const arnParts = extractArnParts(invokedFunctionArn);
222-
return `arn:${arnParts.awsPartition}:codedeploy:${arnParts.awsRegion}:${arnParts.awsAccountId}:deploymentgroup:${applicationName}/${deploymentGroupName}`
223-
}
222+
return `arn:${arnParts.awsPartition}:codedeploy:${arnParts.awsRegion}:${arnParts.awsAccountId}:deploymentgroup:${applicationName}/${deploymentGroupName}`;
223+
};
224224

225225
export const handler = customResourceHelper(
226226
(): ResourceHandler => ({

0 commit comments

Comments
 (0)