2022-03-09 13:45:36 +00:00
|
|
|
#!/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"
|
|
|
|
|
2022-03-15 09:40:01 +00:00
|
|
|
"${TEST_DIR}/check-requirements"
|
2022-03-09 13:45:36 +00:00
|
|
|
|
2022-03-21 14:51:05 +00:00
|
|
|
echo "Running tests..."
|
2022-06-13 19:54:47 +00:00
|
|
|
echo "DB_BACKEND: ${DB_BACKEND}"
|
|
|
|
if [[ -z "${TEST_COVERAGE}" ]]; then
|
2022-04-05 09:00:11 +00:00
|
|
|
echo "Coverage report: no"
|
|
|
|
else
|
|
|
|
echo "Coverage report: yes"
|
|
|
|
rm -f "${LOCAL_DIR}/var/lib/coverage/*"
|
|
|
|
mkdir -p "${LOCAL_DIR}/var/lib/coverage"
|
|
|
|
fi
|
|
|
|
|
2022-03-21 14:51:05 +00:00
|
|
|
|
|
|
|
dump_backend="$(cat "${LOCAL_INIT_DIR}/.backend")"
|
2022-06-13 19:54:47 +00:00
|
|
|
if [[ "${DB_BACKEND}" != "${dump_backend}" ]]; then
|
|
|
|
die "Can't run with backend '${DB_BACKEND}' because the test data was build with '${dump_backend}'"
|
2022-03-21 14:51:05 +00:00
|
|
|
fi
|
|
|
|
|
2022-06-13 19:54:47 +00:00
|
|
|
if [[ $# -ge 1 ]]; then
|
2022-03-21 14:51:05 +00:00
|
|
|
echo "test files: $*"
|
2022-03-09 13:45:36 +00:00
|
|
|
"${TEST_DIR}/lib/bats-core/bin/bats" \
|
|
|
|
--jobs 1 \
|
|
|
|
--print-output-on-failure \
|
2022-06-13 19:54:47 +00:00
|
|
|
--timing \
|
2022-05-28 20:10:27 +00:00
|
|
|
"$@"
|
2022-03-09 13:45:36 +00:00
|
|
|
else
|
2022-03-21 14:51:05 +00:00
|
|
|
echo "test files: ${TEST_DIR}/bats ${TEST_DIR}/dyn-bats"
|
2022-03-09 13:45:36 +00:00
|
|
|
"${TEST_DIR}/lib/bats-core/bin/bats" \
|
|
|
|
--jobs 1 \
|
|
|
|
--print-output-on-failure \
|
|
|
|
-T "${TEST_DIR}/bats" "${TEST_DIR}/dyn-bats"
|
|
|
|
fi
|
2022-04-05 09:00:11 +00:00
|
|
|
|
2022-06-13 19:54:47 +00:00
|
|
|
if [[ -n "${TEST_COVERAGE}" ]]; then
|
2022-05-31 08:01:30 +00:00
|
|
|
# empty files just to avoid merge errors
|
|
|
|
touch "${LOCAL_DIR}"/var/lib/coverage/crowdsec-
|
|
|
|
touch "${LOCAL_DIR}"/var/lib/coverage/cscli-
|
2022-05-24 15:22:08 +00:00
|
|
|
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"
|
2022-04-05 09:00:11 +00:00
|
|
|
fi
|