tests: prevent "make bats-fixture" to run if instance-data is locked (#3201)

* tests: prevent "make bats-fixture" to run if instance-data is locked

* lint
This commit is contained in:
mmetc 2024-09-06 10:31:00 +02:00 committed by GitHub
parent fb0117e778
commit ace942a36d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 21 additions and 11 deletions

View file

@ -1,16 +1,26 @@
#!/usr/bin/env bash
set -eu
die() {
echo >&2 "$@"
exit 1
}
#shellcheck disable=SC1007
THIS_DIR=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
cd "$THIS_DIR" || exit 1
# shellcheck disable=SC1091
. ./.environment.sh
if [[ -f "$LOCAL_INIT_DIR/.lock" ]] && [[ "$1" != "unlock" ]]; then
die "init data is locked: are you doing some manual test? if so, please finish what you are doing, run 'instance-data unlock' and retry"
fi
backend_script="./lib/config/config-${CONFIG_BACKEND}"
if [[ ! -x "$backend_script" ]]; then
echo "unknown config backend '${CONFIG_BACKEND}'" >&2
exit 1
die "unknown config backend '${CONFIG_BACKEND}'"
fi
exec "$backend_script" "$@"

View file

@ -10,12 +10,12 @@ die() {
# shellcheck disable=SC1007
TEST_DIR=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
# shellcheck source=./.environment.sh
. "${TEST_DIR}/.environment.sh"
. "$TEST_DIR/.environment.sh"
"${TEST_DIR}/bin/check-requirements"
"$TEST_DIR/bin/check-requirements"
echo "Running tests..."
echo "DB_BACKEND: ${DB_BACKEND}"
echo "DB_BACKEND: $DB_BACKEND"
if [[ -z "$TEST_COVERAGE" ]]; then
echo "Coverage report: no"
else
@ -24,23 +24,23 @@ fi
[[ -f "$LOCAL_INIT_DIR/.lock" ]] && die "init data is locked: are you doing some manual test? if so, please finish what you are doing, run 'instance-data unlock' and retry"
dump_backend="$(cat "${LOCAL_INIT_DIR}/.backend")"
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}'"
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" \
"$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" \
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"
"$TEST_DIR/bats" "$TEST_DIR/dyn-bats"
fi