diff --git a/circle.yml b/circle.yml index c899a0e8..cef66fcb 100644 --- a/circle.yml +++ b/circle.yml @@ -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 @@ -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 diff --git a/test.bats b/test.bats index a7668d15..adb24e73 100755 --- a/test.bats +++ b/test.bats @@ -7,25 +7,24 @@ 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 @@ -33,12 +32,16 @@ teardown() { } @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 @@ -47,7 +50,8 @@ 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 @@ -55,7 +59,8 @@ teardown() { } @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 @@ -63,7 +68,8 @@ teardown() { } @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 @@ -71,24 +77,32 @@ teardown() { } @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 @@ -96,7 +110,8 @@ teardown() { } @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 @@ -104,7 +119,8 @@ teardown() { } @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 @@ -112,32 +128,32 @@ teardown() { } @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 @@ -145,6 +161,8 @@ teardown() { } @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 @@ -152,6 +170,8 @@ teardown() { } @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 @@ -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 @@ -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 @@ -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 diff --git a/test/.gitignore b/tests/base/.gitignore similarity index 100% rename from test/.gitignore rename to tests/base/.gitignore diff --git a/pipenv-example/handler.py b/tests/base/handler.py similarity index 100% rename from pipenv-example/handler.py rename to tests/base/handler.py diff --git a/pipenv-example/package.json b/tests/base/package.json similarity index 100% rename from pipenv-example/package.json rename to tests/base/package.json diff --git a/test/requirements.txt b/tests/base/requirements.txt similarity index 100% rename from test/requirements.txt rename to tests/base/requirements.txt diff --git a/test/serverless.yml b/tests/base/serverless.yml similarity index 100% rename from test/serverless.yml rename to tests/base/serverless.yml diff --git a/test/vendor/lambda_decorators.py b/tests/base/vendor/lambda_decorators.py similarity index 100% rename from test/vendor/lambda_decorators.py rename to tests/base/vendor/lambda_decorators.py diff --git a/test-indiv/module1/handler1.py b/tests/individually/module1/handler1.py similarity index 100% rename from test-indiv/module1/handler1.py rename to tests/individually/module1/handler1.py diff --git a/test-indiv/module1/requirements.txt b/tests/individually/module1/requirements.txt similarity index 100% rename from test-indiv/module1/requirements.txt rename to tests/individually/module1/requirements.txt diff --git a/test-indiv/module2/handler2.py b/tests/individually/module2/handler2.py similarity index 100% rename from test-indiv/module2/handler2.py rename to tests/individually/module2/handler2.py diff --git a/test-indiv/module2/requirements.txt b/tests/individually/module2/requirements.txt similarity index 100% rename from test-indiv/module2/requirements.txt rename to tests/individually/module2/requirements.txt diff --git a/test-indiv/package.json b/tests/individually/package.json similarity index 100% rename from test-indiv/package.json rename to tests/individually/package.json diff --git a/test-indiv/serverless.yml b/tests/individually/serverless.yml similarity index 100% rename from test-indiv/serverless.yml rename to tests/individually/serverless.yml diff --git a/pipenv-example/.gitignore b/tests/pipenv/.gitignore similarity index 100% rename from pipenv-example/.gitignore rename to tests/pipenv/.gitignore diff --git a/pipenv-example/Pipfile b/tests/pipenv/Pipfile similarity index 100% rename from pipenv-example/Pipfile rename to tests/pipenv/Pipfile diff --git a/pipenv-example/Pipfile.lock b/tests/pipenv/Pipfile.lock similarity index 100% rename from pipenv-example/Pipfile.lock rename to tests/pipenv/Pipfile.lock diff --git a/test/handler.py b/tests/pipenv/handler.py similarity index 100% rename from test/handler.py rename to tests/pipenv/handler.py diff --git a/test/package.json b/tests/pipenv/package.json similarity index 100% rename from test/package.json rename to tests/pipenv/package.json diff --git a/pipenv-example/serverless.yml b/tests/pipenv/serverless.yml similarity index 100% rename from pipenv-example/serverless.yml rename to tests/pipenv/serverless.yml