Skip to content

Commit

Permalink
chore: upgrade to SDK v3 (#1709)
Browse files Browse the repository at this point in the history
Follow-up to #1706, which upgraded the node runtimes to 20. Node 20 is only compatible with SDK v3. This removes every use of the SDK v2.
  • Loading branch information
comcalvi authored Jul 25, 2024
1 parent 1ffeded commit 1f73dd2
Show file tree
Hide file tree
Showing 20 changed files with 1,648 additions and 510 deletions.
32 changes: 20 additions & 12 deletions .projen/deps.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions .projen/tasks.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions .projenrc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,16 @@ const project = new typescript.TypeScriptProject({
'@types/adm-zip',
'@types/follow-redirects',
'aws-cdk',
'jest-create-mock-instance',
'constructs',
'aws-cdk-lib',
'standard-version',
'ts-jest',
'typescript',
'aws-sdk',
'aws-sdk-mock',
'@aws-sdk/client-s3',
'@aws-sdk/client-ssm',
'@aws-sdk/client-secrets-manager',
'@aws-sdk/client-codepipeline',
'@aws-sdk/client-cloudwatch',
'[email protected]', // need to pin due to https://github.com/axios/axios/issues/5101
'rrule',
'esbuild',
Expand Down
38 changes: 19 additions & 19 deletions lib/__tests__/change-control-lambda/disable-transition.test.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
// eslint-disable-next-line @typescript-eslint/no-require-imports
import AWS = require('aws-sdk');

const mockDisableStageTransition = jest.fn((_params: AWS.CodePipeline.DisableStageTransitionInput) => {
return { promise: () => Promise.resolve({}) };
}).mockName('AWS.CodePipeline.disableStageTransition');

const mockEnableStageTransition = jest.fn((_params: AWS.CodePipeline.EnableStageTransitionInput) => {
return { promise: () => Promise.resolve({}) };
}).mockName('AWS.CodePipeline.enableStageTransition');

const pipelineName = 'MyPipeline';
const stageName = 'MyStage';

jest.mock('aws-sdk', () => {
const mockCodePipelineClient = {
disableStageTransition: jest.fn().mockName('CodePipeline.disableStageTransition'),
enableStageTransition: jest.fn().mockName('CodePipeline.enableStageTransition'),

};

jest.mock('@aws-sdk/client-codepipeline', () => {
return {
CodePipeline: jest.fn(() => {
return {
disableStageTransition: mockDisableStageTransition,
enableStageTransition: mockEnableStageTransition,
};
CodePipeline: jest.fn().mockImplementation(() => {
return mockCodePipelineClient;
}),
};
});

beforeEach(() => {
mockCodePipelineClient.disableStageTransition.mockImplementation(() => Promise.resolve({}));
mockCodePipelineClient.enableStageTransition.mockImplementation(() => Promise.resolve({}));
});

describe('disableTransition', () => {
// eslint-disable-next-line @typescript-eslint/no-require-imports
const disableTransition = require('../../change-control-lambda/disable-transition').disableTransition;
Expand All @@ -34,7 +34,7 @@ describe('disableTransition', () => {
await expect(disableTransition(pipelineName, stageName, reason))
.resolves.toBeUndefined();
// THEN
expect(mockDisableStageTransition)
expect(mockCodePipelineClient.disableStageTransition)
.toHaveBeenCalledWith({ pipelineName, stageName, reason, transitionType: 'Inbound' });
});

Expand All @@ -46,7 +46,7 @@ describe('disableTransition', () => {
.resolves.toBeUndefined();
// THEN
const cleanReason = reason.replace(/[^a-zA-Z0-9!@ \(\)\.\*\?\-]/g, '-');
expect(mockDisableStageTransition)
expect(mockCodePipelineClient.disableStageTransition)
.toHaveBeenCalledWith({ pipelineName, stageName, reason: cleanReason, transitionType: 'Inbound' });
});

Expand All @@ -58,7 +58,7 @@ describe('disableTransition', () => {
.resolves.toBeUndefined();
// THEN
const cleanReason = reason.slice(0, 300);
expect(mockDisableStageTransition)
expect(mockCodePipelineClient.disableStageTransition)
.toHaveBeenCalledWith({ pipelineName, stageName, reason: cleanReason, transitionType: 'Inbound' });
});
});
Expand All @@ -68,9 +68,9 @@ test('enableTransition', async () => {
// eslint-disable-next-line @typescript-eslint/no-require-imports
const enableTransition = require('../../change-control-lambda/disable-transition').enableTransition;
// WHEN
await expect(() => enableTransition(pipelineName, stageName))
expect(() => enableTransition(pipelineName, stageName))
.not.toThrow();
// THEN
expect(mockEnableStageTransition)
expect(mockCodePipelineClient.enableStageTransition)
.toHaveBeenCalledWith({ pipelineName, stageName, transitionType: 'Inbound' });
});
40 changes: 16 additions & 24 deletions lib/__tests__/change-control-lambda/handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,21 @@ import * as timeWindow from '../../change-control-lambda/time-window';
// | |
// |_|

jest.mock('aws-sdk', () => {
const mockS3Client = {
getObject: jest.fn().mockName('S3.GetObject'),
};

jest.mock('@aws-sdk/client-s3', () => {
return {
S3: jest.fn(() => {
return {
getObject: mockGetObject,
};
}).mockName('AWS.S3'),
CodePipeline: jest.fn(() => {
return {};
}).mockName('AWS.CodePipeline'),
S3: jest.fn().mockImplementation(() => {
return mockS3Client;
}),
};
});

jest.mock('../../change-control-lambda/disable-transition');
jest.mock('../../change-control-lambda/time-window');

const mockGetObject = jest.fn().mockName('AWS.S3.getObject');

const mockEnableTransition =
jest.fn((_pipeline: string, _stage: string) => Promise.resolve(undefined))
.mockName('enableTransition');
Expand Down Expand Up @@ -87,9 +85,7 @@ describe('handler', () => {
test('when S3 access fails', async () => {
// GIVEN
const e = new Error('S3 Not Working - the apocalypse has begun');
mockGetObject.mockImplementationOnce(() => ({
promise: () => Promise.reject(e),
}));
mockS3Client.getObject.mockImplementationOnce(() => Promise.reject(e));

// THEN
return expect(handler()).rejects.toThrow(e);
Expand All @@ -99,9 +95,7 @@ describe('handler', () => {
for (const cause of ['NoSuchKey', 'NoSuchBucket']) {
test(`when no calendar is found (due to ${cause})`, async () => {
// GIVEN
mockGetObject.mockImplementationOnce(() => ({
promise: () => Promise.reject({ code: cause, message: cause }),
}));
mockS3Client.getObject.mockImplementationOnce(() => Promise.reject({ code: cause, message: cause }));
mockShouldBlockPipeline.mockReturnValueOnce({
summary: 'Blocked by default',
// Other properties - values irrelevant
Expand All @@ -117,10 +111,10 @@ describe('handler', () => {
await expect(handler()).resolves.toBeUndefined();

// THEN
await expect(mockGetObject)
expect(mockS3Client.getObject)
.toHaveBeenCalledWith({ Bucket: bucketName, Key: objectKey });

await expect(mockShouldBlockPipeline)
expect(mockShouldBlockPipeline)
.toHaveBeenCalledWith(expect.stringContaining('No change control calendar was found'),
expect.any(Date));

Expand All @@ -132,19 +126,17 @@ describe('handler', () => {
test('when the window is open', async () => {
// GIVEN
const iCalBody = 'Some iCal document (obviously, this is a fake one!)';
mockGetObject.mockImplementationOnce(() => ({
promise: () => Promise.resolve({ Body: iCalBody }),
}));
mockS3Client.getObject.mockImplementationOnce(() => Promise.resolve({ Body: iCalBody }));
mockShouldBlockPipeline.mockReturnValueOnce(undefined);

// WHEN
await expect(handler()).resolves.toBeUndefined();

// THEN
await expect(mockGetObject)
expect(mockS3Client.getObject)
.toHaveBeenCalledWith({ Bucket: bucketName, Key: objectKey });

await expect(mockShouldBlockPipeline)
expect(mockShouldBlockPipeline)
.toHaveBeenCalledWith(iCalBody, expect.any(Date));

return expect(mockEnableTransition)
Expand Down
12 changes: 6 additions & 6 deletions lib/__tests__/chime-notifier.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ jest.mock('https', () => {
const mockHttpsWrite = jest.fn();

test('call codepipeline and then post to webhooks', async () => {
codePipeline.getPipelineExecution = jest.fn().mockReturnValue({
promise: () => Promise.resolve({
codePipeline.getPipelineExecution = jest.fn().mockReturnValue(
Promise.resolve({
pipelineExecution: {
pipelineExecutionId: 'xyz',
pipelineVersion: 1,
Expand All @@ -48,10 +48,10 @@ test('call codepipeline and then post to webhooks', async () => {
],
},
}),
});
);

codePipeline.listActionExecutions = jest.fn().mockReturnValue({
promise: () => Promise.resolve({
codePipeline.listActionExecutions = jest.fn().mockReturnValue(
Promise.resolve({
actionExecutionDetails: [
{
stageName: 'Source',
Expand All @@ -75,7 +75,7 @@ test('call codepipeline and then post to webhooks', async () => {
},
],
}),
});
);

await handler({
webhookUrls: ['https://my.url/'],
Expand Down
Loading

0 comments on commit 1f73dd2

Please sign in to comment.