Skip to content

improv(tests): adopt aws cdk cli lib #1633

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Jul 28, 2023
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/actions/cached-node-modules/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,6 @@ runs:
npm run build -w packages/metrics & \
npm run build -w packages/parameters & \
npm run build -w packages/idempotency & \
npm run build -w packages/batch
npm run build -w packages/batch & \
npm run build -w packages/testing
shell: bash
6 changes: 6 additions & 0 deletions layers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@
},
"homepage": "https://github.com/aws-powertools/powertools-lambda-typescript#readme",
"devDependencies": {
"@aws-lambda-powertools/testing-utils": "file:../packages/testing",
"source-map-support": "^0.5.21"
},
"dependencies": {
"aws-cdk": "^2.88.0",
"aws-cdk-lib": "^2.88.0",
"esbuild": "^0.18.17"
}
}
64 changes: 33 additions & 31 deletions layers/tests/e2e/layerPublisher.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
*
* @group e2e/layers/all
*/
import { App, Stack } from 'aws-cdk-lib';
import { Tracing } from 'aws-cdk-lib/aws-lambda';
import { App } from 'aws-cdk-lib';
import { LayerVersion, Tracing } from 'aws-cdk-lib/aws-lambda';
import { LayerPublisherStack } from '../../src/layer-publisher-stack';
import {
deployStack,
destroyStack,
} from '../../../packages/commons/tests/utils/cdk-cli';
TestStack,
defaultRuntime,
} from '@aws-lambda-powertools/testing-utils';
import {
generateUniqueName,
invokeFunction,
Expand All @@ -30,7 +30,7 @@ import { v4 } from 'uuid';
import path from 'path';
import packageJson from '../../package.json';

const runtime: string = process.env.RUNTIME || 'nodejs18x';
const runtime: string = process.env.RUNTIME || defaultRuntime;

if (!isValidRuntimeKey(runtime)) {
throw new Error(`Invalid runtime key: ${runtime}`);
Expand Down Expand Up @@ -66,30 +66,33 @@ describe(`layers E2E tests (LayerPublisherStack) for runtime: ${runtime}`, () =>
const lambdaFunctionCodeFile = 'layerPublisher.class.test.functionCode.ts';

const invocationCount = 1;

const integTestApp = new App();
let stackLayer: LayerPublisherStack;
let stackFunction: Stack;

const powerToolsPackageVersion = packageJson.version;
const layerName = generateUniqueName(
RESOURCE_NAME_PREFIX,
uuid,
runtime,
'layer'
);

beforeAll(async () => {
const layerName = generateUniqueName(
RESOURCE_NAME_PREFIX,
uuid,
runtime,
'layer'
);
const testStack = new TestStack(stackNameFunction);
const layerApp = new App();
const layerStack = new LayerPublisherStack(layerApp, stackNameLayers, {
layerName,
powertoolsPackageVersion: powerToolsPackageVersion,
ssmParameterLayerArn: ssmParameterLayerName,
});
const testLayerStack = new TestStack(stackNameLayers, layerApp, layerStack);

stackLayer = new LayerPublisherStack(integTestApp, stackNameLayers, {
layerName: layerName,
powertoolsPackageVersion: powerToolsPackageVersion,
ssmParameterLayerArn: ssmParameterLayerName,
});
beforeAll(async () => {
const outputs = await testLayerStack.deploy();

stackFunction = createStackWithLambdaFunction({
app: integTestApp,
stackName: stackNameFunction,
const layerVersion = LayerVersion.fromLayerVersionArn(
testStack.stackRef,
'LayerVersionArnReference',
outputs['LatestLayerArn']
);
createStackWithLambdaFunction({
stack: testStack.stackRef,
functionName: functionName,
functionEntry: path.join(__dirname, lambdaFunctionCodeFile),
tracing: Tracing.ACTIVE,
Expand All @@ -107,11 +110,10 @@ describe(`layers E2E tests (LayerPublisherStack) for runtime: ${runtime}`, () =>
'@aws-lambda-powertools/tracer',
],
},
layers: [stackLayer.lambdaLayerVersion],
layers: [layerVersion],
});

await deployStack(integTestApp, stackLayer);
await deployStack(integTestApp, stackFunction);
await testStack.deploy();

invocationLogs = await invokeFunction(
functionName,
Expand Down Expand Up @@ -167,8 +169,8 @@ describe(`layers E2E tests (LayerPublisherStack) for runtime: ${runtime}`, () =>

afterAll(async () => {
if (!process.env.DISABLE_TEARDOWN) {
await destroyStack(integTestApp, stackFunction);
await destroyStack(integTestApp, stackLayer);
await testLayerStack.destroy();
await testStack.destroy();
}
}, TEARDOWN_TIMEOUT);
});
1 change: 1 addition & 0 deletions lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"packages/parameters",
"packages/idempotency",
"packages/batch",
"packages/testing",
"examples/cdk",
"examples/sam",
"layers"
Expand Down
Loading