-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathtest.sh
60 lines (55 loc) · 1.18 KB
/
test.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/bin/bash
DATABASE=
HOST=
PORT=5432
USER="postgres"
PASSWORD=
TESTS="/t/*.sql"
function usage() { echo "Usage: $0 -h host -d database -p port -u username -w password -t tests" 1>&2; exit 1; }
while getopts d:h:p:u:w:b:n:t: OPTION
do
case $OPTION in
d)
DATABASE=$OPTARG
;;
h)
HOST=$OPTARG
;;
p)
PORT=$OPTARG
;;
u)
USER=$OPTARG
;;
w)
PASSWORD=$OPTARG
;;
t)
TESTS=$OPTARG
;;
*)
usage
;;
esac
done
if [[ -z $DATABASE ]] || [[ -z $HOST ]] || [[ -z $PORT ]] || [[ -z $USER ]] || [[ -z $TESTS ]]
then
usage
exit 1
fi
echo "Running tests: $TESTS"
# install pgtap
PGPASSWORD=$PASSWORD psql -h $HOST -p $PORT -d $DATABASE -U $USER -f /pgtap/sql/pgtap.sql > /dev/null 2>&1
rc=$?
# exit if pgtap failed to install
if [[ $rc != 0 ]] ; then
echo "pgTap was not installed properly. Unable to run tests!"
exit $rc
fi
# run the tests
PGPASSWORD=$PASSWORD pg_prove -h $HOST -p $PORT -d $DATABASE -U $USER $TESTS
rc=$?
# uninstall pgtap
PGPASSWORD=$PASSWORD psql -h $HOST -p $PORT -d $DATABASE -U $USER -f /pgtap/sql/uninstall_pgtap.sql > /dev/null 2>&1
# exit with return code of the tests
exit $rc