Mercurial > gemma
annotate schema/run_tests.sh @ 5342:08dc7e5de1f5 extented-report
fixing linting errors
author | Thomas Junk <thomas.junk@intevation.de> |
---|---|
date | Fri, 18 Jun 2021 12:05:57 +0200 |
parents | 722b7c305319 |
children |
rev | line source |
---|---|
172
a422471db08a
Automate running DB-tests with an extra database
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
1 #!/bin/sh -e |
1303
a8d1f2897c42
repair schema install scripts
Bernhard Reiter <bernhard@intevation.de>
parents:
1301
diff
changeset
|
2 # This is Free Software under GNU Affero General Public License v >= 3.0 |
a8d1f2897c42
repair schema install scripts
Bernhard Reiter <bernhard@intevation.de>
parents:
1301
diff
changeset
|
3 # without warranty, see README.md and license for details. |
a8d1f2897c42
repair schema install scripts
Bernhard Reiter <bernhard@intevation.de>
parents:
1301
diff
changeset
|
4 # |
a8d1f2897c42
repair schema install scripts
Bernhard Reiter <bernhard@intevation.de>
parents:
1301
diff
changeset
|
5 # SPDX-License-Identifier: AGPL-3.0-or-later |
a8d1f2897c42
repair schema install scripts
Bernhard Reiter <bernhard@intevation.de>
parents:
1301
diff
changeset
|
6 # License-Filename: LICENSES/AGPL-3.0.txt |
a8d1f2897c42
repair schema install scripts
Bernhard Reiter <bernhard@intevation.de>
parents:
1301
diff
changeset
|
7 # |
4116
3cec90587ff9
Make port and database configurable
Tom Gottfried <tom@intevation.de>
parents:
3665
diff
changeset
|
8 # Copyright (C) 2018, 2019 by via donau |
1303
a8d1f2897c42
repair schema install scripts
Bernhard Reiter <bernhard@intevation.de>
parents:
1301
diff
changeset
|
9 # – Österreichische Wasserstraßen-Gesellschaft mbH |
a8d1f2897c42
repair schema install scripts
Bernhard Reiter <bernhard@intevation.de>
parents:
1301
diff
changeset
|
10 # Software engineering by Intevation GmbH |
a8d1f2897c42
repair schema install scripts
Bernhard Reiter <bernhard@intevation.de>
parents:
1301
diff
changeset
|
11 # |
a8d1f2897c42
repair schema install scripts
Bernhard Reiter <bernhard@intevation.de>
parents:
1301
diff
changeset
|
12 # Author(s): |
a8d1f2897c42
repair schema install scripts
Bernhard Reiter <bernhard@intevation.de>
parents:
1301
diff
changeset
|
13 # * Tom Gottfried <tom@intevation.de> |
172
a422471db08a
Automate running DB-tests with an extra database
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
14 |
4116
3cec90587ff9
Make port and database configurable
Tom Gottfried <tom@intevation.de>
parents:
3665
diff
changeset
|
15 ME=`basename "$0"` |
3cec90587ff9
Make port and database configurable
Tom Gottfried <tom@intevation.de>
parents:
3665
diff
changeset
|
16 BASEDIR=`dirname "$0"` |
3cec90587ff9
Make port and database configurable
Tom Gottfried <tom@intevation.de>
parents:
3665
diff
changeset
|
17 |
3cec90587ff9
Make port and database configurable
Tom Gottfried <tom@intevation.de>
parents:
3665
diff
changeset
|
18 usage() |
3cec90587ff9
Make port and database configurable
Tom Gottfried <tom@intevation.de>
parents:
3665
diff
changeset
|
19 { |
3cec90587ff9
Make port and database configurable
Tom Gottfried <tom@intevation.de>
parents:
3665
diff
changeset
|
20 cat <<EOF |
3cec90587ff9
Make port and database configurable
Tom Gottfried <tom@intevation.de>
parents:
3665
diff
changeset
|
21 $ME [OPTION]... |
3cec90587ff9
Make port and database configurable
Tom Gottfried <tom@intevation.de>
parents:
3665
diff
changeset
|
22 |
3cec90587ff9
Make port and database configurable
Tom Gottfried <tom@intevation.de>
parents:
3665
diff
changeset
|
23 Options: |
3cec90587ff9
Make port and database configurable
Tom Gottfried <tom@intevation.de>
parents:
3665
diff
changeset
|
24 -d, --db=NAME create (and drop if exists) the database NAME. |
3cec90587ff9
Make port and database configurable
Tom Gottfried <tom@intevation.de>
parents:
3665
diff
changeset
|
25 Default: "gemma_test" |
3cec90587ff9
Make port and database configurable
Tom Gottfried <tom@intevation.de>
parents:
3665
diff
changeset
|
26 -p, --port=PORT connect do the postgresql cluster at PORT. |
3cec90587ff9
Make port and database configurable
Tom Gottfried <tom@intevation.de>
parents:
3665
diff
changeset
|
27 Default is the postgresql standard port 5432 |
3cec90587ff9
Make port and database configurable
Tom Gottfried <tom@intevation.de>
parents:
3665
diff
changeset
|
28 --help display this help and exit |
3cec90587ff9
Make port and database configurable
Tom Gottfried <tom@intevation.de>
parents:
3665
diff
changeset
|
29 |
3cec90587ff9
Make port and database configurable
Tom Gottfried <tom@intevation.de>
parents:
3665
diff
changeset
|
30 EOF |
3cec90587ff9
Make port and database configurable
Tom Gottfried <tom@intevation.de>
parents:
3665
diff
changeset
|
31 } |
3cec90587ff9
Make port and database configurable
Tom Gottfried <tom@intevation.de>
parents:
3665
diff
changeset
|
32 |
3cec90587ff9
Make port and database configurable
Tom Gottfried <tom@intevation.de>
parents:
3665
diff
changeset
|
33 # Defaults: |
3cec90587ff9
Make port and database configurable
Tom Gottfried <tom@intevation.de>
parents:
3665
diff
changeset
|
34 |
3cec90587ff9
Make port and database configurable
Tom Gottfried <tom@intevation.de>
parents:
3665
diff
changeset
|
35 db=gemma_test |
3cec90587ff9
Make port and database configurable
Tom Gottfried <tom@intevation.de>
parents:
3665
diff
changeset
|
36 port=5432 |
3cec90587ff9
Make port and database configurable
Tom Gottfried <tom@intevation.de>
parents:
3665
diff
changeset
|
37 |
3cec90587ff9
Make port and database configurable
Tom Gottfried <tom@intevation.de>
parents:
3665
diff
changeset
|
38 # Parse options: |
246
299568ad3c37
Use database setup script for tests and Dockerfile
Tom Gottfried <tom@intevation.de>
parents:
234
diff
changeset
|
39 |
4116
3cec90587ff9
Make port and database configurable
Tom Gottfried <tom@intevation.de>
parents:
3665
diff
changeset
|
40 OPTS=`getopt \ |
3cec90587ff9
Make port and database configurable
Tom Gottfried <tom@intevation.de>
parents:
3665
diff
changeset
|
41 -l help,db:,port: \ |
3cec90587ff9
Make port and database configurable
Tom Gottfried <tom@intevation.de>
parents:
3665
diff
changeset
|
42 -o d:p: -n "$ME" -- "$@"` |
3cec90587ff9
Make port and database configurable
Tom Gottfried <tom@intevation.de>
parents:
3665
diff
changeset
|
43 [ $? -eq 0 ] || { usage ; exit 1 ; } |
3cec90587ff9
Make port and database configurable
Tom Gottfried <tom@intevation.de>
parents:
3665
diff
changeset
|
44 |
3cec90587ff9
Make port and database configurable
Tom Gottfried <tom@intevation.de>
parents:
3665
diff
changeset
|
45 eval set -- "$OPTS" |
3cec90587ff9
Make port and database configurable
Tom Gottfried <tom@intevation.de>
parents:
3665
diff
changeset
|
46 |
3cec90587ff9
Make port and database configurable
Tom Gottfried <tom@intevation.de>
parents:
3665
diff
changeset
|
47 while true ; do |
3cec90587ff9
Make port and database configurable
Tom Gottfried <tom@intevation.de>
parents:
3665
diff
changeset
|
48 case "$1" in |
3cec90587ff9
Make port and database configurable
Tom Gottfried <tom@intevation.de>
parents:
3665
diff
changeset
|
49 --db|-d) |
3cec90587ff9
Make port and database configurable
Tom Gottfried <tom@intevation.de>
parents:
3665
diff
changeset
|
50 db="$2" |
3cec90587ff9
Make port and database configurable
Tom Gottfried <tom@intevation.de>
parents:
3665
diff
changeset
|
51 shift 2 |
3cec90587ff9
Make port and database configurable
Tom Gottfried <tom@intevation.de>
parents:
3665
diff
changeset
|
52 ;; |
3cec90587ff9
Make port and database configurable
Tom Gottfried <tom@intevation.de>
parents:
3665
diff
changeset
|
53 --port|-p) |
3cec90587ff9
Make port and database configurable
Tom Gottfried <tom@intevation.de>
parents:
3665
diff
changeset
|
54 port="$2" |
3cec90587ff9
Make port and database configurable
Tom Gottfried <tom@intevation.de>
parents:
3665
diff
changeset
|
55 shift 2 |
3cec90587ff9
Make port and database configurable
Tom Gottfried <tom@intevation.de>
parents:
3665
diff
changeset
|
56 ;; |
3cec90587ff9
Make port and database configurable
Tom Gottfried <tom@intevation.de>
parents:
3665
diff
changeset
|
57 --help) |
3cec90587ff9
Make port and database configurable
Tom Gottfried <tom@intevation.de>
parents:
3665
diff
changeset
|
58 { usage ; exit 0 ; } |
3cec90587ff9
Make port and database configurable
Tom Gottfried <tom@intevation.de>
parents:
3665
diff
changeset
|
59 ;; |
3cec90587ff9
Make port and database configurable
Tom Gottfried <tom@intevation.de>
parents:
3665
diff
changeset
|
60 --) |
3cec90587ff9
Make port and database configurable
Tom Gottfried <tom@intevation.de>
parents:
3665
diff
changeset
|
61 shift |
3cec90587ff9
Make port and database configurable
Tom Gottfried <tom@intevation.de>
parents:
3665
diff
changeset
|
62 break |
3cec90587ff9
Make port and database configurable
Tom Gottfried <tom@intevation.de>
parents:
3665
diff
changeset
|
63 ;; |
3cec90587ff9
Make port and database configurable
Tom Gottfried <tom@intevation.de>
parents:
3665
diff
changeset
|
64 esac |
3cec90587ff9
Make port and database configurable
Tom Gottfried <tom@intevation.de>
parents:
3665
diff
changeset
|
65 done |
3cec90587ff9
Make port and database configurable
Tom Gottfried <tom@intevation.de>
parents:
3665
diff
changeset
|
66 |
3cec90587ff9
Make port and database configurable
Tom Gottfried <tom@intevation.de>
parents:
3665
diff
changeset
|
67 dropdb --if-exists -p "$port" "$db" |
3cec90587ff9
Make port and database configurable
Tom Gottfried <tom@intevation.de>
parents:
3665
diff
changeset
|
68 |
3cec90587ff9
Make port and database configurable
Tom Gottfried <tom@intevation.de>
parents:
3665
diff
changeset
|
69 ./install-db.sh -d "$db" -p "$port" |
3cec90587ff9
Make port and database configurable
Tom Gottfried <tom@intevation.de>
parents:
3665
diff
changeset
|
70 psql -qv ON_ERROR_STOP= -c 'CREATE EXTENSION pgtap' -d "$db" -p "$port" |
172
a422471db08a
Automate running DB-tests with an extra database
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
71 |
224
57dfab80973c
By convention, prefix all test users with 'test'
Tom Gottfried <tom@intevation.de>
parents:
223
diff
changeset
|
72 # Collect test roles to be dropped |
57dfab80973c
By convention, prefix all test users with 'test'
Tom Gottfried <tom@intevation.de>
parents:
223
diff
changeset
|
73 # Concatenate with dummy role to prevent syntax error if there is no test role |
4116
3cec90587ff9
Make port and database configurable
Tom Gottfried <tom@intevation.de>
parents:
3665
diff
changeset
|
74 TEST_ROLES=$(psql -d "$db" -p "$port" -qtc \ |
224
57dfab80973c
By convention, prefix all test users with 'test'
Tom Gottfried <tom@intevation.de>
parents:
223
diff
changeset
|
75 "SELECT concat_ws(',', 'test', string_agg(rolname, ',')) FROM pg_roles |
57dfab80973c
By convention, prefix all test users with 'test'
Tom Gottfried <tom@intevation.de>
parents:
223
diff
changeset
|
76 WHERE rolname LIKE 'test%'") |
57dfab80973c
By convention, prefix all test users with 'test'
Tom Gottfried <tom@intevation.de>
parents:
223
diff
changeset
|
77 |
57dfab80973c
By convention, prefix all test users with 'test'
Tom Gottfried <tom@intevation.de>
parents:
223
diff
changeset
|
78 # Drop test roles, add test data and run tests |
4116
3cec90587ff9
Make port and database configurable
Tom Gottfried <tom@intevation.de>
parents:
3665
diff
changeset
|
79 psql -qXv ON_ERROR_STOP= -v -d "$db" -p "$port" \ |
324
8bacd556ea39
Remove noisy NOTICEs between test output
Tom Gottfried <tom@intevation.de>
parents:
319
diff
changeset
|
80 -c 'SET client_min_messages TO WARNING' \ |
224
57dfab80973c
By convention, prefix all test users with 'test'
Tom Gottfried <tom@intevation.de>
parents:
223
diff
changeset
|
81 -c "DROP ROLE IF EXISTS $TEST_ROLES" \ |
4116
3cec90587ff9
Make port and database configurable
Tom Gottfried <tom@intevation.de>
parents:
3665
diff
changeset
|
82 -f "$BASEDIR"/tap_tests_data.sql \ |
5141
722b7c305319
Prevent equal axis geometries with intersecting validity
Tom Gottfried <tom@intevation.de>
parents:
5095
diff
changeset
|
83 -c "SELECT plan(89 + ( |
3024
5470aa3ffb9a
Fix privileges for GeoServer views
Tom Gottfried <tom@intevation.de>
parents:
2912
diff
changeset
|
84 SELECT count(*)::int |
5470aa3ffb9a
Fix privileges for GeoServer views
Tom Gottfried <tom@intevation.de>
parents:
2912
diff
changeset
|
85 FROM information_schema.tables |
5470aa3ffb9a
Fix privileges for GeoServer views
Tom Gottfried <tom@intevation.de>
parents:
2912
diff
changeset
|
86 WHERE table_schema = 'waterway'))" \ |
4116
3cec90587ff9
Make port and database configurable
Tom Gottfried <tom@intevation.de>
parents:
3665
diff
changeset
|
87 -f "$BASEDIR"/gemma_tests.sql \ |
3cec90587ff9
Make port and database configurable
Tom Gottfried <tom@intevation.de>
parents:
3665
diff
changeset
|
88 -f "$BASEDIR"/isrs_tests.sql \ |
3cec90587ff9
Make port and database configurable
Tom Gottfried <tom@intevation.de>
parents:
3665
diff
changeset
|
89 -f "$BASEDIR"/auth_tests.sql \ |
3cec90587ff9
Make port and database configurable
Tom Gottfried <tom@intevation.de>
parents:
3665
diff
changeset
|
90 -f "$BASEDIR"/manage_users_tests.sql \ |
4126
52f7264265bb
Bulk-delete tracked entries per table
Tom Gottfried <tom@intevation.de>
parents:
4118
diff
changeset
|
91 -f "$BASEDIR"/import_tests.sql \ |
222
cfde876fbaf9
Try to DROP ROLEs before creating them and keep test results
Tom Gottfried <tom@intevation.de>
parents:
207
diff
changeset
|
92 -c 'SELECT * FROM finish()' |