This repository has been archived on 2025-01-04. You can view files and clone it, but cannot push or open issues or pull requests.
lwb6/build/post-build.d/10-database-tests.sh

59 lines
1.5 KiB
Bash
Raw Normal View History

#!/bin/bash
cd legacyworlds-server-data/db-structure
if ! [ -f db-config.txt ]; then
cat > db-config.txt <<EOF
admin=$USER
db=tests
user=tests
password=tests
EOF
fi
export TEST_DATABASE="`grep ^db= db-config.txt | sed -e s/.*=//`"
export TEST_USER="`grep ^user= db-config.txt | sed -e s/.*=//`"
echo
echo
echo "======================================================================"
echo "LOADING DATABASE DEFINITION ..."
echo "======================================================================"
echo
echo
psql -vQUIET=1 -vON_ERROR_STOP=1 -e --file database.sql || exit 1
if ! [ -d tests/admin ] && ! [ -d tests/user ]; then
echo
echo
echo "WARNING: no unit tests to run"
echo
echo
exit 0
fi
echo
echo
echo "======================================================================"
echo "LOADING TEST FRAMEWORK ..."
echo "======================================================================"
echo
echo
psql -vQUIET=1 -f tests/pgtap.sql $TEST_DATABASE || exit 1
echo
echo
echo "======================================================================"
echo "RUNNING DATABASE TESTS ..."
echo "======================================================================"
echo
echo
cd tests
if [ -d admin ]; then
pg_prove -d $TEST_DATABASE `find admin/ -type f -name '*.sql'` || exit 1
fi
if [ -d user ]; then
pg_prove -U $TEST_USER -d $TEST_DATABASE `find user/ -type f -name '*.sql'` || exit 1
fi
if [ -x dirty/run-dirty-tests.sh ]; then
( cd dirty; exec ./run-dirty-tests.sh ) || exit 1
fi