11#! /usr/bin/env sh
22THISDIR=$( cd $( dirname " $0 " ) ; pwd) # this script's directory
33
4- # ####
4+ # #################################################
55# Runs an end-to-end test locally using serverless-offline
6- # ###
6+ # TLDR; this test curls to some known good endpoints looking for an expected HTTP response code:
7+ # #################################################
8+
9+ die () {
10+ echo >&2 " $@ "
11+ stop_serverless_offline
12+ help
13+ exit 1
14+ }
15+
16+ help () {
17+ echo
18+ cat << END_DOC
19+ The script $THISSCRIPT failed. This likely means the e2e tests failed. See output above to confirm.
20+ END_DOC
21+
22+ }
723
824REPO_ROOT_DIR=$( cd " THISDIR" ; pwd)
925echo " Using REPO_ROOT_DIR $REPO_ROOT_DIR "
@@ -15,34 +31,50 @@ npm install -s
1531echo " Running npm install completed."
1632
1733# run severless-offline in background:
18- ./node_modules/.bin/serverless offline &
1934
20- # wait on serverless-offline to start
21- sleep 5
35+ start_serverless_offline () {
36+ ./node_modules/.bin/serverless offline &
37+
38+ # wait on serverless-offline to start
39+ sleep 5
40+ }
41+
42+ start_serverless_offline
43+
44+ stop_serverless_offline () {
45+ # shut down serverles offline now
46+ echo " Killing serverless offline process..."
47+ pkill -f -n " serverless offline"
48+ # sleep for a sec just to get clean output due to the background process
49+ sleep 1
50+ echo " Killing serverless offline process complete."
51+ }
2252
23- # CURL to some known good endpoints expecting 200:
24- TEST_HTTP_EXEC=$REPO_ROOT_DIR /test-files/scripts/test-http.sh
2553ROOT_URL=http://localhost:3000/dev
2654
55+ test_url () {
56+ TEST_URL=$1
57+ TEST_HTTP_RESP_CODE=$2
58+ echo " testing URL '$TEST_URL ' with HTTP response code '$TEST_HTTP_RESP_CODE '"
59+ $REPO_ROOT_DIR /test-files/scripts/test-http.sh $TEST_URL $TEST_HTTP_RESP_CODE || die " \n*FAILURE* testing URL '$TEST_URL ' with HTTP response code '$TEST_HTTP_RESP_CODE '!"
60+ }
61+
62+ test_url $ROOT_URL /binary/jpg.jpg
63+
2764# 200; these all should succeed
28- $TEST_HTTP_EXEC $ROOT_URL /binary/png.png
29- $TEST_HTTP_EXEC $ROOT_URL /binary/jpg.jpg
30- $TEST_HTTP_EXEC $ROOT_URL /binary/glyphicons-halflings-regular.woff2
31- $TEST_HTTP_EXEC $ROOT_URL /binary/subdir/png.png
65+ test_url $ROOT_URL /binary/png.png
66+ test_url $ROOT_URL /binary/jpg.jpg
67+ test_url $ROOT_URL /binary/glyphicons-halflings-regular.woff2
68+ test_url $ROOT_URL /binary/subdir/png.png
3269
3370# 403 for APIG, but 404 for serverless-offline
34- $TEST_HTTP_EXEC " $ROOT_URL /ff404.png" 404
35- $TEST_HTTP_EXEC " $ROOT_URL /jpeg404.jpg" 404
36- $TEST_HTTP_EXEC " $ROOT_URL /subdir404/ff.png" 404
37- $TEST_HTTP_EXEC " $ROOT_URL /subdir/ff404.png" 404
71+ test_url " $ROOT_URL /ff404.png" 404
72+ test_url " $ROOT_URL /jpeg404.jpg" 404
73+ test_url " $ROOT_URL /subdir404/ff.png" 404
74+ test_url " $ROOT_URL /subdir/ff404.png" 404
3875
3976# 404
40- $TEST_HTTP_EXEC " $ROOT_URL /binary/404-glyphicons-halflings-regular.woff2" 404
41- $TEST_HTTP_EXEC " $ROOT_URL /binary/subdir/404-png.png" 404
42-
43- # shut down serverles offline now
44- echo " Killing serverless offline process..."
45- pkill -f -n " serverless offline"
46- # sleep for a sec just to get clean output due to the background process
47- sleep 1
48- echo " Killing serverless offline process complete."
77+ test_url " $ROOT_URL /binary/404-glyphicons-halflings-regular.woff2" 404
78+ test_url " $ROOT_URL /binary/subdir/404-png.png" 404
79+
80+ stop_serverless_offline
0 commit comments