@@ -107,7 +107,7 @@ function get_ip_from_cid() {
107
107
}
108
108
109
109
function postgresql_cmd() {
110
- docker run --rm -e PGPASSWORD=" $PASS " " $IMAGE_NAME " psql " postgresql://$PGUSER @$CONTAINER_IP :5432/${DB-db} " " $@ "
110
+ docker run --rm -e PGPASSWORD=" $PASS " " $IMAGE_NAME " psql -v ON_ERROR_STOP=1 " postgresql://$PGUSER @$CONTAINER_IP :5432/${DB-db} " " $@ "
111
111
}
112
112
113
113
function test_connection() {
@@ -121,9 +121,9 @@ function test_connection() {
121
121
# Don't let the code come here if neither user nor admin is able to
122
122
# connect.
123
123
if [ -v PGUSER ] && [ -v PASS ]; then
124
- CONTAINER_IP=$ip postgresql_cmd <<< " SELECT 1;"
124
+ CONTAINER_IP=$ip postgresql_cmd -At -c " SELECT 1;"
125
125
else
126
- PGUSER=postgres PASS=$ADMIN_PASS CONTAINER_IP=$ip DB=postgres postgresql_cmd <<< " SELECT 1;"
126
+ PGUSER=postgres PASS=$ADMIN_PASS CONTAINER_IP=$ip DB=postgres postgresql_cmd -At -c " SELECT 1;"
127
127
fi
128
128
status=$?
129
129
if [ $status -eq 0 ]; then
@@ -137,14 +137,19 @@ function test_connection() {
137
137
138
138
function test_postgresql() {
139
139
local ret=0
140
+ local user=${1:- user}
140
141
echo " Testing PostgreSQL"
141
- postgresql_cmd <<< " CREATE EXTENSION 'uuid-ossp';" || ret=1 # to test contrib package
142
- postgresql_cmd <<< " CREATE TABLE tbl (col1 VARCHAR(20), col2 VARCHAR(20));" || ret=2
143
- postgresql_cmd <<< " INSERT INTO tbl VALUES ('foo1', 'bar1');" || ret=3
144
- postgresql_cmd <<< " INSERT INTO tbl VALUES ('foo2', 'bar2');" || ret=4
145
- postgresql_cmd <<< " INSERT INTO tbl VALUES ('foo3', 'bar3');" || ret=5
146
- postgresql_cmd <<< " SELECT * FROM tbl;" || ret=6
147
- # postgresql_cmd <<< "DROP TABLE tbl;"
142
+ # test contrib only when having admin privileges
143
+ if [ " $user " == " admin" ] ; then
144
+ postgresql_cmd -At -c " CREATE EXTENSION \" uuid-ossp\" ;" || ret=1 # to test contrib package
145
+ fi
146
+ postgresql_cmd -At -c " CREATE TABLE tbl (col1 VARCHAR(20), col2 VARCHAR(20));" || ret=2
147
+ postgresql_cmd -At -c " INSERT INTO tbl VALUES ('foo1', 'bar1');" || ret=3
148
+ postgresql_cmd -At -c " INSERT INTO tbl VALUES ('foo2', 'bar2');" || ret=4
149
+ postgresql_cmd -At -c " INSERT INTO tbl VALUES ('foo3', 'bar3');" || ret=5
150
+ postgresql_cmd -At -c " SELECT * FROM tbl;" || ret=6
151
+ # not droping table, other tests depend on having it created after this function is run
152
+ # postgresql_cmd -At -c "DROP TABLE tbl;"
148
153
if [ $ret -eq 0 ]; then
149
154
echo " Success!"
150
155
fi
@@ -195,7 +200,7 @@ function assert_login_access() {
195
200
196
201
echo " testing login as $PGUSER :$PASS ; should_success=$success "
197
202
198
- if postgresql_cmd <<< ' SELECT 1;' ; then
203
+ if postgresql_cmd -At -c ' SELECT 1;' ; then
199
204
if $success ; then
200
205
echo " $PGUSER ($PASS ) access granted as expected"
201
206
return
@@ -422,11 +427,11 @@ function run_tests() {
422
427
run_configuration_tests $name || ret=8
423
428
424
429
if $user_login ; then
425
- test_postgresql $name || ret=9
430
+ test_postgresql || ret=9
426
431
fi
427
432
428
433
if $admin_login ; then
429
- DB=postgres PGUSER=postgres PASS=$ADMIN_PASS test_postgresql $name || ret=10
434
+ DB=postgres PGUSER=postgres PASS=$ADMIN_PASS test_postgresql admin || ret=10
430
435
fi
431
436
if [ $ret -eq 0 ]; then
432
437
echo " Success!"
@@ -631,6 +636,7 @@ $volume_options
631
636
632
637
assert_login_access ${user} ${password} true || ret=4
633
638
assert_login_access ' postgres' ${admin_password} true || ret=5
639
+ test_postgresql || ret 5
634
640
635
641
echo " Changing passwords"
636
642
@@ -664,6 +670,9 @@ $volume_options
664
670
assert_login_access ' postgres' " NEW_${admin_password} " true || ret=10
665
671
assert_login_access ' postgres' ${admin_password} false || ret=11
666
672
673
+ # check that we still work with the original volume
674
+ postgresql_cmd -At -c " SELECT * FROM tbl;" | grep bar3 || ret=12
675
+
667
676
if [ $ret -eq 0 ]; then
668
677
echo " Success!"
669
678
fi
0 commit comments