Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Local tests #398

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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