forked from aws-powertools/powertools-lambda-layer-cdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlambda-powertools-python-layer.test.ts
132 lines (107 loc) · 4.15 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import { Stack } from 'aws-cdk-lib';
import { Template } from 'aws-cdk-lib/assertions';
import { Architecture, 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 [x86_64] 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.7',
'python3.8',
'python3.9',
],
});
});
});
describe('with arm64 architecture', () => {
const stack = new Stack();
new LambdaPowertoolsLayer(stack, 'PowertoolsLayer', {
runtimeFamily: RuntimeFamily.PYTHON,
compatibleArchitectures: [Architecture.ARM_64],
});
const template = Template.fromStack(stack);
test('synthesizes successfully', () => {
template.hasResourceProperties('AWS::Lambda::LayerVersion', {
Description: 'Lambda Powertools for Python [arm64] latest version',
CompatibleArchitectures: ['arm64'],
});
});
});
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 [x86_64] version 1.21.0',
});
});
test('fails with invalid version', () => {
const stack = new Stack();
expect(() => new LambdaPowertoolsLayer(stack, 'PowertoolsLayerBadVersion', {
version: '0.0.0',
})).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 [x86_64] with extra dependencies version 1.22.0',
});
});
test('synthesizes with extras 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 [x86_64] with extra dependencies latest version',
});
});
});
describe('construct build args for Dockerfile', () => {
test('returns extras and version', () => {
const args = LambdaPowertoolsLayer.constructBuildArgs(RuntimeFamily.PYTHON, true, '1.21.0');
expect(args).toEqual('[all]==1.21.0');
});
test('returns only extras when no version provided', () => {
const args = LambdaPowertoolsLayer.constructBuildArgs(RuntimeFamily.PYTHON, true, undefined);
expect(args).toEqual('[all]');
});
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('');
});
});