Attempt Postgres CI build.

pull/14/head
Sander Vocke 5 years ago
parent 85a0b0671f
commit 41a0987d02
  1. 10
      .drone.yml
  2. 72
      server/test/test.sh

@ -9,10 +9,16 @@ steps:
- npm install - npm install
- cd server && npm install; cd .. - cd server && npm install; cd ..
- name: back-end test - name: back-end test (SQLite3)
image: node image: node
commands: commands:
- cd server && npm test; cd .. - cd server && ./test/test.sh --sqlite ; cd ..
- name: back-end test (PostgreSQL)
image: node
commands:
- POSTGRES_USER=mudbase POSTGRES_DATABASE=mudbase POSTGRES_DB=mudbase \
cd server && ./test/test.sh --postgres --start-postgres-testcontainer ; cd ..
--- ---
kind: pipeline kind: pipeline

@ -12,13 +12,17 @@ POSTGRES_CONFIG='{"client":"pg","connection":{"host":"localhost","port":9432,"us
DO_SQLITE= DO_SQLITE=
DO_POSTGRES= DO_POSTGRES=
START_POSTGRES=
START_POSTGRES_TESTCONTAINER=
usage() { usage() {
cat << EOF | echo cat << EOF | echo
This tool runs MuDBase's Jasmine tests. Different database back-ends can be selected (multiple is allowed too). This tool runs MuDBase's Jasmine tests. Different database back-ends can be selected (multiple is allowed too).
Options: Options:
-s,--sqlite Use SQLite in memory for testing. -s,--sqlite Use SQLite in memory for testing.
-p,--postgres Use Postgres for testing. Spins up a temporary Postgres container on localhos, port 9432. -p,--postgres Use Postgres for testing. Spins up a temporary Postgres container on localhos, port 9432.
-sp,--start-postgres Start its own Postgres Docker container for testing against.
-spt,--start-postgres-testcontainer Assume running in the sandervocke/postgres_node container. Spin up a PG process.
any other option is passed on to Jasmine. any other option is passed on to Jasmine.
EOF EOF
} }
@ -35,6 +39,14 @@ while (( "$#" )); do
DO_POSTGRES=1 DO_POSTGRES=1
shift shift
;; ;;
-sp|--start-postgres)
START_POSTGRES=1
shift
;;
-spt|--start-postgres-testcontainer)
START_POSTGRES_TESTCONTAINER=1
shift
;;
*) # preserve positional arguments *) # preserve positional arguments
echo "Preserving params: $1" echo "Preserving params: $1"
PARAMS="$PARAMS \"$1\"" PARAMS="$PARAMS \"$1\""
@ -51,27 +63,45 @@ if [ ! -z "${DO_SQLITE}" ]; then
SQLITE_RESULT=$(echo $?) SQLITE_RESULT=$(echo $?)
fi fi
if [ ! -z "${DO_POSTGRES}" ]; then if [ ! -z "${DO_POSTGRES}" ]; then
# Fire up a test Postgres. if [ ! -z "${START_POSTGRES}" ]; then
docker pull postgres:12 # Fire up a test Postgres.
CONTAINERID=$(docker create --rm \ docker pull postgres:12
--env POSTGRES_USER=mudbase \ CONTAINERID=$(docker create --rm \
--env POSTGRES_PASSWORD=mudbase \ --env POSTGRES_USER=mudbase \
--env POSTGRES_DB=mudbase \ --env POSTGRES_PASSWORD=mudbase \
-p 9432:5432 \ --env POSTGRES_DB=mudbase \
postgres:12) -p 9432:5432 \
docker start ${CONTAINERID} postgres:12)
trap "docker stop ${CONTAINERID}" EXIT docker start ${CONTAINERID}
trap "docker stop ${CONTAINERID}" EXIT
# Wait for postgres to be ready. # Wait for postgres to be ready.
while [ -z "$(docker logs ${CONTAINERID} | grep 'ready to accept connections')" ]; do while true; do
sleep 1; pg_isready -d mudbase -h localhost -p 9432 -U mudbase
done [ "$(echo $?)" == "0" ] && break
sleep 1
done
elif [ ! -z "${START_POSTGRES_TESTCONTAINER}" ]; then
# Fire up a test Postgres process.
docker_entrypoint.sh postgres &
PID=$(echo $!)
trap "kill $PID" EXIT
# Wait for postgres to be ready.
while true; do
pg_isready -d mudbase -h localhost -p 5432 -U mudbase
[ "$(echo $?)" == "0" ] && break
sleep 1
done
fi
MUDBASE_DB_CONFIG="$POSTGRES_CONFIG" ./node_modules/.bin/ts-node node_modules/jasmine/bin/jasmine --config=test/jasmine.json "$@" MUDBASE_DB_CONFIG="$POSTGRES_CONFIG" ./node_modules/.bin/ts-node node_modules/jasmine/bin/jasmine --config=test/jasmine.json "$@"
POSTGRES_RESULT=$(echo $?) POSTGRES_RESULT=$(echo $?)
docker stop ${CONTAINERID} if [ ! -z "${START_POSTGRES}" ]; then
trap - EXIT docker stop ${CONTAINERID}
trap - EXIT
fi
fi fi
printf "Tests finished. Results:\n\n" printf "Tests finished. Results:\n\n"
@ -82,4 +112,8 @@ if [ ! -z "${DO_POSTGRES}" ]; then
echo "Postgres: $([ ${POSTGRES_RESULT} == '1' ] && echo Fail || echo Success)" echo "Postgres: $([ ${POSTGRES_RESULT} == '1' ] && echo Fail || echo Success)"
fi fi
popd popd
[ "${SQLITE_RESULT}" == '1' -o "${POSTGRES_RESULT}" == '1' ] && exit 1
exit 0

Loading…
Cancel
Save