Skip to content

Commit

Permalink
testinteg-tests-alpha): update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
WinterYukky committed Jul 14, 2023
1 parent 92a2e3c commit 71b7605
Show file tree
Hide file tree
Showing 9 changed files with 140 additions and 150 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
{
"version": "32.0.0",
"files": {
"0c7aaf76cc1dd0b815cbae58e87758f463c3c89426c018d858acff3d1ec29630": {
"618fc075b4931b5a1dd4d257a0604152ada8eae3cad6807905d6901ec179f677": {
"source": {
"path": "asset.0c7aaf76cc1dd0b815cbae58e87758f463c3c89426c018d858acff3d1ec29630.bundle",
"path": "asset.618fc075b4931b5a1dd4d257a0604152ada8eae3cad6807905d6901ec179f677.bundle",
"packaging": "zip"
},
"destinations": {
"current_account-current_region": {
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
"objectKey": "0c7aaf76cc1dd0b815cbae58e87758f463c3c89426c018d858acff3d1ec29630.zip",
"objectKey": "618fc075b4931b5a1dd4d257a0604152ada8eae3cad6807905d6901ec179f677.zip",
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
}
}
},
"73baddea6b6218c0efd01444a62d4ee70b363fd48282cb0719ff5f6ceedc46b4": {
"97ceceb47d60bd8b1fdf97533201dffd346e8c0830ece372061638cdd56d32fd": {
"source": {
"path": "lambdaintegrationDefaultTestDeployAssertAC2ED705.template.json",
"packaging": "file"
},
"destinations": {
"current_account-current_region": {
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
"objectKey": "73baddea6b6218c0efd01444a62d4ee70b363fd48282cb0719ff5f6ceedc46b4.json",
"objectKey": "97ceceb47d60bd8b1fdf97533201dffd346e8c0830ece372061638cdd56d32fd.json",
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
}
},
"expected": "{\"$ObjectLike\":{\"body\":{\"message\":\"Hello\"}}}",
"salt": "1689319968176"
"salt": "1689327791749"
},
"UpdateReplacePolicy": "Delete",
"DeletionPolicy": "Delete"
Expand Down Expand Up @@ -71,7 +71,7 @@
"S3Bucket": {
"Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}"
},
"S3Key": "0c7aaf76cc1dd0b815cbae58e87758f463c3c89426c018d858acff3d1ec29630.zip"
"S3Key": "618fc075b4931b5a1dd4d257a0604152ada8eae3cad6807905d6901ec179f677.zip"
},
"Timeout": 120,
"Handler": "index.handler",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@
"validateOnSynth": false,
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}",
"cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}",
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/73baddea6b6218c0efd01444a62d4ee70b363fd48282cb0719ff5f6ceedc46b4.json",
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/97ceceb47d60bd8b1fdf97533201dffd346e8c0830ece372061638cdd56d32fd.json",
"requiresBootstrapStackVersion": 6,
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version",
"additionalDependencies": [
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,16 @@
import { CustomResourceHandler } from './base';
import { AwsApiCallRequest, AwsApiCallResult } from './types';
import { decode } from './utils';
import * as sdkV2ToV3 from './sdk-v2-to-v3';

// These functions defined at 'aws-cdk-lib/custom-resources'.
// However, 'aws-cdk-lib/custom-resources' exports the some constructs,
// so when import the package, then bundle size is too large and lambda function is not working.
// To avoid this issue, we using inject of esbuild (https://esbuild.github.io/api/#inject)
declare const getV3ClientPackageName: (clientName: string) => string;
declare const findV3ClientConstructor: (pkg: Object) => new (config: any) => {
send: (command: any) => Promise<any>;
config: any;
};

/**
* Flattens a nested object
Expand Down Expand Up @@ -37,7 +46,7 @@ interface V3SdkPkg {
}

function getServicePackage(service: string): V3SdkPkg {
const packageName = sdkV2ToV3.getV3ClientPackageName(service);
const packageName = getV3ClientPackageName(service);
try {
/* eslint-disable-next-line @typescript-eslint/no-require-imports */
const pkg = require(packageName);
Expand All @@ -54,7 +63,7 @@ function getServicePackage(service: string): V3SdkPkg {

function getServiceClient(sdkPkg: V3SdkPkg): any {
try {
const ServiceClient = sdkV2ToV3.findV3ClientConstructor(sdkPkg.pkg);
const ServiceClient = findV3ClientConstructor(sdkPkg.pkg);
return new ServiceClient({});
} catch (e) {
console.error(e);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { AssertionRequest, AssertionResult, ExpectedResult } from '../../../../lib/assertions';
import { Match } from '../../../../lib/assertions/match';
import { getV3ClientPackageName, findV3ClientConstructor } from 'aws-cdk-lib/custom-resources';
import { AssertionHandler } from '../../../../lib/assertions/providers/lambda-handler/assertion';

function assertionHandler() {
Expand All @@ -9,8 +10,10 @@ function assertionHandler() {
return new AssertionHandler({} as any, context); // as any to ignore all type checks
}

// eslint-disable-next-line @typescript-eslint/no-require-imports
jest.mock('../../../../lib/assertions/providers/lambda-handler/sdk-v2-to-v3', () => require('aws-cdk-lib/custom-resources'));
// @ts-ignore
global.getV3ClientPackageName = getV3ClientPackageName;
// @ts-ignore
global.findV3ClientConstructor = findV3ClientConstructor;
beforeAll(() => {
jest.useFakeTimers();
jest.spyOn(console, 'log').mockImplementation(() => { return true; });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { CustomResourceHandler } from '../../../../lib/assertions/providers/lamb
import { mockClient } from 'aws-sdk-client-mock';
import { ListBucketsCommand, ListBucketsOutput, S3Client } from '@aws-sdk/client-s3';
import { SFNClient, StartExecutionCommand } from '@aws-sdk/client-sfn';
import { getV3ClientPackageName, findV3ClientConstructor } from 'aws-cdk-lib/custom-resources';
import 'aws-sdk-client-mock-jest';

interface MyHandlerRequest {
Expand All @@ -18,8 +19,11 @@ interface MyHandlerResponse {
interface CloudFormationResponse extends Omit<AWSLambda.CloudFormationCustomResourceResponse, 'Data'> {
readonly Data: any;
}
// eslint-disable-next-line @typescript-eslint/no-require-imports
jest.mock('../../../../lib/assertions/providers/lambda-handler/sdk-v2-to-v3', () => require('aws-cdk-lib/custom-resources'));

// @ts-ignore
global.getV3ClientPackageName = getV3ClientPackageName;
// @ts-ignore
global.findV3ClientConstructor = findV3ClientConstructor;
const s3Mock = mockClient(S3Client);
const sfnMock = mockClient(SFNClient);
describe('CustomResourceHandler', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { DescribeInstancesCommand, EC2Client } from '@aws-sdk/client-ec2';
import { mockClient } from 'aws-sdk-client-mock';
import { AwsApiCallRequest, AwsApiCallResult } from '../../../../lib/assertions';
import { AwsApiCallHandler } from '../../../../lib/assertions/providers/lambda-handler/sdk';
import { getV3ClientPackageName, findV3ClientConstructor } from 'aws-cdk-lib/custom-resources';
import 'aws-sdk-client-mock-jest';

function sdkHandler() {
Expand All @@ -12,8 +13,10 @@ function sdkHandler() {
};
return new AwsApiCallHandler({} as any, context); // as any to ignore all type checks
}
// eslint-disable-next-line @typescript-eslint/no-require-imports
jest.mock('../../../../lib/assertions/providers/lambda-handler/sdk-v2-to-v3', () => require('aws-cdk-lib/custom-resources'));
// @ts-ignore
global.getV3ClientPackageName = getV3ClientPackageName;
// @ts-ignore
global.findV3ClientConstructor = findV3ClientConstructor;
beforeAll(() => {
jest.useFakeTimers();
jest.spyOn(console, 'log').mockImplementation(() => { return true; });
Expand Down

0 comments on commit 71b7605

Please sign in to comment.