From 730543be0ee7d9c4c828fef15881175f97427695 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Wed, 24 Nov 2021 16:34:21 +0100 Subject: [PATCH] Add script to run tests locally --- tests/run.sh | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100755 tests/run.sh diff --git a/tests/run.sh b/tests/run.sh new file mode 100755 index 000000000..a487f74b6 --- /dev/null +++ b/tests/run.sh @@ -0,0 +1,47 @@ +#!/bin/sh + +set -euxo pipefail + +build() { + pushd ../ + GOOS=linux CGO_ENABLED=0 go build -o tests/ ./cmd/icingadb + popd + go test -o icingadb-test -c . +} + +cleanup() { + docker rm -f $(docker ps -q --filter="name=icinga-testing-*") > /dev/null 2>&1 || true + docker network prune -f --filter="label=icinga=testing" +} + +raiseLimits() { + if [ "$(ulimit -n)" -lt "1024" ]; then + ulimit -n 1024 + fi +} + +run() { + export ICINGA_TESTING_ICINGADB_BINARY=icingadb + export ICINGA_TESTING_ICINGADB_SCHEMA=../schema/mysql/schema.sql + if [ "$(uname -s)" = "Darwin" ]; then + export TMPDIR="/private${TMPDIR}" + fi + + ./icingadb-test -icingatesting.debuglog debug.log -test.v +} + +# Note that we do not trap ERR as it can be useful to check running containers. +trap 'cleanup' INT TERM +trap 'catch $? $LINENO' EXIT +catch() { + if [ "$1" -eq "0" ]; then + cleanup + fi +} + +cd "${BASH_SOURCE%/*}" + +cleanup +raiseLimits +build +run