#!/usr/bin/bash -eux

# During PostgreSQL transitions, postgresql and postgresql-postgis do not
# necessarily point at the same PG major version. Run tests with the version
# that has PostGIS.
postgis=$(ls /usr/lib/postgresql/*/lib/postgis-*.so | tail -n1)
postgis=${postgis#/usr/lib/postgresql/} # remove prefix
postgis=${postgis%/lib*} # remove suffix

pg_virtualenv -v $postgis <<EOF
set -eux

# Basic postgresql+postgis setup
psql -c "CREATE DATABASE template_postgis IS_TEMPLATE true;"

# Run the tests
cd tests
bash -e ./run_all_tests.sh
EOF
