kabi-dw/tests/sanity/runtest.sh
2023-06-29 10:08:23 +02:00

132 lines
2.9 KiB
Bash
Executable File

#!/usr/bin/env bash
function cleanup()
{
rlPhaseStartCleanup
rm -rf "${TEMPFILES[@]}"
rlPhaseEnd
}
trap cleanup 0 1 9 15
# --- Globals -----------------------------------------------------------------
SCRIPT_ROOT="$(dirname "$(realpath "${BASH_SOURCE[0]}")")"
# A list of temporary files; used by cleanup to delete on signals 0 1 9 15.
TEMPFILES=()
# A list of dependencies to include.
INCLUDES=()
# A list of files containing test definitions.
# These are auto-discovered using test-*.sh pattern.
TESTS_FILES=()
# A list of tests to run.
# These are automatically added by test files.
TESTS=()
# --- Initialization ----------------------------------------------------------
# Requires: restraint-rhts
. /usr/bin/rhts-environment.sh || exit 1
# Requires: beakerlib
. /usr/share/beakerlib/beakerlib.sh || exit 1
INCLUDES+=("$SCRIPT_ROOT/common-tests.sh")
TESTS_FILES+=("$SCRIPT_ROOT/test-"*".sh")
# --- bkr journal -------------------------------------------------------------
rlJournalStart
rlPhaseStartSetup
# --- Load dependencies -------------------------------------------------------
for path in ${INCLUDES[@]} ${TESTS_FILES[@]}
do
if ! test -r $path
then
rlFail "Path \`$path' does not exist or is not readable"
exit 1
fi
source $path && {
rlPass "File \`$(basename "$path")' loaded."
} || {
rlFail "Unable to load \`$path'."
exit 1
}
done
# --- Temporary files ---------------------------------------------------------
echo ":: Initialization: Temporary files."
__stdout_log=$(mktemp -p /tmp kabidw-test-stdout.XXXXX)
TEMPFILES+=("$__stdout_log")
__stderr_log=$(mktemp -p /tmp kabidw-test-stderr.XXXXX)
TEMPFILES+=("$__stderr_log")
# --- Evaluate RPM-specific macros --------------------------------------------
# This is required not to hardcode kabidw install location should %{_bindir} and
# %{_datadir} be changed.
echo ":: Initialization: Evaluating RPM macros."
if test -z "$RPM_BIN_DIR"
then
RPM_BIN_DIR="$(rpm --eval '%{_bindir}')"
echo " * RPM %{_bindir} determined as: $RPM_BIN_DIR"
fi
if test -z "$RPM_DATA_DIR"
then
RPM_DATA_DIR="$(rpm --eval '%{_datadir}')"
echo " * RPM %{_datadir} determined as: $RPM_DATA_DIR"
fi
# --- Determine kabidw location --------------------------------------------------
if test -z "$KABI_DW_BIN"
then
KABI_DW_BIN="$RPM_BIN_DIR/kabi-dw"
echo ":: kabidw path determined as: $KABI_DW_BIN"
fi
rlPass "Initialization passed."
rlPhaseEnd
# --- Run tests ---------------------------------------------------------------
overall_status=0
for test in ${TESTS[@]}
do
run_test $test "$__stdout_log" "$__stderr_log"
if test $? -gt 0
then
overall_status=1
fi
done
rlPhaseStartTest
if test $overall_status -gt 0
then
rlFail "Some tests failed."
exit 1
else
rlPass "All tests passed."
fi
echo
rlPhaseEnd
rlJournalPrintText
rlJournalEnd