forked from aws-powertools/powertools-lambda-layer-cdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlambda-powertools-typescript-layer.test.ts
85 lines (69 loc) · 2.57 KB
/
lambda-powertools-typescript-layer.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
import { Stack } from 'aws-cdk-lib';
import { Template } from 'aws-cdk-lib/assertions';
import { RuntimeFamily } from 'aws-cdk-lib/aws-lambda';
import { LambdaPowertoolsLayer } from '../src';
describe('with minimal configuration the construct', () => {
const stack = new Stack();
new LambdaPowertoolsLayer(stack, 'PowertoolsLayer', {
runtimeFamily: RuntimeFamily.NODEJS,
});
const template = Template.fromStack(stack);
test('synthesizes successfully', () => {
template.hasResourceProperties('AWS::Lambda::LayerVersion', {
Description: 'Lambda Powertools for TypeScript [x86_64] latest version',
});
});
test('has license set to MIT-0', () => {
template.hasResourceProperties('AWS::Lambda::LayerVersion', {
LicenseInfo: 'MIT-0',
});
});
test('matches the nodejs runtimes', () => {
template.hasResourceProperties('AWS::Lambda::LayerVersion', {
CompatibleRuntimes: [
'nodejs12.x',
'nodejs14.x',
'nodejs16.x',
],
});
});
});
describe('for layerVersionName configuration the construct', () => {
test('synthisizes to a layer with provided name', () => {
const stack = new Stack();
new LambdaPowertoolsLayer(stack, 'PowertoolsLayer', {
layerVersionName: 'mySpecialName',
});
Template.fromStack(stack).hasResourceProperties('AWS::Lambda::LayerVersion', {
LayerName: 'mySpecialName',
});
});
});
describe('with version configuration the construct', () => {
test('synthesizes to a layer with specific valid version', () => {
const stack = new Stack();
const version = '0.9.0';
new LambdaPowertoolsLayer(stack, 'PowertoolsLayer', {
runtimeFamily: RuntimeFamily.NODEJS,
version: version,
});
Template.fromStack(stack).hasResourceProperties('AWS::Lambda::LayerVersion', {
Description: `Lambda Powertools for TypeScript [x86_64] version ${version}`,
});
});
test('fails with invalid version', () => {
const stack = new Stack();
expect(() => new LambdaPowertoolsLayer(stack, 'PowertoolsLayerBadVersion', {
runtimeFamily: RuntimeFamily.NODEJS,
version: '12.222.21123',
})).toThrow(/docker exited with status 1/);
});
test('returns version with @ when provided provided', () => {
const args = LambdaPowertoolsLayer.constructBuildArgs(RuntimeFamily.NODEJS, undefined, '0.9.0');
expect(args).toEqual('@0.9.0');
});
test('returns empty when no version provided', () => {
const args = LambdaPowertoolsLayer.constructBuildArgs(RuntimeFamily.NODEJS, undefined, undefined);
expect(args).toEqual('');
});
});