#!/bin/bash if [ -z "$TEST_DATABASE" ]; then echo "Missing TEST_DATABASE environment variable" exit 1; fi echo echo 'Running "dirty" database tests' echo find -mindepth 1 -maxdepth 1 -type d | sort | while read testdir; do [ -f "$testdir/run-test.sql" ] || continue echo "Dirty test $testdir" echo "--------------------------------------------" echo echo "Creating temporary database ..." echo "DROP DATABASE IF EXISTS dirty_tests; CREATE DATABASE dirty_tests TEMPLATE $TEST_DATABASE;" \ | psql -vQUIET=1 -vON_ERROR_STOP=1 $TEST_DATABASE || exit 1 if [ -f "$testdir/prepare.sql" ]; then echo "Preparing database ..." ( cd .. && exec psql -vQUIET=1 -vON_ERROR_STOP=1 --file "dirty/$testdir/prepare.sql" dirty_tests ) || exit 1 fi echo "Running main test ..." ( cd .. && pg_prove -d dirty_tests dirty/$testdir/run-test.sql ) || exit 1 echo "Dropping temporary database ..." echo -e "DROP DATABASE IF EXISTS dirty_tests;" \ | psql -vQUIET=1 -vON_ERROR_STOP=1 $TEST_DATABASE || exit 1 echo done