#!/usr/bin/bash
set -e
# If variables undefined, package test will create it's own database.
unset DBI_DSN DBI_USER DBI_PASS
unset DBDPG_DEBUG DBDPG_INITDB DBDPG_NOCLEANUP DBDPG_TEST_ALWAYS_ENV \
    DBDPG_TESTINITDB PGDATABASE PGINITDB POSTGRES_HOME POSTGRES_LIB \
    TEST_OUTPUT TEST_SIGNATURE
# The tests write to temporary database which is placed in $DIR
DIR=$(mktemp -d)
pushd "$DIR"
cp -a /usr/libexec/perl-DBD-Pg/* ./
# When tests are run by root, 'postgres' is used as DBI_USER
# DBI_USER has to be able to write to the $DIR
if [ `id -u` -eq 0 ]; then
    chown -hR postgres:postgres $DIR
fi
# Jobs can't be run in parallel
prove -I .
popd
rm -rf "$DIR"
