Skip to content

Commit 8aafd89

Browse files
authored
Merge pull request sclorg#464 from zmiklank/use_generic_run_tests
Use generic run tests
2 parents 57f0fa6 + b9141e5 commit 8aafd89

File tree

2 files changed

+12
-56
lines changed

2 files changed

+12
-56
lines changed

test/run_test

+11-55
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# The image has to be available before this script is executed.
77
#
88

9-
set -exo nounset
9+
set -xo nounset
1010
shopt -s nullglob
1111

1212
# library from container-common-scripts
@@ -36,14 +36,12 @@ test -n "${IMAGE_NAME-}" || false 'make sure $IMAGE_NAME is defined'
3636
test -n "${VERSION-}" || false 'make sure $VERSION is defined'
3737
test -n "${OS-}" || false 'make sure $OS is defined'
3838

39-
CIDFILE_DIR=$(mktemp --suffix=postgresql_test_cidfiles -d)
39+
CID_FILE_DIR=$(mktemp --suffix=postgresql_test_cidfiles -d)
4040

4141
volumes_to_clean=
4242
images_to_clean=()
4343
files_to_clean=
4444
test_dir="$(readlink -f "$(dirname "$0")")"
45-
test_short_summary=''
46-
TESTSUITE_RESULT=1
4745

4846
_cleanup_commands_space=
4947
_cleanup_commands=
@@ -63,22 +61,6 @@ function cleanup() {
6361
# Print a big fat separator to find the error easier
6462
echo "=================================== Cleanup begins here ============================="
6563

66-
for cidfile in $CIDFILE_DIR/* ; do
67-
CONTAINER=$(cat $cidfile)
68-
69-
echo "Stopping and removing container $CONTAINER..."
70-
docker stop $CONTAINER
71-
exit_status=$(docker inspect -f '{{.State.ExitCode}}' $CONTAINER)
72-
if [ "$exit_status" != "0" ]; then
73-
echo "Dumping logs for $CONTAINER"
74-
docker logs $CONTAINER
75-
fi
76-
docker rm $CONTAINER
77-
rm $cidfile
78-
echo "Done."
79-
done
80-
rmdir $CIDFILE_DIR
81-
8264
ct_path_foreach "$volumes_to_clean" cleanup_volume_dir
8365

8466
if test -n "${images_to_clean-}"; then
@@ -94,16 +76,8 @@ function cleanup() {
9476
echo "$_cleanup_commands" | while read -r line; do
9577
eval "$line"
9678
done
97-
98-
echo "$test_short_summary"
99-
100-
if [ $TESTSUITE_RESULT -eq 0 ] ; then
101-
echo "Tests for ${IMAGE_NAME} succeeded."
102-
else
103-
echo "Tests for ${IMAGE_NAME} failed."
104-
fi
79+
echo "================== postgresql-container-specific cleanup ends here ====================="
10580
}
106-
trap cleanup EXIT
10781

10882
cleanup_volume_dir ()
10983
{
@@ -120,7 +94,7 @@ cleanup_volume_dir ()
12094

12195
function get_cid() {
12296
local id="$1" ; shift || return 1
123-
echo $(cat "$CIDFILE_DIR/$id")
97+
echo $(cat "$CID_FILE_DIR/$id")
12498
}
12599

126100
function get_container_ip() {
@@ -182,7 +156,7 @@ function create_container() {
182156
# TODO: fix all create_container() invocations so that we don't need this,
183157
# e.g. multiline DOCKER_ARGS var should end by trailing backslashes
184158
cargs=$(echo "$cargs" | tr '\n' ' ')
185-
cidfile="$CIDFILE_DIR/$name"
159+
cidfile="$CID_FILE_DIR/$name"
186160
# create container with a cidfile in a directory for cleanup
187161
eval "docker run $cargs --cidfile \$cidfile -d \$IMAGE_NAME \"\$@\""
188162
echo "Created container $(cat $cidfile)"
@@ -288,8 +262,6 @@ assert_container_creation_succeeds ()
288262
if test -n "$ADMIN_PASS"; then
289263
PGUSER=postgres PASS=$ADMIN_PASS DB=$DB test_connection "$name"
290264
fi
291-
292-
docker stop "$(get_cid "$name")"
293265
}
294266

295267

@@ -439,14 +411,14 @@ function run_tests() {
439411
function run_slave() {
440412
local suffix="$1"; shift
441413
docker run $cluster_args -e POSTGRESQL_MASTER_IP=${master_hostname} \
442-
-d --cidfile ${CIDFILE_DIR}/slave-${suffix}.cid $IMAGE_NAME run-postgresql-slave
414+
-d --cidfile ${CID_FILE_DIR}/slave-${suffix}.cid $IMAGE_NAME run-postgresql-slave
443415
}
444416

445417
function run_master() {
446418
local suffix="$1"; shift
447419
master_args=${master_args-}
448420
docker run $cluster_args $master_args \
449-
-d --cidfile ${CIDFILE_DIR}/master-${suffix}.cid $IMAGE_NAME run-postgresql-master >/dev/null
421+
-d --cidfile ${CID_FILE_DIR}/master-${suffix}.cid $IMAGE_NAME run-postgresql-master >/dev/null
450422
}
451423

452424
function test_slave_visibility() {
@@ -544,7 +516,7 @@ function run_master_restart_test() {
544516
test_slave_visibility
545517

546518
echo "Kill the master and create a new one"
547-
local cidfile=$CIDFILE_DIR/master-$cid_suffix.cid
519+
local cidfile=$CID_FILE_DIR/master-$cid_suffix.cid
548520
docker kill $(cat $cidfile)
549521
# Don't forget to remove its .cid file
550522
rm $cidfile
@@ -621,7 +593,6 @@ $volume_options
621593

622594
echo " Changing passwords"
623595

624-
docker stop $(get_cid ${name})
625596
DOCKER_ARGS="
626597
-e POSTGRESQL_DATABASE=${database}
627598
-e POSTGRESQL_USER=${user}
@@ -735,8 +706,6 @@ ${mount_opts}
735706
# need this to wait for the container to start up
736707
PGUSER=user PASS=password test_connection "$container_name"
737708
PGUSER=backuser PASS=pass DB=backup test_connection "$container_name"
738-
739-
docker stop "$(get_cid $container_name)" >/dev/null
740709
}
741710

742711
run_s2i_test() {
@@ -822,8 +791,6 @@ run_s2i_enable_ssl_test()
822791

823792
docker run --rm -e PGPASSWORD="password" "$IMAGE_NAME" psql "postgresql://postgres@$CONTAINER_IP:5432/postgres?sslmode=require" || \
824793
false "FAIL: Did not manage to connect using SSL only."
825-
826-
docker stop "$(get_cid "$container_name")"
827794
}
828795

829796
run_s2i_bake_data_test ()
@@ -841,8 +808,6 @@ run_s2i_bake_data_test ()
841808

842809
test "hello world" == "$(docker exec "$(get_cid "$container_name")" \
843810
bash -c "psql -tA -c 'SELECT * FROM test;'")"
844-
845-
docker stop "$(get_cid "$container_name")"
846811
}
847812

848813
run_pgaudit_test()
@@ -898,20 +863,11 @@ EOSQL"
898863
grep -E 'AUDIT: SESSION,.*,.*,READ,SELECT,,,SELECT' "${data_dir}"/userdata/log/postgresql-*.log
899864
}
900865

901-
function run_all_tests() {
902-
for test_case in $TEST_LIST; do
903-
: "Running test $test_case"
904-
$test_case
905-
done;
906-
}
907-
908866
# configuration defaults
909867
POSTGRESQL_MAX_CONNECTIONS=100
910868
POSTGRESQL_MAX_PREPARED_TRANSACTIONS=0
911869
POSTGRESQL_SHARED_BUFFERS=32MB
912870

913-
# Run the chosen tests
914-
TEST_LIST=${TESTS:-$TEST_LIST} run_all_tests
915-
916-
TESTSUITE_RESULT=0
917-
echo "All tests passed."
871+
ct_enable_cleanup
872+
TEST_SUMMARY=''
873+
TEST_SET=${TESTS:-$TEST_LIST} ct_run_tests_from_testset 'postgresql-container_tests'

0 commit comments

Comments
 (0)