Skip to content

Commit

Permalink
improv(tests): adopt aws cdk cli lib (#1633)
Browse files Browse the repository at this point in the history
* tests(ci): add testing package

* chore: add comments on types

* chore: improve code smells

* chore: improve code smells

* feat(testing): created base testing

* chore: removed aws-cdk-lib & aws-cdk

* tests: moved tracer to new testing lib

* tests: move logger to new testing

* tests: move metrics to new testing

* restored string

* tests: move idempotency to new testing

* tests: move parameters to new testing

* chore: added testing pkg to ci

* tests: move layers to new testing

* chore: remove ref suffix
  • Loading branch information
dreamorosi authored Jul 28, 2023
1 parent 8ea1672 commit 4318d6f
Show file tree
Hide file tree
Showing 36 changed files with 1,387 additions and 1,458 deletions.
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.stack,
'LayerVersionArnReference',
outputs['LatestLayerArn']
);
createStackWithLambdaFunction({
stack: testStack.stack,
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

0 comments on commit 4318d6f

Please sign in to comment.