Skip to content

Commit

Permalink
Add script to run tests locally
Browse files Browse the repository at this point in the history
  • Loading branch information
lippserd committed Nov 24, 2021
1 parent 4705619 commit 730543b
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions tests/run.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 730543b

Please sign in to comment.