54 lines
1.5 KiB
Bash
Executable file
54 lines
1.5 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
|
|
set -eu
|
|
|
|
die() {
|
|
echo >&2 "$@"
|
|
exit 1
|
|
}
|
|
|
|
# shellcheck disable=SC1007
|
|
TEST_DIR=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
|
|
# shellcheck source=./.environment.sh
|
|
. "${TEST_DIR}/.environment.sh"
|
|
|
|
"${TEST_DIR}/bin/check-requirements"
|
|
|
|
echo "Running tests..."
|
|
echo "DB_BACKEND: ${DB_BACKEND}"
|
|
if [[ -z "${TEST_COVERAGE}" ]]; then
|
|
echo "Coverage report: no"
|
|
else
|
|
echo "Coverage report: yes"
|
|
rm -f "${LOCAL_DIR}/var/lib/coverage/*"
|
|
mkdir -p "${LOCAL_DIR}/var/lib/coverage"
|
|
fi
|
|
|
|
dump_backend="$(cat "${LOCAL_INIT_DIR}/.backend")"
|
|
if [[ "${DB_BACKEND}" != "${dump_backend}" ]]; then
|
|
die "Can't run with backend '${DB_BACKEND}' because the test data was build with '${dump_backend}'"
|
|
fi
|
|
|
|
if [[ $# -ge 1 ]]; then
|
|
echo "test files: $*"
|
|
"${TEST_DIR}/lib/bats-core/bin/bats" \
|
|
--jobs 1 \
|
|
--timing \
|
|
--print-output-on-failure \
|
|
"$@"
|
|
else
|
|
echo "test files: ${TEST_DIR}/bats ${TEST_DIR}/dyn-bats"
|
|
"${TEST_DIR}/lib/bats-core/bin/bats" \
|
|
--jobs 1 \
|
|
--timing \
|
|
--print-output-on-failure \
|
|
"${TEST_DIR}/bats" "${TEST_DIR}/dyn-bats"
|
|
fi
|
|
|
|
if [[ -n "${TEST_COVERAGE}" ]]; then
|
|
# empty files just to avoid merge errors
|
|
touch "${LOCAL_DIR}"/var/lib/coverage/crowdsec-
|
|
touch "${LOCAL_DIR}"/var/lib/coverage/cscli-
|
|
gocovmerge "${LOCAL_DIR}"/var/lib/coverage/crowdsec-* > "${LOCAL_DIR}/var/lib/coverage/coverage-crowdsec.out"
|
|
gocovmerge "${LOCAL_DIR}"/var/lib/coverage/cscli-* > "${LOCAL_DIR}/var/lib/coverage/coverage-cscli.out"
|
|
fi
|