Skip to content

Commit 395ced3

Browse files
committed
Fixes to test.bats with cache and slim
1 parent f6ac721 commit 395ced3

File tree

1 file changed

+26
-10
lines changed

1 file changed

+26
-10
lines changed

test.bats

+26-10
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ setup() {
88
export LANG=C.UTF-8
99
fi
1010
export USR_CACHE_DIR=`node -e 'console.log(require("./lib/shared").getUserCachePath())'`
11+
# Please note: If you update change the requirements.txt in test/base this value will
12+
# change. Run a test which uses this variable manually step by step and list the cache
13+
# folder to find the new hash if you do this
14+
export CACHE_FOLDER_HASH="b8b9d2be59f6f2ea5778e8b2aa4d2ddc_slspyc"
1115
if [ -d "${USR_CACHE_DIR}" ] ; then
1216
rm -Rf "${USR_CACHE_DIR}"
1317
fi
@@ -184,7 +188,7 @@ teardown() {
184188
perl -p -i'.bak' -e 's/(pythonRequirements:$)/\1\n useDownloadCache: true\n useStaticCache: true/' serverless.yml
185189
sls package
186190
USR_CACHE_DIR=`node -e 'console.log(require("../../lib/shared").getUserCachePath())'`
187-
ls $USR_CACHE_DIR/b8b9d2be59f6f2ea5778e8b2aa4d2ddc_slspyc/flask
191+
ls $USR_CACHE_DIR/$CACHE_FOLDER_HASH/flask
188192
ls $USR_CACHE_DIR/downloadCacheslspyc/http
189193
}
190194

@@ -195,7 +199,7 @@ teardown() {
195199
perl -p -i'.bak' -e 's/(pythonRequirements:$)/\1\n useDownloadCache: true\n useStaticCache: true/' serverless.yml
196200
sls --dockerizePip=true package
197201
USR_CACHE_DIR=`node -e 'console.log(require("../../lib/shared").getUserCachePath())'`
198-
ls $USR_CACHE_DIR/b8b9d2be59f6f2ea5778e8b2aa4d2ddc_slspyc/flask
202+
ls $USR_CACHE_DIR/$CACHE_FOLDER_HASH/flask
199203
ls $USR_CACHE_DIR/downloadCacheslspyc/http
200204
}
201205

@@ -206,8 +210,8 @@ teardown() {
206210
perl -p -i'.bak' -e 's/(pythonRequirements:$)/\1\n useStaticCache: true/' serverless.yml
207211
sls package
208212
USR_CACHE_DIR=`node -e 'console.log(require("../../lib/shared").getUserCachePath())'`
209-
ls $USR_CACHE_DIR/b8b9d2be59f6f2ea5778e8b2aa4d2ddc_slspyc/flask
210-
ls $USR_CACHE_DIR/b8b9d2be59f6f2ea5778e8b2aa4d2ddc_slspyc/.completed_requirements
213+
ls $USR_CACHE_DIR/$CACHE_FOLDER_HASH/flask
214+
ls $USR_CACHE_DIR/$CACHE_FOLDER_HASH/.completed_requirements
211215
}
212216

213217
@test "py3.6 uses static cache with cacheLocation option" {
@@ -217,8 +221,8 @@ teardown() {
217221
perl -p -i'.bak' -e 's/(pythonRequirements:$)/\1\n useStaticCache: true\n cacheLocation: .requirements-cache/' serverless.yml
218222
sls package
219223
USR_CACHE_DIR=`node -e 'console.log(require("../../lib/shared").getUserCachePath())'`
220-
ls .requirements-cache/b8b9d2be59f6f2ea5778e8b2aa4d2ddc_slspyc/flask
221-
ls .requirements-cache/b8b9d2be59f6f2ea5778e8b2aa4d2ddc_slspyc/.completed_requirements
224+
ls .requirements-cache/$CACHE_FOLDER_HASH/flask
225+
ls .requirements-cache/$CACHE_FOLDER_HASH/.completed_requirements
222226
}
223227

224228
@test "py3.6 checking that static cache actually pulls from cache (by poisoning it)" {
@@ -229,18 +233,30 @@ teardown() {
229233
sls package
230234
cp .serverless/sls-py-req-test.zip ./puck
231235
USR_CACHE_DIR=`node -e 'console.log(require("../../lib/shared").getUserCachePath())'`
232-
echo "injected new file into static cache folder" > $USR_CACHE_DIR/b8b9d2be59f6f2ea5778e8b2aa4d2ddc_slspyc/injected_file_is_bad_form
236+
echo "injected new file into static cache folder" > $USR_CACHE_DIR/$CACHE_FOLDER_HASH/injected_file_is_bad_form
233237
sls package
234238
[ `wc -c ./.serverless/sls-py-req-test.zip | awk '{ print $1 }'` -gt `wc -c ./puck | awk '{ print $1 }'` ]
235239
}
236240

237-
@test "py3.6 uses cache with dockerizePip & slim option" {
241+
@test "py3.6 uses static cache with dockerizePip & slim option" {
238242
cd tests/base
239243
npm i $(npm pack ../..)
240244
! uname -sm|grep Linux || groups|grep docker || id -u|egrep '^0$' || skip "can't dockerize on linux if not root & not in docker group"
241245
perl -p -i'.bak' -e 's/(pythonRequirements:$)/\1\n useStaticCache: true/' serverless.yml
242-
sls --slim=true package
243-
ls .requirements-cache/http
246+
sls --dockerizePip=true --slim=true package
247+
ls $USR_CACHE_DIR/$CACHE_FOLDER_HASH/flask
248+
unzip .serverless/sls-py-req-test.zip -d puck
249+
test $(find puck -name "*.pyc" | wc -l) -eq 0
250+
}
251+
252+
@test "py3.6 uses download cache with dockerizePip & slim option" {
253+
cd tests/base
254+
npm i $(npm pack ../..)
255+
! uname -sm|grep Linux || groups|grep docker || id -u|egrep '^0$' || skip "can't dockerize on linux if not root & not in docker group"
256+
perl -p -i'.bak' -e 's/(pythonRequirements:$)/\1\n useDownloadCache: true/' serverless.yml
257+
sls --dockerizePip=true --slim=true package
258+
ls $USR_CACHE_DIR/downloadCacheslspyc/http
259+
unzip .serverless/sls-py-req-test.zip -d puck
244260
test $(find puck -name "*.pyc" | wc -l) -eq 0
245261
}
246262

0 commit comments

Comments
 (0)