Skip to content

Commit fcbf517

Browse files
author
bweigel
committed
add testable vendor option- ref serverless#209
1 parent 927b7cb commit fcbf517

File tree

4 files changed

+166
-0
lines changed

4 files changed

+166
-0
lines changed

test.js

+158
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,99 @@ const canUseDocker = () => {
120120
return result.status === 0;
121121
};
122122

123+
test('py3.6 can package different vendor libraries for each module', t => {
124+
process.chdir('tests/individually');
125+
const path = npm(['pack', '../..']);
126+
npm(['i', path]);
127+
sls(['--vendor-hello1=lib_a', '--vendor-hello2=lib_b', 'package']);
128+
129+
const zipfiles_hello = listZipFiles(
130+
'.serverless/module1-sls-py-req-test-indiv-dev-hello1.zip'
131+
);
132+
t.true(
133+
zipfiles_hello.includes('handler1.py'),
134+
'handler1.py is packaged at root level in function hello1'
135+
);
136+
t.false(
137+
zipfiles_hello.includes('handler2.py'),
138+
'handler2.py is NOT packaged at root level in function hello1'
139+
);
140+
t.true(
141+
zipfiles_hello.includes(`pyaml${sep}__init__.py`),
142+
'pyaml is packaged in function hello1'
143+
);
144+
t.false(
145+
zipfiles_hello.includes(`flask${sep}__init__.py`),
146+
'flask is NOT packaged in function hello1'
147+
);
148+
t.true(
149+
zipfiles_hello.includes(`vendor_library_a.py`),
150+
'vendor library lib_a is packaged in function hello1'
151+
);
152+
t.false(
153+
zipfiles_hello.includes(`vendor_library_b.py`),
154+
'vendor library lib_b is NOT packaged in function hello1'
155+
);
156+
157+
const zipfiles_hello2 = listZipFiles(
158+
'.serverless/module2-sls-py-req-test-indiv-dev-hello2.zip'
159+
);
160+
t.true(
161+
zipfiles_hello2.includes('handler2.py'),
162+
'handler2.py is packaged at root level in function hello2'
163+
);
164+
t.false(
165+
zipfiles_hello2.includes('handler1.py'),
166+
'handler1.py is NOT packaged at root level in function hello2'
167+
);
168+
t.false(
169+
zipfiles_hello2.includes(`pyaml${sep}__init__.py`),
170+
'pyaml is NOT packaged in function hello2'
171+
);
172+
t.true(
173+
zipfiles_hello2.includes(`flask${sep}__init__.py`),
174+
'flask is packaged in function hello2'
175+
);
176+
t.false(
177+
zipfiles_hello2.includes(`vendor_library_a.py`),
178+
'vendor library lib_a is NOT packaged in function hello2'
179+
);
180+
t.true(
181+
zipfiles_hello2.includes(`vendor_library_b.py`),
182+
'vendor library lib_b is packaged in function hello2'
183+
);
184+
185+
const zipfiles_hello3 = listZipFiles(
186+
'.serverless/module2-sls-py-req-test-indiv-dev-hello3.zip'
187+
);
188+
t.true(
189+
zipfiles_hello3.includes('handler2.py'),
190+
'handler2.py is packaged at root level in function hello3'
191+
);
192+
t.false(
193+
zipfiles_hello3.includes('handler1.py'),
194+
'handler1.py is NOT packaged at root level in function hello3'
195+
);
196+
t.false(
197+
zipfiles_hello3.includes(`pyaml${sep}__init__.py`),
198+
'pyaml is NOT packaged in function hello3'
199+
);
200+
t.true(
201+
zipfiles_hello3.includes(`flask${sep}__init__.py`),
202+
'flask is packaged in function hello3'
203+
);
204+
t.false(
205+
zipfiles_hello3.includes(`vendor_library_a.py`),
206+
'vendor library lib_a is packaged in function hello3'
207+
);
208+
t.true(
209+
zipfiles_hello3.includes(`vendor_library_b.py`),
210+
'vendor library lib_b is NOT packaged in function hello3'
211+
);
212+
213+
t.end();
214+
});
215+
123216
test('default pythonBin can package flask with default options', t => {
124217
process.chdir('tests/base');
125218
const path = npm(['pack', '../..']);
@@ -1654,6 +1747,71 @@ test('py3.6 can package only requirements of module', t => {
16541747
t.end();
16551748
});
16561749

1750+
test('py3.6 can package different vendor libraries for each module', t => {
1751+
process.chdir('tests/individually');
1752+
const path = npm(['pack', '../..']);
1753+
npm(['i', path]);
1754+
sls(['--vendor-hello1=lib_a', '--vendor-hello2=lib_b', 'package']);
1755+
1756+
const zipfiles_hello = listZipFiles(
1757+
'.serverless/module1-sls-py-req-test-indiv-dev-hello1.zip'
1758+
);
1759+
t.true(
1760+
zipfiles_hello.includes('handler1.py'),
1761+
'handler1.py is packaged at root level in function hello1'
1762+
);
1763+
t.false(
1764+
zipfiles_hello.includes('handler2.py'),
1765+
'handler2.py is NOT packaged at root level in function hello1'
1766+
);
1767+
t.true(
1768+
zipfiles_hello.includes(`pyaml${sep}__init__.py`),
1769+
'pyaml is packaged in function hello1'
1770+
);
1771+
t.false(
1772+
zipfiles_hello.includes(`flask${sep}__init__.py`),
1773+
'flask is NOT packaged in function hello1'
1774+
);
1775+
t.true(
1776+
zipfiles_hello.includes(`vendor_library_a.py`),
1777+
'vendor library lib_a is packaged in function hello1'
1778+
);
1779+
t.false(
1780+
zipfiles_hello.includes(`vendor_library_b.py`),
1781+
'vendor library lib_b is NOT packaged in function hello1'
1782+
);
1783+
1784+
const zipfiles_hello2 = listZipFiles(
1785+
'.serverless/module2-sls-py-req-test-indiv-dev-hello2.zip'
1786+
);
1787+
t.true(
1788+
zipfiles_hello2.includes('handler2.py'),
1789+
'handler2.py is packaged at root level in function hello2'
1790+
);
1791+
t.false(
1792+
zipfiles_hello2.includes('handler1.py'),
1793+
'handler1.py is NOT packaged at root level in function hello2'
1794+
);
1795+
t.false(
1796+
zipfiles_hello2.includes(`pyaml${sep}__init__.py`),
1797+
'pyaml is NOT packaged in function hello2'
1798+
);
1799+
t.true(
1800+
zipfiles_hello2.includes(`flask${sep}__init__.py`),
1801+
'flask is packaged in function hello2'
1802+
);
1803+
t.false(
1804+
zipfiles_hello2.includes(`vendor_library_a.py`),
1805+
'vendor library lib_a is NOT packaged in function hello1'
1806+
);
1807+
t.true(
1808+
zipfiles_hello2.includes(`vendor_library_b.py`),
1809+
'vendor library lib_b is packaged in function hello1'
1810+
);
1811+
1812+
t.end();
1813+
});
1814+
16571815
test('py3.6 can package lambda-decorators using vendor and invidiually option', t => {
16581816
process.chdir('tests/base');
16591817
const path = npm(['pack', '../..']);

tests/individually/lib_a/vendor_library_a.py

Whitespace-only changes.

tests/individually/lib_b/vendor_library_b.py

Whitespace-only changes.

tests/individually/serverless.yml

+8
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,17 @@ functions:
1717
hello1:
1818
handler: handler1.hello
1919
module: module1
20+
vendor: ${opt:vendor-hello1, ''}
21+
2022
hello2:
2123
handler: handler2.hello
2224
module: module2
25+
vendor: ${opt:vendor-hello2, ''}
26+
27+
hello3:
28+
handler: handler2.hello
29+
module: module2
30+
vendor: ${opt:vendor-hello1, ''}
2331

2432
plugins:
2533
- serverless-python-requirements

0 commit comments

Comments
 (0)