Skip to content

Commit f0d21dd

Browse files
lippserdoxzijulianbrost
committed
Add script to run tests locally
Co-authored-by: Alvar Penning <alvar.penning@icinga.com> Co-authored-by: Julian Brost <julian.brost@icinga.com>
1 parent d4e3991 commit f0d21dd

1 file changed

Lines changed: 74 additions & 0 deletions

File tree

tests/run.sh

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#!/usr/bin/env bash
2+
3+
# This script eases running the integration tests on the local machine.
4+
#
5+
# Configuration happens mostly through environment variables. In addition to
6+
# the already defined variables, the following are introduced for this script.
7+
#
8+
# - ICINGADB_TESTING_RUN_PREFIX
9+
# Optional command to prefix the actual test run with, e.g., sudo.
10+
# - ICINGADB_TESTING_DATABASES
11+
# Space-separated list of database types, defaults to "mysql pgsql".
12+
#
13+
# In addition to the environment variables, all arguments given to this script
14+
# are being passed to the go test call, e.g., -test.run to limit the tests.
15+
#
16+
# Example usage:
17+
# $ ICINGADB_TESTING_DATABASES=pgsql ./tests/run.sh -test.run TestHistory
18+
19+
set -euxo pipefail
20+
21+
: "${ICINGADB_TESTING_DATABASES:=mysql pgsql}"
22+
: "${ICINGADB_TESTING_RUN_PREFIX:=}"
23+
24+
build() {
25+
pushd ..
26+
GOOS=linux CGO_ENABLED=0 go build -o tests/ ./cmd/icingadb
27+
popd
28+
go test -o icingadb-test -c .
29+
}
30+
31+
cleanup() {
32+
for id in $(docker ps -q --filter="name=icinga-testing-*"); do
33+
docker container rm -f -v "$id"
34+
done
35+
docker network prune -f --filter="label=icinga=testing"
36+
}
37+
38+
raiseLimits() {
39+
if [ "$(ulimit -n)" -lt "1024" ]; then
40+
ulimit -n 1024
41+
fi
42+
}
43+
44+
run() {
45+
export ICINGA_TESTING_ICINGADB_BINARY="${PWD}/icingadb"
46+
export ICINGA_TESTING_ICINGADB_SCHEMA_MYSQL="${PWD}/../schema/mysql/schema.sql"
47+
export ICINGA_TESTING_ICINGADB_SCHEMA_PGSQL="${PWD}/../schema/pgsql/schema.sql"
48+
49+
if [ "$(uname -s)" = "Darwin" ]; then
50+
export TMPDIR="/private${TMPDIR}"
51+
fi
52+
53+
for t in $ICINGADB_TESTING_DATABASES; do
54+
export ICINGADB_TESTS_DATABASE_TYPE="$t"
55+
time $ICINGADB_TESTING_RUN_PREFIX ./icingadb-test \
56+
-icingatesting.debuglog debug.log -test.v "$@"
57+
done
58+
}
59+
60+
# Note that we do not trap ERR as it can be useful to check running containers.
61+
trap 'cleanup' INT TERM
62+
trap 'catch $? $LINENO' EXIT
63+
catch() {
64+
if [ "$1" -eq "0" ]; then
65+
cleanup
66+
fi
67+
}
68+
69+
cd "${BASH_SOURCE%/*}"
70+
71+
cleanup
72+
raiseLimits
73+
build
74+
run "$@"

0 commit comments

Comments
 (0)