-
Notifications
You must be signed in to change notification settings - Fork 154
/
Copy pathlayerPublisher.test.ts
174 lines (154 loc) · 4.48 KB
/
layerPublisher.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/**
* Test LayerPublisherStack class
*
* @group e2e/layers/all
*/
import { App, Stack } from 'aws-cdk-lib';
import { Tracing } from 'aws-cdk-lib/aws-lambda';
import { LayerPublisherStack } from '../../src/layer-publisher-stack';
import {
deployStack,
destroyStack,
} from '../../../packages/commons/tests/utils/cdk-cli';
import {
generateUniqueName,
invokeFunction,
isValidRuntimeKey,
createStackWithLambdaFunction,
} from '../../../packages/commons/tests/utils/e2eUtils';
import {
RESOURCE_NAME_PREFIX,
SETUP_TIMEOUT,
TEARDOWN_TIMEOUT,
TEST_CASE_TIMEOUT,
} from './constants';
import {
LEVEL,
InvocationLogs,
} from '../../../packages/commons/tests/utils/InvocationLogs';
import { v4 } from 'uuid';
import path from 'path';
import packageJson from '../../package.json';
const runtime: string = process.env.RUNTIME || 'nodejs18x';
if (!isValidRuntimeKey(runtime)) {
throw new Error(`Invalid runtime key: ${runtime}`);
}
describe(`layers E2E tests (LayerPublisherStack) for runtime: ${runtime}`, () => {
const uuid = v4();
let invocationLogs: InvocationLogs[];
const stackNameLayers = generateUniqueName(
RESOURCE_NAME_PREFIX,
uuid,
runtime,
'layerStack'
);
const stackNameFunction = generateUniqueName(
RESOURCE_NAME_PREFIX,
uuid,
runtime,
'functionStack'
);
const functionName = generateUniqueName(
RESOURCE_NAME_PREFIX,
uuid,
runtime,
'function'
);
const ssmParameterLayerName = generateUniqueName(
RESOURCE_NAME_PREFIX,
uuid,
runtime,
'parameter'
);
const lambdaFunctionCodeFile = 'layerPublisher.class.test.functionCode.ts';
const invocationCount = 1;
const integTestApp = new App();
let stackLayer: LayerPublisherStack;
let stackFunction: Stack;
const powerToolsPackageVersion = packageJson.version;
beforeAll(async () => {
const layerName = generateUniqueName(
RESOURCE_NAME_PREFIX,
uuid,
runtime,
'layer'
);
stackLayer = new LayerPublisherStack(integTestApp, stackNameLayers, {
layerName: layerName,
powertoolsPackageVersion: powerToolsPackageVersion,
ssmParameterLayerArn: ssmParameterLayerName,
});
stackFunction = createStackWithLambdaFunction({
app: integTestApp,
stackName: stackNameFunction,
functionName: functionName,
functionEntry: path.join(__dirname, lambdaFunctionCodeFile),
tracing: Tracing.ACTIVE,
environment: {
UUID: uuid,
POWERTOOLS_PACKAGE_VERSION: powerToolsPackageVersion,
POWERTOOLS_SERVICE_NAME: 'LayerPublisherStack',
},
runtime: runtime,
bundling: {
externalModules: [
'@aws-lambda-powertools/commons',
'@aws-lambda-powertools/logger',
'@aws-lambda-powertools/metrics',
'@aws-lambda-powertools/tracer',
],
},
layers: [stackLayer.lambdaLayerVersion],
});
await deployStack(integTestApp, stackLayer);
await deployStack(integTestApp, stackFunction);
invocationLogs = await invokeFunction(
functionName,
invocationCount,
'SEQUENTIAL'
);
}, SETUP_TIMEOUT);
describe('LayerPublisherStack usage', () => {
it(
'should have no errors in the logs, which indicates the pacakges version matches the expected one',
() => {
const logs = invocationLogs[0].getFunctionLogs(LEVEL.ERROR);
expect(logs.length).toBe(0);
},
TEST_CASE_TIMEOUT
);
it(
'should have one warning related to missing Metrics namespace',
() => {
const logs = invocationLogs[0].getFunctionLogs(LEVEL.WARN);
expect(logs.length).toBe(1);
expect(logs[0]).toContain('Namespace should be defined, default used');
},
TEST_CASE_TIMEOUT
);
it(
'should have one info log related to coldstart metric',
() => {
const logs = invocationLogs[0].getFunctionLogs(LEVEL.INFO);
expect(logs.length).toBe(1);
expect(logs[0]).toContain('ColdStart');
},
TEST_CASE_TIMEOUT
);
it(
'should have one debug log that says Hello World!',
() => {
const logs = invocationLogs[0].getFunctionLogs(LEVEL.DEBUG);
expect(logs.length).toBe(1);
expect(logs[0]).toContain('Hello World!');
},
TEST_CASE_TIMEOUT
);
});
afterAll(async () => {
if (!process.env.DISABLE_TEARDOWN) {
await destroyStack(integTestApp, stackFunction);
await destroyStack(integTestApp, stackLayer);
}
}, TEARDOWN_TIMEOUT);
});