Skip to content

Commit 8783049

Browse files
authored
Tests reorg (#164)
* start a reorg of tests to clean up the repo root a bit * fix npm i paths for tests that were already cd'ing * lets see if we can use docker via machine-style builds * fix shape for docker->machine switch * work in home? * sudo? * build python... * add cd & npm i for vendor test * apt update first * uggghhh. bats isnt in the trusty repos * sudo pipenv install * disable actual test for now.. ugh. and remove user test since machines dont run as root * use weird install/pack trick. add cds to a few tests i forgot
1 parent 372b619 commit 8783049

20 files changed

+66
-34
lines changed

β€Žcircle.yml

+22-14
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,32 @@
11
version: 2
22
jobs:
33
build:
4-
working_directory: /sls-py-req
5-
docker:
6-
- image: ubuntu:rolling
4+
working_directory: ~/sls-py-req
5+
machine:
6+
image: circleci/classic
77
steps:
88
- checkout
9-
- setup_remote_docker
10-
# Apt deps
11-
- run: apt -y update && apt -y install python3-pip python3.6 python-pip python2.7 curl unzip bats docker
9+
# Build python3.6. gross. (based on my gist here: https://git.io/vxMFG )
10+
- run: |
11+
sudo apt-get update
12+
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
13+
wget https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tar.xz
14+
tar xf Python-3.6.5.tar.xz
15+
cd Python-3.6.5
16+
./configure
17+
make
18+
sudo make altinstall
19+
# install bats
20+
- run: |
21+
git clone https://github.com/sstephenson/bats.git
22+
cd bats
23+
sudo ./install.sh /usr/local
24+
# other deps
25+
- run: sudo apt -y update && sudo apt -y install python-pip python2.7 curl unzip
1226
# instal pipenv
13-
- run: python3.6 -m pip install pipenv
27+
- run: sudo python3.6 -m pip install pipenv
1428
# install nodejs
15-
- run: curl -sL https://deb.nodesource.com/setup_6.x | bash - && apt -y install nodejs
29+
- run: curl -sL https://deb.nodesource.com/setup_6.x | sudo bash - && sudo apt -y install nodejs
1630
# install serverless & depcheck
1731
- run: npm install -g serverless depcheck
1832
# install deps
@@ -23,9 +37,3 @@ jobs:
2337
- run: npm run lint
2438
# test!
2539
- run: npm run test
26-
# create a user
27-
- run: useradd -m tester
28-
# give this dir to the test user
29-
- run: chown -R tester .
30-
# test as user!
31-
- run: su -c "npm run test" tester

β€Žtest.bats

+44-20
Original file line numberDiff line numberDiff line change
@@ -7,38 +7,41 @@ setup() {
77
export LC_ALL=C.UTF-8
88
export LANG=C.UTF-8
99
fi
10-
11-
cd test
12-
13-
npm i ..
1410
}
1511

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

2217
@test "py3.6 can package flask with default options" {
18+
cd tests/base
19+
npm i $(npm pack ../..)
2320
sls package
2421
unzip .serverless/sls-py-req-test.zip -d puck
2522
ls puck/flask
2623
}
2724

2825
@test "py3.6 can package flask with zip option" {
26+
cd tests/base
27+
npm i $(npm pack ../..)
2928
sls --zip=true package
3029
unzip .serverless/sls-py-req-test.zip -d puck
3130
ls puck/.requirements.zip puck/unzip_requirements.py
3231
! ls puck/flask
3332
}
3433

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

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

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

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

6570
@test "py3.6 uses cache with dockerizePip option" {
66-
[ -z "$CIRCLE_BRANCH" ] || skip "Volumes are weird in CircleCI https://circleci.com/docs/2.0/building-docker-images/#mounting-folders"
71+
cd tests/base
72+
npm i $(npm pack ../..)
6773
! uname -sm|grep Linux || groups|grep docker || id -u|egrep '^0$' || skip "can't dockerize on linux if not root & not in docker group"
6874
perl -p -i'.bak' -e 's/(pythonRequirements:$)/\1\n pipCmdExtraArgs: ["--cache-dir", ".requirements-cache"]/' serverless.yml
6975
sls --dockerizePip=true package
7076
ls .requirements-cache/http
7177
}
7278

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

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

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

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

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

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

114130
@test "pipenv py3.6 can package flask with default options" {
115-
cd ../pipenv-example
116-
npm i ..
131+
cd tests/pipenv
132+
npm i $(npm pack ../..)
117133
sls package
118134
unzip .serverless/sls-py-req-test.zip -d puck
119135
ls puck/flask
120136
}
121137

122138
@test "pipenv py3.6 can package flask with zip option" {
123-
cd ../pipenv-example
124-
npm i ..
139+
cd tests/pipenv
140+
npm i $(npm pack ../..)
125141
sls --zip=true package
126142
unzip .serverless/sls-py-req-test.zip -d puck
127143
ls puck/.requirements.zip puck/unzip_requirements.py
128144
}
129145

130146
@test "pipenv py3.6 doesn't package boto3 by default" {
131-
cd ../pipenv-example
132-
npm i ..
147+
cd tests/pipenv
148+
npm i $(npm pack ../..)
133149
sls package
134150
unzip .serverless/sls-py-req-test.zip -d puck
135151
! ls puck/boto3
136152
}
137153

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

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

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

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

174196
@test "py3.6 can package only requirements of module" {
175-
cd ../test-indiv
176-
npm i ..
197+
cd tests/individually
198+
npm i $(npm pack ../..)
177199
sls package
178200
unzip .serverless/module1.zip -d puck
179201
unzip .serverless/module2.zip -d puck2
@@ -188,6 +210,8 @@ teardown() {
188210
}
189211

190212
@test "py3.6 can package lambda-decorators using vendor option" {
213+
cd tests/base
214+
npm i $(npm pack ../..)
191215
sls --vendor=./vendor package
192216
unzip .serverless/sls-py-req-test.zip -d puck
193217
ls puck/flask
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.

0 commit comments

Comments
Β (0)