test: restructure dir layout
Attempt to clarify the structure of our tests. Each test case is now encapsulated in a script in `test/cases`. Each of these scripts should be runnable on a pristine machine and be independent of each other. It is up to the test-orchestractor to decide if they should be run consequtively instance, or in parallel on separate instances. Each script can execute several tests and call whatever helper binaries is desired. However, each case should be assumed to always run as one.
This commit is contained in:
parent
d7247e2878
commit
3c7f61c322
48 changed files with 31 additions and 33 deletions
61
test/cases/base_tests.sh
Executable file
61
test/cases/base_tests.sh
Executable file
|
|
@ -0,0 +1,61 @@
|
|||
#!/bin/bash
|
||||
set -euo pipefail
|
||||
|
||||
WORKING_DIRECTORY=/usr/libexec/osbuild-composer
|
||||
TESTS_PATH=/usr/libexec/osbuild-composer-test
|
||||
|
||||
PASSED_TESTS=()
|
||||
FAILED_TESTS=()
|
||||
|
||||
TEST_CASES=(
|
||||
"osbuild-weldr-tests"
|
||||
"osbuild-dnf-json-tests"
|
||||
"osbuild-composer-cli-tests"
|
||||
"osbuild-auth-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
|
||||
}
|
||||
|
||||
# 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 tests were executed and any of them failed.
|
||||
if [ ${#PASSED_TESTS[@]} -gt 0 ] && [ ${#FAILED_TESTS[@]} -eq 0 ]; then
|
||||
echo "🎉 All tests passed."
|
||||
exit 0
|
||||
else
|
||||
echo "🔥 One or more tests failed."
|
||||
exit 1
|
||||
fi
|
||||
Loading…
Add table
Add a link
Reference in a new issue