Skip to content

Commit 0718914

Browse files
author
bweigel
committed
adds tests to check for flaky packaging
1 parent a236f66 commit 0718914

File tree

4 files changed

+80
-13
lines changed

4 files changed

+80
-13
lines changed

test.js

+70-11
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ const listRequirementsZipFiles = filename => {
8686
const zip = deasync(new JSZip().loadAsync(readFileSync(filename)));
8787
const reqsBuffer = deasync(zip.file('.requirements.zip').async('nodebuffer'));
8888
const reqsZip = deasync(new JSZip().loadAsync(reqsBuffer));
89-
return Object.keys(reqsZip.files)
89+
return Object.keys(reqsZip.files);
9090
};
9191

9292
test('default pythonBin can package flask with default options', t => {
@@ -142,20 +142,65 @@ test('py3.6 can package flask with slim option', t => {
142142
t.end();
143143
});
144144

145-
146145
test('can package individually without moving modules to root of zip-File', t => {
147146
process.chdir('tests/base');
148147
const path = npm(['pack', '../..']);
149148
npm(['i', path]);
150149
sls(['--individually=true', '--moveup=false', 'package']);
151-
const zipfiles = listZipFiles(
152-
'.serverless/fn2-sls-py-req-test-dev-hello4.zip'
150+
151+
152+
const zipfiles_hello = listZipFiles(
153+
'.serverless/hello.zip'
154+
);
155+
t.false(
156+
zipfiles_hello.includes(`fn2${sep}__init__.py`),
157+
'fn2 is not packaged in function hello'
153158
);
154159
t.true(
155-
zipfiles.includes(`fn2${sep}__init__.py`),
156-
'fn2 is packaged as module'
160+
zipfiles_hello.includes('handler.py'),
161+
'handler.py is packaged in function hello'
157162
);
158-
t.true(zipfiles.includes(`flask${sep}__init__.py`), 'flask is packaged');
163+
t.false(
164+
zipfiles_hello.includes(`dataclasses${sep}__init__.py`),
165+
'dataclasses is not packaged in function hello'
166+
);
167+
t.true(
168+
zipfiles_hello.includes(`flask${sep}__init__.py`),
169+
'flask is packaged in function hello'
170+
);
171+
172+
const zipfiles_hello4 = listZipFiles(
173+
'.serverless/hello4.zip'
174+
);
175+
t.true(
176+
zipfiles_hello4.includes(`fn2${sep}__init__.py`),
177+
'fn2 is packaged as module in function hello4'
178+
);
179+
t.true(
180+
zipfiles_hello4.includes(`dataclasses${sep}__init__.py`),
181+
'dataclasses is packaged in function hello4'
182+
);
183+
t.false(
184+
zipfiles_hello4.includes(`flask${sep}__init__.py`),
185+
'flask is not packaged in function hello4'
186+
);
187+
188+
const zipfiles_hello5 = listZipFiles(
189+
'.serverless/hello5.zip'
190+
);
191+
t.true(
192+
zipfiles_hello5.includes(`fn2${sep}__init__.py`),
193+
'fn2 is packaged as module in function hello5'
194+
);
195+
t.true(
196+
zipfiles_hello5.includes(`dataclasses${sep}__init__.py`),
197+
'dataclasses is packaged in function hello5'
198+
);
199+
t.false(
200+
zipfiles_hello5.includes(`flask${sep}__init__.py`),
201+
'flask is not packaged in function hello5'
202+
);
203+
159204
t.end();
160205
});
161206

@@ -167,10 +212,18 @@ test("py3.6 doesn't package bottle with zip option", t => {
167212
process.chdir('tests/base');
168213
const path = npm(['pack', '../..']);
169214
npm(['i', path]);
170-
perl(['-p', "-i'.bak'", '-e', 's/(pythonRequirements:$)/\\1\\n noDeploy: [bottle]/', 'serverless.yml'])
215+
perl([
216+
'-p',
217+
"-i'.bak'",
218+
'-e',
219+
's/(pythonRequirements:$)/\\1\\n noDeploy: [bottle]/',
220+
'serverless.yml'
221+
]);
171222
sls([`--pythonBin=${getPythonBin(3)}`, '--zip=true', 'package']);
172223
const zipfiles = listZipFiles('.serverless/sls-py-req-test.zip');
173-
const zippedReqs = listRequirementsZipFiles('.serverless/sls-py-req-test.zip');
224+
const zippedReqs = listRequirementsZipFiles(
225+
'.serverless/sls-py-req-test.zip'
226+
);
174227
t.true(
175228
zipfiles.includes('.requirements.zip'),
176229
'zipped requirements are packaged'
@@ -180,7 +233,13 @@ test("py3.6 doesn't package bottle with zip option", t => {
180233
zipfiles.includes(`flask${sep}__init__.py`),
181234
"flask isn't packaged on its own"
182235
);
183-
t.true(zippedReqs.includes(`flask/__init__.py`), 'flask is packaged in the .requirements.zip file');
184-
t.false(zippedReqs.includes(`bottle.py`), 'bottle is not packaged in the .requirements.zip file');
236+
t.true(
237+
zippedReqs.includes(`flask/__init__.py`),
238+
'flask is packaged in the .requirements.zip file'
239+
);
240+
t.false(
241+
zippedReqs.includes(`bottle.py`),
242+
'bottle is not packaged in the .requirements.zip file'
243+
);
185244
t.end();
186245
});

tests/base/common/__init__.py

Whitespace-only changes.

tests/base/fn2/requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dataclasses

tests/base/serverless.yml

+9-2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ package:
3333
functions:
3434
hello:
3535
handler: handler.hello
36-
hello2:
37-
handler: handler.hello
3836
hello3:
3937
handler: handler.hello
4038
runtime: nodejs6.10
@@ -44,3 +42,12 @@ functions:
4442
package:
4543
include:
4644
- 'fn2/**'
45+
hello2:
46+
handler: handler.hello
47+
hello5:
48+
handler: fn2.handler.hello2
49+
module: fn2
50+
package:
51+
include:
52+
- 'fn2/**'
53+
- 'common/__init__.py'

0 commit comments

Comments
 (0)