Skip to content

Commit decd13e

Browse files
committed
test(layers): add parser to layber publisher e2e test
1 parent f4a5531 commit decd13e

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

layers/tests/e2e/layerPublisher.class.test.functionCode.ts

+11-1
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ import { AppConfigProvider } from '@aws-lambda-powertools/parameters/appconfig';
88
import { DynamoDBProvider } from '@aws-lambda-powertools/parameters/dynamodb';
99
import { SecretsProvider } from '@aws-lambda-powertools/parameters/secrets';
1010
import { SSMProvider } from '@aws-lambda-powertools/parameters/ssm';
11+
import { EventBridgeSchema } from '@aws-lambda-powertools/parser/schemas';
1112
import { Tracer } from '@aws-lambda-powertools/tracer';
1213
import { AppConfigDataClient } from '@aws-sdk/client-appconfigdata';
1314
import { DynamoDBClient } from '@aws-sdk/client-dynamodb';
1415
import { SecretsManagerClient } from '@aws-sdk/client-secrets-manager';
1516
import { SSMClient } from '@aws-sdk/client-ssm';
17+
import { z } from 'zod';
1618

1719
const logger = new Logger({
1820
logLevel: 'DEBUG',
@@ -48,6 +50,10 @@ new DynamoDBProvider({ tableName: 'foo', awsSdkV3Client: ddbClient });
4850
// Instantiating the BatchProcessor will confirm that the utility can be used
4951
new BatchProcessor(EventType.SQS);
5052

53+
const testSchema = z.object({ instance_id: z.string(), state: z.string() });
54+
55+
const testEventSchema = EventBridgeSchema.extend({ detail: testSchema });
56+
5157
const layerPath = process.env.LAYERS_PATH || '/opt/nodejs/node_modules';
5258
const expectedVersion = process.env.POWERTOOLS_PACKAGE_VERSION || '0.0.0';
5359

@@ -79,7 +85,7 @@ const getVersionFromModule = async (moduleName: string): Promise<string> => {
7985
return moduleVersion;
8086
};
8187

82-
export const handler = async (): Promise<void> => {
88+
export const handler = async (event: unknown): Promise<void> => {
8389
// Check that the packages version matches the expected one
8490
for (const moduleName of [
8591
'commons',
@@ -89,6 +95,7 @@ export const handler = async (): Promise<void> => {
8995
'parameters',
9096
'idempotency',
9197
'batch',
98+
'parser',
9299
]) {
93100
const moduleVersion = await getVersionFromModule(moduleName);
94101
if (moduleVersion !== expectedVersion) {
@@ -115,4 +122,7 @@ export const handler = async (): Promise<void> => {
115122
// the presence of a log will indicate that the logger is working
116123
// while the content of the log will indicate that the tracer is working
117124
logger.debug('subsegment', { subsegment: subsegment.format() });
125+
126+
// Check that the parser is working
127+
testEventSchema.parse(event);
118128
};

layers/tests/e2e/layerPublisher.test.ts

+19
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
import { TestNodejsFunction } from '@aws-lambda-powertools/testing-utils/resources/lambda';
1414
import { App } from 'aws-cdk-lib';
1515
import { LayerVersion } from 'aws-cdk-lib/aws-lambda';
16+
import type { EventBridgeEvent } from 'aws-lambda';
1617
import packageJson from '../../package.json';
1718
import { LayerPublisherStack } from '../../src/layer-publisher-stack';
1819
import {
@@ -132,6 +133,24 @@ describe('Layers E2E tests', () => {
132133
functionName: testStack.findAndGetStackOutputValue(
133134
`test${outputFormat}Fn`
134135
),
136+
// Uses an EventBridge event payload to test parser functionality
137+
payload: {
138+
version: '0',
139+
id: '6a7e8feb-b491-4cf7-a9f1-bf3703467718',
140+
'detail-type': 'EC2 Instance State-change Notification',
141+
source: 'aws.ec2',
142+
account: '111122223333',
143+
time: '2017-12-22T18:43:48Z',
144+
region: 'us-west-1',
145+
resources: [
146+
'arn:aws:ec2:us-west-1:123456789012:instance/i-1234567890abcdef0',
147+
],
148+
detail: {
149+
instance_id: 'i-1234567890abcdef0',
150+
state: 'terminated',
151+
},
152+
'replay-name': 'replay_archive',
153+
} satisfies EventBridgeEvent<string, unknown>,
135154
})
136155
);
137156
}

0 commit comments

Comments
 (0)