Blame test/cases/base_tests.sh

Packit Service 509fd4
#!/bin/bash
Packit Service 509fd4
set -euo pipefail
Packit Service 509fd4
Packit Service 509fd4
WORKING_DIRECTORY=/usr/libexec/osbuild-composer
Packit Service 509fd4
TESTS_PATH=/usr/libexec/osbuild-composer-test
Packit Service 509fd4
mkdir --parents /tmp/logs
Packit Service 509fd4
LOGS_DIRECTORY=$(mktemp --directory --tmpdir=/tmp/logs)
Packit Service 509fd4
Packit Service 509fd4
PASSED_TESTS=()
Packit Service 509fd4
FAILED_TESTS=()
Packit Service 509fd4
Packit Service 509fd4
TEST_CASES=(
Packit Service 509fd4
  "osbuild-weldr-tests"
Packit Service 509fd4
  "osbuild-dnf-json-tests"
Packit Service 509fd4
  "osbuild-composer-cli-tests"
Packit Service 509fd4
  "osbuild-auth-tests"
Packit Service 509fd4
)
Packit Service 509fd4
Packit Service 509fd4
# Print out a nice test divider so we know when tests stop and start.
Packit Service 509fd4
test_divider () {
Packit Service 509fd4
    printf "%0.s-" {1..78} && echo
Packit Service 509fd4
}
Packit Service 509fd4
Packit Service 509fd4
# Run a test case and store the result as passed or failed.
Packit Service 509fd4
run_test_case () {
Packit Service 509fd4
    TEST_NAME=$(basename "$1")
Packit Service 509fd4
    echo
Packit Service 509fd4
    test_divider
Packit Service 509fd4
    echo "🏃🏻 Running test: ${TEST_NAME}"
Packit Service 509fd4
    test_divider
Packit Service 509fd4
Packit Service 509fd4
    if sudo "${1}" -test.v | tee "${LOGS_DIRECTORY}"/"${TEST_NAME}".log; then
Packit Service 509fd4
        PASSED_TESTS+=("$TEST_NAME")
Packit Service 509fd4
    else
Packit Service 509fd4
        FAILED_TESTS+=("$TEST_NAME")
Packit Service 509fd4
    fi
Packit Service 509fd4
Packit Service 509fd4
    test_divider
Packit Service 509fd4
    echo
Packit Service 509fd4
}
Packit Service 509fd4
Packit Service 509fd4
Packit Service 509fd4
# Provision the software under tet.
Packit Service 509fd4
/usr/libexec/osbuild-composer-test/provision.sh
Packit Service 509fd4
Packit Service 509fd4
# Change to the working directory.
Packit Service 509fd4
cd $WORKING_DIRECTORY
Packit Service 509fd4
Packit Service 509fd4
# Run each test case.
Packit Service 509fd4
for TEST_CASE in "${TEST_CASES[@]}"; do
Packit Service 509fd4
    run_test_case ${TESTS_PATH}/"$TEST_CASE"
Packit Service 509fd4
done
Packit Service 509fd4
Packit Service 509fd4
# Print a report of the test results.
Packit Service 509fd4
test_divider
Packit Service 509fd4
echo "😃 Passed tests:" "${PASSED_TESTS[@]}"
Packit Service 509fd4
echo "☹ Failed tests:" "${FAILED_TESTS[@]}"
Packit Service 509fd4
test_divider
Packit Service 509fd4
Packit Service 509fd4
# Exit with a failure if tests were executed and any of them failed.
Packit Service 509fd4
if [ ${#PASSED_TESTS[@]} -gt 0 ] && [ ${#FAILED_TESTS[@]} -eq 0 ]; then
Packit Service 509fd4
    echo "🎉 All tests passed."
Packit Service 509fd4
    exit 0
Packit Service 509fd4
else
Packit Service 509fd4
    echo "🔥 One or more tests failed."
Packit Service 509fd4
    exit 1
Packit Service 509fd4
fi