Mercurial > gemma
changeset 4116:3cec90587ff9
Make port and database configurable
author | Tom Gottfried <tom@intevation.de> |
---|---|
date | Wed, 31 Jul 2019 18:00:49 +0200 |
parents | 5c0a99b56b2a |
children | ab08a74ad2f4 |
files | schema/run_tests.sh |
diffstat | 1 files changed, 63 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/schema/run_tests.sh Wed Jul 31 18:00:12 2019 +0200 +++ b/schema/run_tests.sh Wed Jul 31 18:00:49 2019 +0200 @@ -5,35 +5,87 @@ # SPDX-License-Identifier: AGPL-3.0-or-later # License-Filename: LICENSES/AGPL-3.0.txt # -# Copyright (C) 2018 by via donau +# Copyright (C) 2018, 2019 by via donau # – Österreichische Wasserstraßen-Gesellschaft mbH # Software engineering by Intevation GmbH # # Author(s): # * Tom Gottfried <tom@intevation.de> -dropdb --if-exists gemma_test +ME=`basename "$0"` +BASEDIR=`dirname "$0"` + +usage() +{ + cat <<EOF +$ME [OPTION]... + +Options: + -d, --db=NAME create (and drop if exists) the database NAME. + Default: "gemma_test" + -p, --port=PORT connect do the postgresql cluster at PORT. + Default is the postgresql standard port 5432 + --help display this help and exit + +EOF +} + +# Defaults: + +db=gemma_test +port=5432 + +# Parse options: -./install-db.sh -d gemma_test -psql -qv ON_ERROR_STOP= -c 'CREATE EXTENSION pgtap' -d gemma_test +OPTS=`getopt \ + -l help,db:,port: \ + -o d:p: -n "$ME" -- "$@"` +[ $? -eq 0 ] || { usage ; exit 1 ; } + +eval set -- "$OPTS" + +while true ; do + case "$1" in + --db|-d) + db="$2" + shift 2 + ;; + --port|-p) + port="$2" + shift 2 + ;; + --help) + { usage ; exit 0 ; } + ;; + --) + shift + break + ;; + esac +done + +dropdb --if-exists -p "$port" "$db" + +./install-db.sh -d "$db" -p "$port" +psql -qv ON_ERROR_STOP= -c 'CREATE EXTENSION pgtap' -d "$db" -p "$port" # Collect test roles to be dropped # Concatenate with dummy role to prevent syntax error if there is no test role -TEST_ROLES=$(psql -qtc \ +TEST_ROLES=$(psql -d "$db" -p "$port" -qtc \ "SELECT concat_ws(',', 'test', string_agg(rolname, ',')) FROM pg_roles WHERE rolname LIKE 'test%'") # Drop test roles, add test data and run tests -psql -qXv ON_ERROR_STOP= -v -d gemma_test \ +psql -qXv ON_ERROR_STOP= -v -d "$db" -p "$port" \ -c 'SET client_min_messages TO WARNING' \ -c "DROP ROLE IF EXISTS $TEST_ROLES" \ - -f tap_tests_data.sql \ + -f "$BASEDIR"/tap_tests_data.sql \ -c "SELECT plan(71 + ( SELECT count(*)::int FROM information_schema.tables WHERE table_schema = 'waterway'))" \ - -f gemma_tests.sql \ - -f isrs_tests.sql \ - -f auth_tests.sql \ - -f manage_users_tests.sql \ + -f "$BASEDIR"/gemma_tests.sql \ + -f "$BASEDIR"/isrs_tests.sql \ + -f "$BASEDIR"/auth_tests.sql \ + -f "$BASEDIR"/manage_users_tests.sql \ -c 'SELECT * FROM finish()'