forked from aws-samples/cdk-lambda-powertools-python-layer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlambda-powertools-python-layer.test.ts
118 lines (94 loc) · 3.62 KB
/
lambda-powertools-python-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
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
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 no configuration the construct', () => {
const stack = new Stack();
new LambdaPowertoolsLayer(stack, 'PowertoolsLayer');
const template = Template.fromStack(stack);
test('synthesizes successfully', () => {
template.hasResourceProperties('AWS::Lambda::LayerVersion', {
Description: 'Lambda Powertools for Python latest version',
});
});
test('has license set to MIT-0', () => {
template.hasResourceProperties('AWS::Lambda::LayerVersion', {
LicenseInfo: 'MIT-0',
});
});
test('matches the python 3.x runtimes', () => {
template.hasResourceProperties('AWS::Lambda::LayerVersion', {
CompatibleRuntimes: [
'python3.6',
'python3.7',
'python3.8',
'python3.9',
],
});
});
});
describe('for layerVersionName configuraiton 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();
new LambdaPowertoolsLayer(stack, 'PowertoolsLayer', {
version: '1.21.0',
});
Template.fromStack(stack).hasResourceProperties('AWS::Lambda::LayerVersion', {
Description: 'Lambda Powertools for Python version 1.21.0',
});
});
test('fails with invalid version', () => {
const stack = new Stack();
expect(() => new LambdaPowertoolsLayer(stack, 'PowertoolsLayerBadVersion', {
version: '12.222.21123',
})).toThrow(/docker exited with status 1/);
});
test('synthesizes with pynadtic and specific version', () => {
const stack = new Stack();
new LambdaPowertoolsLayer(stack, 'LayerExtrasVersion', {
includeExtras: true,
version: '1.22.0',
});
Template.fromStack(stack).hasResourceProperties('AWS::Lambda::LayerVersion', {
Description: 'Lambda Powertools for Python with Pydantic version 1.22.0',
});
});
test('synthesizes with pyndatic and latest version', () => {
const stack = new Stack();
new LambdaPowertoolsLayer(stack, 'LayerExtrasNoVersion', {
includeExtras: true,
});
Template.fromStack(stack).hasResourceProperties('AWS::Lambda::LayerVersion', {
Description: 'Lambda Powertools for Python with Pydantic latest version',
});
});
});
describe('construct build args for Dockerfile', () => {
test('returns pydantic and version', () => {
const args = LambdaPowertoolsLayer.constructBuildArgs(RuntimeFamily.PYTHON, true, '1.21.0');
expect(args).toEqual('[pydantic]==1.21.0');
});
test('returns only pydantic when no version provided', () => {
const args = LambdaPowertoolsLayer.constructBuildArgs(RuntimeFamily.PYTHON, true, undefined);
expect(args).toEqual('[pydantic]');
});
test('returns only version when no extras flag provided', () => {
const args = LambdaPowertoolsLayer.constructBuildArgs(RuntimeFamily.PYTHON, undefined, '1.11.0');
expect(args).toEqual('==1.11.0');
});
test('returns empty when no version and extras provided', () => {
const args = LambdaPowertoolsLayer.constructBuildArgs(RuntimeFamily.PYTHON, undefined, undefined);
expect(args).toEqual('');
});
});