#!/bin/sh

set -e

case $USER in
	root) PGUSER=postgres ;;
	*)    PGUSER=$USER ;;
esac

pg_buildext \
	-o "shared_preload_libraries=pg_partman_bgw" \
	-o "pg_partman_bgw.dbname=postgres" \
	-o "pg_partman_bgw.interval=10" \
	-o "pg_partman_bgw.role=$PGUSER" \
	virtualenv <<-EOF
		psql -c "CREATE EXTENSION pgtap"
		psql -c "CREATE EXTENSION pg_partman"
		# run one of the normal tests
		pg_prove -ovf test/test-id.sql
		# run one of the bgw tests
		pg_prove -ovf test/test_bgw/test-time-daily-bgw.sql
	EOF
