1
+ import * as fs from 'fs' ;
1
2
import * as path from 'path' ;
2
3
import { Architecture , Code , Runtime } from '@aws-cdk/aws-lambda' ;
3
4
import { DockerImage } from '@aws-cdk/core' ;
@@ -25,7 +26,7 @@ beforeEach(() => {
25
26
26
27
test ( 'Bundling a function without dependencies' , ( ) => {
27
28
const entry = path . join ( __dirname , 'lambda-handler-nodeps' ) ;
28
- Bundling . bundle ( {
29
+ const assetCode = Bundling . bundle ( {
29
30
entry : entry ,
30
31
runtime : Runtime . PYTHON_3_7 ,
31
32
architecture : Architecture . X86_64 ,
@@ -36,7 +37,7 @@ test('Bundling a function without dependencies', () => {
36
37
bundling : expect . objectContaining ( {
37
38
command : [
38
39
'bash' , '-c' ,
39
- 'cp -R /asset-input/ /asset-output' ,
40
+ 'cp -rT /asset-input/ /asset-output' ,
40
41
] ,
41
42
} ) ,
42
43
} ) ) ;
@@ -47,11 +48,14 @@ test('Bundling a function without dependencies', () => {
47
48
} ) ,
48
49
platform : 'linux/amd64' ,
49
50
} ) ) ;
51
+
52
+ const files = fs . readdirSync ( assetCode . path ) ;
53
+ expect ( files ) . toContain ( 'index.py' ) ;
50
54
} ) ;
51
55
52
56
test ( 'Bundling a function with requirements.txt' , ( ) => {
53
57
const entry = path . join ( __dirname , 'lambda-handler' ) ;
54
- Bundling . bundle ( {
58
+ const assetCode = Bundling . bundle ( {
55
59
entry : entry ,
56
60
runtime : Runtime . PYTHON_3_7 ,
57
61
architecture : Architecture . X86_64 ,
@@ -62,10 +66,14 @@ test('Bundling a function with requirements.txt', () => {
62
66
bundling : expect . objectContaining ( {
63
67
command : [
64
68
'bash' , '-c' ,
65
- 'python -m pip install -r requirements.txt -t /asset-output && cp -R /asset-input/ /asset-output' ,
69
+ 'python -m pip install -r requirements.txt -t /asset-output && cp -rT /asset-input/ /asset-output' ,
66
70
] ,
67
71
} ) ,
68
72
} ) ) ;
73
+
74
+ const files = fs . readdirSync ( assetCode . path ) ;
75
+ expect ( files ) . toContain ( 'index.py' ) ;
76
+ expect ( files ) . toContain ( 'requirements.txt' ) ;
69
77
} ) ;
70
78
71
79
test ( 'Bundling Python 2.7 with requirements.txt installed' , ( ) => {
@@ -81,7 +89,7 @@ test('Bundling Python 2.7 with requirements.txt installed', () => {
81
89
bundling : expect . objectContaining ( {
82
90
command : [
83
91
'bash' , '-c' ,
84
- 'python -m pip install -r requirements.txt -t /asset-output && cp -R /asset-input/ /asset-output' ,
92
+ 'python -m pip install -r requirements.txt -t /asset-output && cp -rT /asset-input/ /asset-output' ,
85
93
] ,
86
94
} ) ,
87
95
} ) ) ;
@@ -101,7 +109,7 @@ test('Bundling a layer with dependencies', () => {
101
109
bundling : expect . objectContaining ( {
102
110
command : [
103
111
'bash' , '-c' ,
104
- 'python -m pip install -r requirements.txt -t /asset-output/python && cp -R /asset-input/ /asset-output/python' ,
112
+ 'python -m pip install -r requirements.txt -t /asset-output/python && cp -rT /asset-input/ /asset-output/python' ,
105
113
] ,
106
114
} ) ,
107
115
} ) ) ;
@@ -121,7 +129,7 @@ test('Bundling a python code layer', () => {
121
129
bundling : expect . objectContaining ( {
122
130
command : [
123
131
'bash' , '-c' ,
124
- 'cp -R /asset-input/ /asset-output/python' ,
132
+ 'cp -rT /asset-input/ /asset-output/python' ,
125
133
] ,
126
134
} ) ,
127
135
} ) ) ;
@@ -130,7 +138,7 @@ test('Bundling a python code layer', () => {
130
138
test ( 'Bundling a function with pipenv dependencies' , ( ) => {
131
139
const entry = path . join ( __dirname , 'lambda-handler-pipenv' ) ;
132
140
133
- Bundling . bundle ( {
141
+ const assetCode = Bundling . bundle ( {
134
142
entry : path . join ( entry , '.' ) ,
135
143
runtime : Runtime . PYTHON_3_9 ,
136
144
architecture : Architecture . X86_64 ,
@@ -141,16 +149,23 @@ test('Bundling a function with pipenv dependencies', () => {
141
149
bundling : expect . objectContaining ( {
142
150
command : [
143
151
'bash' , '-c' ,
144
- 'PIPENV_VENV_IN_PROJECT=1 pipenv lock -r > requirements.txt && rm -rf .venv && python -m pip install -r requirements.txt -t /asset-output/python && cp -R /asset-input/ /asset-output/python' ,
152
+ 'PIPENV_VENV_IN_PROJECT=1 pipenv lock -r > requirements.txt && rm -rf .venv && python -m pip install -r requirements.txt -t /asset-output/python && cp -rT /asset-input/ /asset-output/python' ,
145
153
] ,
146
154
} ) ,
147
155
} ) ) ;
156
+
157
+ const files = fs . readdirSync ( assetCode . path ) ;
158
+ expect ( files ) . toContain ( 'index.py' ) ;
159
+ expect ( files ) . toContain ( 'Pipfile' ) ;
160
+ expect ( files ) . toContain ( 'Pipfile.lock' ) ;
161
+ // Contains hidden files.
162
+ expect ( files ) . toContain ( '.gitignore' ) ;
148
163
} ) ;
149
164
150
165
test ( 'Bundling a function with poetry dependencies' , ( ) => {
151
166
const entry = path . join ( __dirname , 'lambda-handler-poetry' ) ;
152
167
153
- Bundling . bundle ( {
168
+ const assetCode = Bundling . bundle ( {
154
169
entry : path . join ( entry , '.' ) ,
155
170
runtime : Runtime . PYTHON_3_9 ,
156
171
architecture : Architecture . X86_64 ,
@@ -161,10 +176,17 @@ test('Bundling a function with poetry dependencies', () => {
161
176
bundling : expect . objectContaining ( {
162
177
command : [
163
178
'bash' , '-c' ,
164
- 'poetry export --with-credentials --format requirements.txt --output requirements.txt && python -m pip install -r requirements.txt -t /asset-output/python && cp -R /asset-input/ /asset-output/python' ,
179
+ 'poetry export --with-credentials --format requirements.txt --output requirements.txt && python -m pip install -r requirements.txt -t /asset-output/python && cp -rT /asset-input/ /asset-output/python' ,
165
180
] ,
166
181
} ) ,
167
182
} ) ) ;
183
+
184
+ const files = fs . readdirSync ( assetCode . path ) ;
185
+ expect ( files ) . toContain ( 'index.py' ) ;
186
+ expect ( files ) . toContain ( 'pyproject.toml' ) ;
187
+ expect ( files ) . toContain ( 'poetry.lock' ) ;
188
+ // Contains hidden files.
189
+ expect ( files ) . toContain ( '.gitignore' ) ;
168
190
} ) ;
169
191
170
192
test ( 'Bundling a function with custom bundling image' , ( ) => {
@@ -184,7 +206,7 @@ test('Bundling a function with custom bundling image', () => {
184
206
image,
185
207
command : [
186
208
'bash' , '-c' ,
187
- 'python -m pip install -r requirements.txt -t /asset-output/python && cp -R /asset-input/ /asset-output/python' ,
209
+ 'python -m pip install -r requirements.txt -t /asset-output/python && cp -rT /asset-input/ /asset-output/python' ,
188
210
] ,
189
211
} ) ,
190
212
} ) ) ;
0 commit comments