Skip to content

Update tests #239

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/pip.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,8 @@ function generateRequirementsFile(source, target, options) {
// If we have options (prefixed with --) keep them for later
prepend.push(req);
return false;
} else if (req === '') {
return false;
}
return !noDeploy.has(req.split(/[=<> \t]/)[0].trim());
});
Expand All @@ -297,7 +299,7 @@ function generateRequirementsFile(source, target, options) {
for (let item of prepend.reverse()) {
filteredRequirements.unshift(item);
}
fse.writeFileSync(target, filteredRequirements.join('\n'));
fse.writeFileSync(target, filteredRequirements.join('\n') + '\n');
}

/**
Expand Down
21 changes: 7 additions & 14 deletions test.bats
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ setup() {
# Please note: If you update change the requirements.txt in test/base this value will
# change. Run a test which uses this variable manually step by step and list the cache
# folder to find the new hash if you do this
export CACHE_FOLDER_HASH="b8b9d2be59f6f2ea5778e8b2aa4d2ddc_slspyc"
if [ -d "${USR_CACHE_DIR}" ] ; then
rm -Rf "${USR_CACHE_DIR}"
fi
Expand Down Expand Up @@ -151,8 +150,6 @@ teardown() {
@test "py3.6 uses download cache with useDownloadCache option" {
cd tests/base
npm i $(npm pack ../..)
docker &> /dev/null || skip "docker not present"
! uname -sm|grep Linux || groups|grep docker || id -u|egrep '^0$' || skip "can't dockerize on linux if not root & not in docker group"
perl -p -i'.bak' -e 's/(pythonRequirements:$)/\1\n useDownloadCache: true/' serverless.yml
sls package
USR_CACHE_DIR=`node -e 'console.log(require("../../lib/shared").getUserCachePath())'`
Expand All @@ -162,8 +159,6 @@ teardown() {
@test "py3.6 uses download cache with cacheLocation option" {
cd tests/base
npm i $(npm pack ../..)
docker &> /dev/null || skip "docker not present"
! uname -sm|grep Linux || groups|grep docker || id -u|egrep '^0$' || skip "can't dockerize on linux if not root & not in docker group"
perl -p -i'.bak' -e 's/(pythonRequirements:$)/\1\n useDownloadCache: true\n cacheLocation: .requirements-cache/' serverless.yml
sls package
ls .requirements-cache/downloadCacheslspyc/http
Expand Down Expand Up @@ -193,11 +188,10 @@ teardown() {
@test "py3.6 uses static and download cache" {
cd tests/base
npm i $(npm pack ../..)
docker &> /dev/null || skip "docker not present"
! uname -sm|grep Linux || groups|grep docker || id -u|egrep '^0$' || skip "can't dockerize on linux if not root & not in docker group"
perl -p -i'.bak' -e 's/(pythonRequirements:$)/\1\n useDownloadCache: true\n useStaticCache: true/' serverless.yml
sls package
USR_CACHE_DIR=`node -e 'console.log(require("../../lib/shared").getUserCachePath())'`
USR_CACHE_DIR=`node -e 'console.log(require("./node_modules/serverless-python-requirements/lib/shared").getUserCachePath())'`
CACHE_FOLDER_HASH=$(md5sum <(grep -v boto3 requirements.txt|sort) | cut -d' ' -f1)_slspyc
ls $USR_CACHE_DIR/$CACHE_FOLDER_HASH/flask
ls $USR_CACHE_DIR/downloadCacheslspyc/http
}
Expand All @@ -210,43 +204,41 @@ teardown() {
perl -p -i'.bak' -e 's/(pythonRequirements:$)/\1\n useDownloadCache: true\n useStaticCache: true/' serverless.yml
sls --dockerizePip=true package
USR_CACHE_DIR=`node -e 'console.log(require("../../lib/shared").getUserCachePath())'`
CACHE_FOLDER_HASH=$(md5sum <(grep -v boto3 requirements.txt|sort) | cut -d' ' -f1)_slspyc
ls $USR_CACHE_DIR/$CACHE_FOLDER_HASH/flask
ls $USR_CACHE_DIR/downloadCacheslspyc/http
}

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

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

@test "py3.6 checking that static cache actually pulls from cache (by poisoning it)" {
cd tests/base
npm i $(npm pack ../..)
docker &> /dev/null || skip "docker not present"
! uname -sm|grep Linux || groups|grep docker || id -u|egrep '^0$' || skip "can't dockerize on linux if not root & not in docker group"
perl -p -i'.bak' -e 's/(pythonRequirements:$)/\1\n useStaticCache: true/' serverless.yml
sls package
cp .serverless/sls-py-req-test.zip ./puck
USR_CACHE_DIR=`node -e 'console.log(require("../../lib/shared").getUserCachePath())'`
CACHE_FOLDER_HASH=$(md5sum <(grep -v boto3 requirements.txt|sort) | cut -d' ' -f1)_slspyc
echo "injected new file into static cache folder" > $USR_CACHE_DIR/$CACHE_FOLDER_HASH/injected_file_is_bad_form
sls package
[ `wc -c ./.serverless/sls-py-req-test.zip | awk '{ print $1 }'` -gt `wc -c ./puck | awk '{ print $1 }'` ]
Expand All @@ -259,6 +251,7 @@ teardown() {
! uname -sm|grep Linux || groups|grep docker || id -u|egrep '^0$' || skip "can't dockerize on linux if not root & not in docker group"
perl -p -i'.bak' -e 's/(pythonRequirements:$)/\1\n useStaticCache: true/' serverless.yml
sls --dockerizePip=true --slim=true package
CACHE_FOLDER_HASH=$(md5sum <(grep -v boto3 requirements.txt|sort) | cut -d' ' -f1)_slspyc
ls $USR_CACHE_DIR/$CACHE_FOLDER_HASH/flask
unzip .serverless/sls-py-req-test.zip -d puck
test $(find puck -name "*.pyc" | wc -l) -eq 0
Expand Down
2 changes: 1 addition & 1 deletion tests/base/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
"author": "",
"license": "ISC",
"dependencies": {
"serverless-python-requirements": "file:serverless-python-requirements-4.1.1.tgz"
"serverless-python-requirements": "file:serverless-python-requirements-4.2.1.tgz"
}
}
2 changes: 1 addition & 1 deletion tests/individually/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
"author": "",
"license": "ISC",
"dependencies": {
"serverless-python-requirements": "file:serverless-python-requirements-4.1.1.tgz"
"serverless-python-requirements": "file:serverless-python-requirements-4.2.1.tgz"
}
}
2 changes: 1 addition & 1 deletion tests/pipenv/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
"author": "",
"license": "ISC",
"dependencies": {
"serverless-python-requirements": "file:serverless-python-requirements-4.1.1.tgz"
"serverless-python-requirements": "file:serverless-python-requirements-4.2.1.tgz"
}
}