Skip to content

Commit 319fcf4

Browse files
committed
test: add test for injection path with scaleway provider
1 parent c64c04e commit 319fcf4

File tree

6 files changed

+94
-24
lines changed

6 files changed

+94
-24
lines changed

test.js

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -22,30 +22,30 @@ const initialWorkingDir = process.cwd();
2222

2323
const mkCommand =
2424
(cmd) =>
25-
(args, options = {}) => {
26-
options['env'] = Object.assign(
27-
{ SLS_DEBUG: 'true' },
28-
process.env,
29-
options['env']
30-
);
31-
const { error, stdout, stderr, status } = crossSpawn.sync(
32-
cmd,
33-
args,
34-
options
35-
);
36-
if (error && !options['noThrow']) {
37-
console.error(`Error running: ${quote([cmd, ...args])}`); // eslint-disable-line no-console
38-
throw error;
39-
}
40-
if (status && !options['noThrow']) {
41-
console.error('STDOUT: ', stdout.toString()); // eslint-disable-line no-console
42-
console.error('STDERR: ', stderr.toString()); // eslint-disable-line no-console
43-
throw new Error(
44-
`${quote([cmd, ...args])} failed with status code ${status}`
25+
(args, options = {}) => {
26+
options['env'] = Object.assign(
27+
{ SLS_DEBUG: 'true' },
28+
process.env,
29+
options['env']
4530
);
46-
}
47-
return stdout && stdout.toString().trim();
48-
};
31+
const { error, stdout, stderr, status } = crossSpawn.sync(
32+
cmd,
33+
args,
34+
options
35+
);
36+
if (error && !options['noThrow']) {
37+
console.error(`Error running: ${quote([cmd, ...args])}`); // eslint-disable-line no-console
38+
throw error;
39+
}
40+
if (status && !options['noThrow']) {
41+
console.error('STDOUT: ', stdout.toString()); // eslint-disable-line no-console
42+
console.error('STDERR: ', stderr.toString()); // eslint-disable-line no-console
43+
throw new Error(
44+
`${quote([cmd, ...args])} failed with status code ${status}`
45+
);
46+
}
47+
return stdout && stdout.toString().trim();
48+
};
4949

5050
const sls = mkCommand('sls');
5151
const git = mkCommand('git');
@@ -421,7 +421,7 @@ test(
421421
);
422422
t.true(
423423
zipfiles.filter((filename) => filename.endsWith('__main__.py')).length >
424-
0,
424+
0,
425425
'__main__.py files are packaged'
426426
);
427427
t.end();
@@ -1654,3 +1654,14 @@ test('poetry py3.7 fails packaging if poetry.lock is missing and flag requirePoe
16541654
);
16551655
t.end();
16561656
});
1657+
1658+
test('py3.7 injects dependencies into `package` folder when using scaleway provider', async (t) => {
1659+
process.chdir('tests/scaleway_provider');
1660+
const path = npm(['pack', '../..']);
1661+
npm(['i', path]);
1662+
sls(['package'], { env: {} });
1663+
const zipfiles = await listZipFiles('.serverless/sls-py-req-test.zip');
1664+
t.true(zipfiles.includes(`package${sep}flask${sep}__init__.py`), 'flask is packaged');
1665+
t.true(zipfiles.includes(`package${sep}boto3${sep}__init__.py`), 'boto3 is packaged');
1666+
t.end();
1667+
});
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
slimPatterns:
2+
- '**/__main__.py'

tests/scaleway_provider/handler.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import requests
2+
3+
4+
def hello(event, context):
5+
return requests.get('https://httpbin.org/get').json()

tests/scaleway_provider/package.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "example",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"author": "",
10+
"license": "ISC",
11+
"dependencies": {
12+
"serverless-python-requirements": "file:serverless-python-requirements-5.3.1.tgz",
13+
"serverless-scaleway-functions": "^0.4.5"
14+
}
15+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
flask==0.12.5
2+
bottle
3+
boto3
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
service: sls-py-req-test
2+
3+
configValidationMode: off
4+
5+
provider:
6+
name: scaleway
7+
runtime: python37
8+
9+
plugins:
10+
- serverless-python-requirements
11+
- serverless-scaleway-functions
12+
13+
custom:
14+
pythonRequirements:
15+
zip: ${env:zip, self:custom.defaults.zip}
16+
slim: ${env:slim, self:custom.defaults.slim}
17+
slimPatterns: ${file(./slimPatterns.yml):slimPatterns, self:custom.defaults.slimPatterns}
18+
slimPatternsAppendDefaults: ${env:slimPatternsAppendDefaults, self:custom.defaults.slimPatternsAppendDefaults}
19+
dockerizePip: ${env:dockerizePip, self:custom.defaults.dockerizePip}
20+
defaults:
21+
zip: false
22+
slimPatterns: false
23+
slimPatternsAppendDefaults: true
24+
slim: false
25+
dockerizePip: false
26+
27+
package:
28+
patterns:
29+
- '!**/*'
30+
- 'handler.py'
31+
32+
functions:
33+
hello:
34+
handler: handler.hello

0 commit comments

Comments
 (0)