Convert base test runner to bash

Simplify the base test runner and make it easier to see the output live.

Signed-off-by: Major Hayden <major@redhat.com>
This commit is contained in:
Major Hayden 2020-06-10 16:55:20 -05:00 committed by Ondřej Budai
parent 3d488385ff
commit d953e5ea18
2 changed files with 65 additions and 1 deletions

View file

@ -324,7 +324,7 @@ void run_tests(test_type) {
if (test_type == 'base') {
sh (
label: "Base tests",
script: "ansible-playbook -e workspace=${WORKSPACE} -e test_type=base -i hosts.ini schutzbot/test.yml"
script: "schutzbot/run_base_tests.sh"
)
}

64
schutzbot/run_base_tests.sh Executable file
View file

@ -0,0 +1,64 @@
#!/bin/bash
set -euo pipefail
WORKING_DIRECTORY=/usr/libexec/osbuild-composer
TESTS_PATH=/usr/libexec/tests/osbuild-composer
PASSED_TESTS=()
FAILED_TESTS=()
TEST_CASES=(
"osbuild-rcm-tests"
"osbuild-weldr-tests"
"osbuild-dnf-json-tests"
"osbuild-tests"
)
# Print out a nice test divider so we know when tests stop and start.
test_divider () {
printf "%0.s-" {1..78} && echo
}
# Run a test case and store the result as passed or failed.
run_test_case () {
TEST_NAME=$(basename $1)
echo
test_divider
echo "🏃🏻 Running test: ${TEST_NAME}"
test_divider
if sudo ${1} -test.v | tee ${WORKSPACE}/${TEST_NAME}.log; then
PASSED_TESTS+=($TEST_NAME)
else
FAILED_TESTS+=($TEST_NAME)
fi
test_divider
echo
}
# Ensure osbuild-composer-tests is installed.
sudo dnf -y install osbuild-composer-tests
# Change to the working directory.
cd $WORKING_DIRECTORY
# Run each test case.
for TEST_CASE in "${TEST_CASES[@]}"; do
run_test_case ${TESTS_PATH}/$TEST_CASE
done
# Print a report of the test results.
test_divider
echo "😃 Passed tests: ${PASSED_TESTS[@]}"
echo "☹ Failed tests: ${FAILED_TESTS[@]}"
test_divider
# Exit with a failure if any tests failed.
if [ ${#FAILED_TESTS[@]} -eq 0 ]; then
echo "🎉 All tests passed."
exit 0
else
echo "🔥 One or more tests failed."
exit 1
fi