Skip to content

Commit e14aac9

Browse files
authored
Update tests (#239)
* Don't skip non-docker tests when docker isn't present * Don't hard code a static cache md5sum @AndrewFarley, I noticed that tests were failing on #238 and got the same errors locally on `master`. Do you think it's reasonable to compute the md5sum this way? I don't like hard coding the hash. But, I understand that this makes the test verify less of the process. Best would probably be to externally replicate what `genrerateRequirementsFile` does to create a new file and md5sum that instead of `.serverless/requirements.txt`
1 parent b32f55b commit e14aac9

File tree

5 files changed

+13
-18
lines changed

5 files changed

+13
-18
lines changed

lib/pip.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,8 @@ function generateRequirementsFile(source, target, options) {
289289
// If we have options (prefixed with --) keep them for later
290290
prepend.push(req);
291291
return false;
292+
} else if (req === '') {
293+
return false;
292294
}
293295
return !noDeploy.has(req.split(/[=<> \t]/)[0].trim());
294296
});
@@ -297,7 +299,7 @@ function generateRequirementsFile(source, target, options) {
297299
for (let item of prepend.reverse()) {
298300
filteredRequirements.unshift(item);
299301
}
300-
fse.writeFileSync(target, filteredRequirements.join('\n'));
302+
fse.writeFileSync(target, filteredRequirements.join('\n') + '\n');
301303
}
302304

303305
/**

test.bats

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ setup() {
1111
# Please note: If you update change the requirements.txt in test/base this value will
1212
# change. Run a test which uses this variable manually step by step and list the cache
1313
# folder to find the new hash if you do this
14-
export CACHE_FOLDER_HASH="b8b9d2be59f6f2ea5778e8b2aa4d2ddc_slspyc"
1514
if [ -d "${USR_CACHE_DIR}" ] ; then
1615
rm -Rf "${USR_CACHE_DIR}"
1716
fi
@@ -151,8 +150,6 @@ teardown() {
151150
@test "py3.6 uses download cache with useDownloadCache option" {
152151
cd tests/base
153152
npm i $(npm pack ../..)
154-
docker &> /dev/null || skip "docker not present"
155-
! uname -sm|grep Linux || groups|grep docker || id -u|egrep '^0$' || skip "can't dockerize on linux if not root & not in docker group"
156153
perl -p -i'.bak' -e 's/(pythonRequirements:$)/\1\n useDownloadCache: true/' serverless.yml
157154
sls package
158155
USR_CACHE_DIR=`node -e 'console.log(require("../../lib/shared").getUserCachePath())'`
@@ -162,8 +159,6 @@ teardown() {
162159
@test "py3.6 uses download cache with cacheLocation option" {
163160
cd tests/base
164161
npm i $(npm pack ../..)
165-
docker &> /dev/null || skip "docker not present"
166-
! uname -sm|grep Linux || groups|grep docker || id -u|egrep '^0$' || skip "can't dockerize on linux if not root & not in docker group"
167162
perl -p -i'.bak' -e 's/(pythonRequirements:$)/\1\n useDownloadCache: true\n cacheLocation: .requirements-cache/' serverless.yml
168163
sls package
169164
ls .requirements-cache/downloadCacheslspyc/http
@@ -193,11 +188,10 @@ teardown() {
193188
@test "py3.6 uses static and download cache" {
194189
cd tests/base
195190
npm i $(npm pack ../..)
196-
docker &> /dev/null || skip "docker not present"
197-
! uname -sm|grep Linux || groups|grep docker || id -u|egrep '^0$' || skip "can't dockerize on linux if not root & not in docker group"
198191
perl -p -i'.bak' -e 's/(pythonRequirements:$)/\1\n useDownloadCache: true\n useStaticCache: true/' serverless.yml
199192
sls package
200-
USR_CACHE_DIR=`node -e 'console.log(require("../../lib/shared").getUserCachePath())'`
193+
USR_CACHE_DIR=`node -e 'console.log(require("./node_modules/serverless-python-requirements/lib/shared").getUserCachePath())'`
194+
CACHE_FOLDER_HASH=$(md5sum <(grep -v boto3 requirements.txt|sort) | cut -d' ' -f1)_slspyc
201195
ls $USR_CACHE_DIR/$CACHE_FOLDER_HASH/flask
202196
ls $USR_CACHE_DIR/downloadCacheslspyc/http
203197
}
@@ -210,43 +204,41 @@ teardown() {
210204
perl -p -i'.bak' -e 's/(pythonRequirements:$)/\1\n useDownloadCache: true\n useStaticCache: true/' serverless.yml
211205
sls --dockerizePip=true package
212206
USR_CACHE_DIR=`node -e 'console.log(require("../../lib/shared").getUserCachePath())'`
207+
CACHE_FOLDER_HASH=$(md5sum <(grep -v boto3 requirements.txt|sort) | cut -d' ' -f1)_slspyc
213208
ls $USR_CACHE_DIR/$CACHE_FOLDER_HASH/flask
214209
ls $USR_CACHE_DIR/downloadCacheslspyc/http
215210
}
216211

217212
@test "py3.6 uses static cache" {
218213
cd tests/base
219214
npm i $(npm pack ../..)
220-
docker &> /dev/null || skip "docker not present"
221-
! uname -sm|grep Linux || groups|grep docker || id -u|egrep '^0$' || skip "can't dockerize on linux if not root & not in docker group"
222215
perl -p -i'.bak' -e 's/(pythonRequirements:$)/\1\n useStaticCache: true/' serverless.yml
223216
sls package
224217
USR_CACHE_DIR=`node -e 'console.log(require("../../lib/shared").getUserCachePath())'`
218+
CACHE_FOLDER_HASH=$(md5sum <(grep -v boto3 requirements.txt|sort) | cut -d' ' -f1)_slspyc
225219
ls $USR_CACHE_DIR/$CACHE_FOLDER_HASH/flask
226220
ls $USR_CACHE_DIR/$CACHE_FOLDER_HASH/.completed_requirements
227221
}
228222

229223
@test "py3.6 uses static cache with cacheLocation option" {
230224
cd tests/base
231225
npm i $(npm pack ../..)
232-
docker &> /dev/null || skip "docker not present"
233-
! uname -sm|grep Linux || groups|grep docker || id -u|egrep '^0$' || skip "can't dockerize on linux if not root & not in docker group"
234226
perl -p -i'.bak' -e 's/(pythonRequirements:$)/\1\n useStaticCache: true\n cacheLocation: .requirements-cache/' serverless.yml
235227
sls package
236228
USR_CACHE_DIR=`node -e 'console.log(require("../../lib/shared").getUserCachePath())'`
229+
CACHE_FOLDER_HASH=$(md5sum <(grep -v boto3 requirements.txt|sort) | cut -d' ' -f1)_slspyc
237230
ls .requirements-cache/$CACHE_FOLDER_HASH/flask
238231
ls .requirements-cache/$CACHE_FOLDER_HASH/.completed_requirements
239232
}
240233

241234
@test "py3.6 checking that static cache actually pulls from cache (by poisoning it)" {
242235
cd tests/base
243236
npm i $(npm pack ../..)
244-
docker &> /dev/null || skip "docker not present"
245-
! uname -sm|grep Linux || groups|grep docker || id -u|egrep '^0$' || skip "can't dockerize on linux if not root & not in docker group"
246237
perl -p -i'.bak' -e 's/(pythonRequirements:$)/\1\n useStaticCache: true/' serverless.yml
247238
sls package
248239
cp .serverless/sls-py-req-test.zip ./puck
249240
USR_CACHE_DIR=`node -e 'console.log(require("../../lib/shared").getUserCachePath())'`
241+
CACHE_FOLDER_HASH=$(md5sum <(grep -v boto3 requirements.txt|sort) | cut -d' ' -f1)_slspyc
250242
echo "injected new file into static cache folder" > $USR_CACHE_DIR/$CACHE_FOLDER_HASH/injected_file_is_bad_form
251243
sls package
252244
[ `wc -c ./.serverless/sls-py-req-test.zip | awk '{ print $1 }'` -gt `wc -c ./puck | awk '{ print $1 }'` ]
@@ -259,6 +251,7 @@ teardown() {
259251
! uname -sm|grep Linux || groups|grep docker || id -u|egrep '^0$' || skip "can't dockerize on linux if not root & not in docker group"
260252
perl -p -i'.bak' -e 's/(pythonRequirements:$)/\1\n useStaticCache: true/' serverless.yml
261253
sls --dockerizePip=true --slim=true package
254+
CACHE_FOLDER_HASH=$(md5sum <(grep -v boto3 requirements.txt|sort) | cut -d' ' -f1)_slspyc
262255
ls $USR_CACHE_DIR/$CACHE_FOLDER_HASH/flask
263256
unzip .serverless/sls-py-req-test.zip -d puck
264257
test $(find puck -name "*.pyc" | wc -l) -eq 0

tests/base/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99
"author": "",
1010
"license": "ISC",
1111
"dependencies": {
12-
"serverless-python-requirements": "file:serverless-python-requirements-4.1.1.tgz"
12+
"serverless-python-requirements": "file:serverless-python-requirements-4.2.1.tgz"
1313
}
1414
}

tests/individually/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99
"author": "",
1010
"license": "ISC",
1111
"dependencies": {
12-
"serverless-python-requirements": "file:serverless-python-requirements-4.1.1.tgz"
12+
"serverless-python-requirements": "file:serverless-python-requirements-4.2.1.tgz"
1313
}
1414
}

tests/pipenv/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99
"author": "",
1010
"license": "ISC",
1111
"dependencies": {
12-
"serverless-python-requirements": "file:serverless-python-requirements-4.1.1.tgz"
12+
"serverless-python-requirements": "file:serverless-python-requirements-4.2.1.tgz"
1313
}
1414
}

0 commit comments

Comments
 (0)