Skip to content

Tests reorg #164

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 13 commits into from
Apr 4, 2018
36 changes: 22 additions & 14 deletions circle.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,32 @@
version: 2
jobs:
build:
working_directory: /sls-py-req
docker:
- image: ubuntu:rolling
working_directory: ~/sls-py-req
machine:
image: circleci/classic
steps:
- checkout
- setup_remote_docker
# Apt deps
- run: apt -y update && apt -y install python3-pip python3.6 python-pip python2.7 curl unzip bats docker
# Build python3.6. gross. (based on my gist here: https://git.io/vxMFG )
- run: |
sudo apt-get update
sudo apt-get install build-essential tk-dev libncurses5-dev libncursesw5-dev libreadline6-dev libdb5.3-dev libgdbm-dev libsqlite3-dev libssl-dev libbz2-dev libexpat1-dev liblzma-dev zlib1g-dev
wget https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tar.xz
tar xf Python-3.6.5.tar.xz
cd Python-3.6.5
./configure
make
sudo make altinstall
# install bats
- run: |
git clone https://github.com/sstephenson/bats.git
cd bats
sudo ./install.sh /usr/local
# other deps
- run: sudo apt -y update && sudo apt -y install python-pip python2.7 curl unzip
# instal pipenv
- run: python3.6 -m pip install pipenv
- run: sudo python3.6 -m pip install pipenv
# install nodejs
- run: curl -sL https://deb.nodesource.com/setup_6.x | bash - && apt -y install nodejs
- run: curl -sL https://deb.nodesource.com/setup_6.x | sudo bash - && sudo apt -y install nodejs
# install serverless & depcheck
- run: npm install -g serverless depcheck
# install deps
Expand All @@ -23,9 +37,3 @@ jobs:
- run: npm run lint
# test!
- run: npm run test
# create a user
- run: useradd -m tester
# give this dir to the test user
- run: chown -R tester .
# test as user!
- run: su -c "npm run test" tester
64 changes: 44 additions & 20 deletions test.bats
Original file line number Diff line number Diff line change
Expand Up @@ -7,38 +7,41 @@ setup() {
export LC_ALL=C.UTF-8
export LANG=C.UTF-8
fi

cd test

npm i ..
}

teardown() {
sls requirements clean
rm -rf puck puck2 puck3 node_modules .serverless .requirements.zip .requirements-cache
if [ -f serverless.yml.bak ]; then mv serverless.yml.bak serverless.yml; fi
}

@test "py3.6 can package flask with default options" {
cd tests/base
npm i $(npm pack ../..)
sls package
unzip .serverless/sls-py-req-test.zip -d puck
ls puck/flask
}

@test "py3.6 can package flask with zip option" {
cd tests/base
npm i $(npm pack ../..)
sls --zip=true package
unzip .serverless/sls-py-req-test.zip -d puck
ls puck/.requirements.zip puck/unzip_requirements.py
! ls puck/flask
}

@test "py3.6 doesn't package boto3 by default" {
cd tests/base
npm i $(npm pack ../..)
sls package
unzip .serverless/sls-py-req-test.zip -d puck
! ls puck/boto3
}

@test "py3.6 doesn't package bottle with noDeploy option" {
cd tests/base
npm i $(npm pack ../..)
perl -p -i'.bak' -e 's/(pythonRequirements:$)/\1\n noDeploy: [bottle]/' serverless.yml
sls package
unzip .serverless/sls-py-req-test.zip -d puck
Expand All @@ -47,111 +50,128 @@ teardown() {
}

@test "py3.6 can package flask with zip & dockerizePip option" {
[ -z "$CIRCLE_BRANCH" ] || skip "Volumes are weird in CircleCI https://circleci.com/docs/2.0/building-docker-images/#mounting-folders"
cd tests/base
npm i $(npm pack ../..)
! uname -sm|grep Linux || groups|grep docker || id -u|egrep '^0$' || skip "can't dockerize on linux if not root & not in docker group"
sls --dockerizePip=true --zip=true package
unzip .serverless/sls-py-req-test.zip -d puck
ls puck/.requirements.zip puck/unzip_requirements.py
}

@test "py3.6 can package flask with dockerizePip option" {
[ -z "$CIRCLE_BRANCH" ] || skip "Volumes are weird in CircleCI https://circleci.com/docs/2.0/building-docker-images/#mounting-folders"
cd tests/base
npm i $(npm pack ../..)
! uname -sm|grep Linux || groups|grep docker || id -u|egrep '^0$' || skip "can't dockerize on linux if not root & not in docker group"
sls --dockerizePip=true package
unzip .serverless/sls-py-req-test.zip -d puck
ls puck/flask
}

@test "py3.6 uses cache with dockerizePip option" {
[ -z "$CIRCLE_BRANCH" ] || skip "Volumes are weird in CircleCI https://circleci.com/docs/2.0/building-docker-images/#mounting-folders"
cd tests/base
npm i $(npm pack ../..)
! 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 pipCmdExtraArgs: ["--cache-dir", ".requirements-cache"]/' serverless.yml
sls --dockerizePip=true package
ls .requirements-cache/http
}

@test "py2.7 can package flask with default options" {
cd tests/base
npm i $(npm pack ../..)
sls --runtime=python2.7 package
unzip .serverless/sls-py-req-test.zip -d puck
ls puck/flask
}

@test "py2.7 can package flask with zip option" {
cd tests/base
npm i $(npm pack ../..)
sls --runtime=python2.7 --zip=true package
unzip .serverless/sls-py-req-test.zip -d puck
ls puck/.requirements.zip puck/unzip_requirements.py
}

@test "py2.7 doesn't package boto3 by default" {
cd tests/base
npm i $(npm pack ../..)
sls package
unzip .serverless/sls-py-req-test.zip -d puck
! ls puck/boto3
}

@test "py2.7 doesn't package bottle with noDeploy option" {
cd tests/base
npm i $(npm pack ../..)
perl -p -i'.bak' -e 's/(pythonRequirements:$)/\1\n noDeploy: [bottle]/' serverless.yml
sls --runtime=python2.7 package
unzip .serverless/sls-py-req-test.zip -d puck
! ls puck/bottle.py
}

@test "py2.7 can package flask with zip & dockerizePip option" {
[ -z "$CIRCLE_BRANCH" ] || skip "Volumes are weird in CircleCI https://circleci.com/docs/2.0/building-docker-images/#mounting-folders"
cd tests/base
npm i $(npm pack ../..)
! uname -sm|grep Linux || groups|grep docker || id -u|egrep '^0$' || skip "can't dockerize on linux if not root & not in docker group"
sls --dockerizePip=true --runtime=python2.7 --zip=true package
unzip .serverless/sls-py-req-test.zip -d puck
ls puck/.requirements.zip puck/unzip_requirements.py
}

@test "py2.7 can package flask with dockerizePip option" {
[ -z "$CIRCLE_BRANCH" ] || skip "Volumes are weird in CircleCI https://circleci.com/docs/2.0/building-docker-images/#mounting-folders"
cd tests/base
npm i $(npm pack ../..)
! uname -sm|grep Linux || groups|grep docker || id -u|egrep '^0$' || skip "can't dockerize on linux if not root & not in docker group"
sls --dockerizePip=true --runtime=python2.7 package
unzip .serverless/sls-py-req-test.zip -d puck
ls puck/flask
}

@test "pipenv py3.6 can package flask with default options" {
cd ../pipenv-example
npm i ..
cd tests/pipenv
npm i $(npm pack ../..)
sls package
unzip .serverless/sls-py-req-test.zip -d puck
ls puck/flask
}

@test "pipenv py3.6 can package flask with zip option" {
cd ../pipenv-example
npm i ..
cd tests/pipenv
npm i $(npm pack ../..)
sls --zip=true package
unzip .serverless/sls-py-req-test.zip -d puck
ls puck/.requirements.zip puck/unzip_requirements.py
}

@test "pipenv py3.6 doesn't package boto3 by default" {
cd ../pipenv-example
npm i ..
cd tests/pipenv
npm i $(npm pack ../..)
sls package
unzip .serverless/sls-py-req-test.zip -d puck
! ls puck/boto3
}

@test "pipenv py3.6 doesn't package bottle with noDeploy option" {
cd ../pipenv-example
npm i ..
cd tests/pipenv
npm i $(npm pack ../..)
perl -p -i'.bak' -e 's/(pythonRequirements:$)/\1\n noDeploy: [bottle]/' serverless.yml
sls package
unzip .serverless/sls-py-req-test.zip -d puck
! ls puck/bottle.py
}

@test "py3.6 can package flask with zip option and no explicit include" {
cd tests/base
npm i $(npm pack ../..)
sed -i'.bak' -e 's/include://' -e 's/^.*handler.py//' serverless.yml
sls --zip=true package
unzip .serverless/sls-py-req-test.zip -d puck
ls puck/.requirements.zip puck/unzip_requirements.py
}

@test "py3.6 can package flask with package individually option" {
cd tests/base
npm i $(npm pack ../..)
sls --individually=true package
unzip .serverless/hello.zip -d puck
unzip .serverless/hello2.zip -d puck2
Expand All @@ -162,6 +182,8 @@ teardown() {
}

@test "py2.7 can package flask with package individually option" {
cd tests/base
npm i $(npm pack ../..)
sls --individually=true --runtime=python2.7 package
unzip .serverless/hello.zip -d puck
unzip .serverless/hello2.zip -d puck2
Expand All @@ -172,8 +194,8 @@ teardown() {
}

@test "py3.6 can package only requirements of module" {
cd ../test-indiv
npm i ..
cd tests/individually
npm i $(npm pack ../..)
sls package
unzip .serverless/module1.zip -d puck
unzip .serverless/module2.zip -d puck2
Expand All @@ -188,6 +210,8 @@ teardown() {
}

@test "py3.6 can package lambda-decorators using vendor option" {
cd tests/base
npm i $(npm pack ../..)
sls --vendor=./vendor package
unzip .serverless/sls-py-req-test.zip -d puck
ls puck/flask
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.