added ability to run tests against docker container

This commit is contained in:
Rudis Muiznieks 2020-07-18 18:11:03 -05:00
parent 3df358c7f5
commit 565edd84ab
1 changed files with 29 additions and 12 deletions

View File

@ -1,6 +1,6 @@
#!/usr/bin/env bash #!/usr/bin/env bash
BASEDIR=$(dirname "$0") BASEDIR=$(cd "$(dirname "$0")"; pwd)
PORT=14227 PORT=14227
TEST_USER=testuser@example.com TEST_USER=testuser@example.com
FAILED=0 FAILED=0
@ -78,7 +78,6 @@ assert_equal_jq() {
assert_notnull_jq() { assert_notnull_jq() {
selector=$1;shift selector=$1;shift
expected=$1;shift
actual=$(echo "$TEST_CONTENT" | jq -r "$selector") actual=$(echo "$TEST_CONTENT" | jq -r "$selector")
if [ "$actual" == "null" ]; then if [ "$actual" == "null" ]; then
printf "${RED}✗ CHECK${NC} ${BOLD}$selector${NC} is null\n" printf "${RED}✗ CHECK${NC} ${BOLD}$selector${NC} is null\n"
@ -101,13 +100,26 @@ mkdir -p "$BASEDIR/data/plans"
sqlite3 "$BASEDIR/data/test.db" < "$BASEDIR/../schema.sql" sqlite3 "$BASEDIR/data/test.db" < "$BASEDIR/../schema.sql"
# run the test server # run the test server
PORT=$PORT \ if [ -z "$USE_DOCKER" ]; then
PID_FILE="$BASEDIR/data/test.pid" \ PORT=$PORT \
LOG_FILE="$BASEDIR/data/test.log" \ PID_FILE="$BASEDIR/data/test.pid" \
DATABASE="$BASEDIR/data/test.db" \ LOG_FILE="$BASEDIR/data/test.log" \
PLAN_DIR="$BASEDIR/data/plans" \ DATABASE="$BASEDIR/data/test.db" \
SENDMAIL=/usr/bin/true \ PLAN_DIR="$BASEDIR/data/plans" \
perl "$BASEDIR/../server.pl" -d >>/dev/null 2>>/dev/null SENDMAIL=/usr/bin/true \
perl "$BASEDIR/../server.pl" -d >>/dev/null 2>>/dev/null
else
docker build -t dotplan-online-test "$BASEDIR/.."
docker run --name dotplan_online_test -d --rm \
-v "$BASEDIR/data":"/opt/data" -p $PORT:$PORT \
-e PORT=$PORT \
-e PID_FILE="/opt/data/test.pid" \
-e LOG_FILE="/opt/data/test.log" \
-e DATABASE="/opt/data/test.db" \
-e PLAN_DIR="/opt/data/plans" \
-e SENDMAIL=/usr/bin/true \
dotplan-online-test
fi
wait_file "$BASEDIR/data/test.pid" || { wait_file "$BASEDIR/data/test.pid" || {
echo "Pid file didn't appear after $? seconds, bailing." echo "Pid file didn't appear after $? seconds, bailing."
@ -236,9 +248,14 @@ that is signed'
printf "\nTearing down...\n" printf "\nTearing down...\n"
if [ -f "$BASEDIR/data/test.pid" ]; then if [ -z "$USE_DOCKER" ]; then
kill -9 `cat "$BASEDIR/data/test.pid"` if [ -f "$BASEDIR/data/test.pid" ]; then
rm "$BASEDIR/data/test.pid" kill -9 `cat "$BASEDIR/data/test.pid"`
rm "$BASEDIR/data/test.pid"
fi
else
docker exec dotplan_online_test rm /opt/data/test.pid
docker kill dotplan_online_test
fi fi
printf "Tests complete.\n" printf "Tests complete.\n"