DRY when setting up, running & parsing results for beakerlib tests

Cherry-picked from b197e448ff

Related: rhbz#1769525
This commit is contained in:
Alexander Todorov 2019-11-06 14:24:30 +02:00 committed by Alexander Todorov
parent bb4b6b7059
commit 3409d0a949
3 changed files with 39 additions and 39 deletions

View File

@ -19,6 +19,35 @@ if [ "$COMPOSER_TEST_FAIL_FAST" == "1" ]; then
} }
fi fi
setup_beakerlib_env() {
export BEAKERLIB_DIR=$(mktemp -d /tmp/composer-test.XXXXXX)
export BEAKERLIB_JOURNAL=0
}
run_beakerlib_tests() {
if [ -z "$*" ]; then
echo "run_beakerlib_tests() requires a test to execute"
else
# execute tests
for TEST in "$@"; do
$TEST
done
fi
}
parse_beakerlib_results() {
. $BEAKERLIB_DIR/TestResults
TESTRESULT_RESULT_ECODE="${TESTRESULT_RESULT_ECODE:-}"
if [ $TESTRESULT_RESULT_ECODE != 0 ]; then
echo "Test failed. Leaving log in $BEAKERLIB_DIR"
exit $TESTRESULT_RESULT_ECODE
fi
rm -rf $BEAKERLIB_DIR
}
export QEMU_BIN="/usr/libexec/qemu-kvm" export QEMU_BIN="/usr/libexec/qemu-kvm"
export QEMU="$QEMU_BIN -machine accel=kvm:tcg" export QEMU="$QEMU_BIN -machine accel=kvm:tcg"
export SSH_PORT=2222 export SSH_PORT=2222

View File

@ -1,11 +1,12 @@
#!/bin/bash #!/bin/bash
# Note: execute this file from the project root directory # Note: execute this file from the project root directory
# Note: Use test/check-cli && test/check-cloud if you want to
# execute test scenarios by hand!
set -eu set -eu
. $(dirname $0)/cli/lib/lib.sh . $(dirname $0)/cli/lib/lib.sh
export BEAKERLIB_DIR=$(mktemp -d /tmp/composer-test.XXXXXX)
CLI="${CLI:-}" CLI="${CLI:-}"
function setup_tests { function setup_tests {
@ -105,20 +106,9 @@ if [ -e "/var/tmp/test-results" ]; then
rm -rf "/var/tmp/test-results" rm -rf "/var/tmp/test-results"
fi fi
export BEAKERLIB_JOURNAL=0 setup_beakerlib_env
export PATH="/usr/local/bin:$PATH"
if [ -z "$*" ]; then
# invoke cli/ tests which can be executed without special preparation
./tests/cli/test_blueprints_sanity.sh
./tests/cli/test_compose_sanity.sh
else
# execute other cli tests which need more adjustments in the calling environment
# or can't be executed inside Travis CI
for TEST in "$@"; do
$TEST
done
fi
run_beakerlib_tests "$@"
if [ -z "$CLI" ]; then if [ -z "$CLI" ]; then
# stop lorax-composer and remove /run/weldr/api.socket # stop lorax-composer and remove /run/weldr/api.socket
@ -133,11 +123,4 @@ else
composer_start composer_start
fi fi
. $BEAKERLIB_DIR/TestResults parse_beakerlib_results
if [ $TESTRESULT_RESULT_ECODE != 0 ]; then
echo "Test failed. Leaving log in $BEAKERLIB_DIR"
exit $TESTRESULT_RESULT_ECODE
fi
rm -rf $BEAKERLIB_DIR

View File

@ -1,26 +1,14 @@
#!/bin/bash #!/bin/bash
# Note: execute this file from the project root directory # Note: execute this file from the project root directory
# Used for running a beakerlib test script inside a running VM
# without setting up composer first!
set -eu set -eu
. $(dirname $0)/cli/lib/lib.sh . $(dirname $0)/cli/lib/lib.sh
export BEAKERLIB_DIR=$(mktemp -d /tmp/composer-test.XXXXXX) setup_beakerlib_env
export BEAKERLIB_JOURNAL=0
if [ -z "$*" ]; then
echo "test_image.sh requires a test to execute"
else
# execute tests
for TEST in "$@"; do
$TEST
done
fi
. $BEAKERLIB_DIR/TestResults run_beakerlib_tests "$@"
if [ $TESTRESULT_RESULT_ECODE != 0 ]; then parse_beakerlib_results
echo "Test failed. Leaving log in $BEAKERLIB_DIR"
exit $TESTRESULT_RESULT_ECODE
fi
rm -rf $BEAKERLIB_DIR