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

Cherry-picked from b197e448ff

Related: rhbz#1770193
This commit is contained in:
Alexander Todorov 2019-11-06 14:24:30 +02:00 committed by Brian C. Lane
parent 3d3c32819c
commit 92535addc8
3 changed files with 39 additions and 39 deletions

View File

@ -19,6 +19,35 @@ if [ "$COMPOSER_TEST_FAIL_FAST" == "1" ]; then
}
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="$QEMU_BIN -machine accel=kvm:tcg"
export SSH_PORT=2222

View File

@ -1,11 +1,12 @@
#!/bin/bash
# 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
. $(dirname $0)/cli/lib/lib.sh
export BEAKERLIB_DIR=$(mktemp -d /tmp/composer-test.XXXXXX)
CLI="${CLI:-}"
function setup_tests {
@ -105,20 +106,9 @@ if [ -e "/var/tmp/test-results" ]; then
rm -rf "/var/tmp/test-results"
fi
export BEAKERLIB_JOURNAL=0
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
setup_beakerlib_env
run_beakerlib_tests "$@"
if [ -z "$CLI" ]; then
# stop lorax-composer and remove /run/weldr/api.socket
@ -133,11 +123,4 @@ else
composer_start
fi
. $BEAKERLIB_DIR/TestResults
if [ $TESTRESULT_RESULT_ECODE != 0 ]; then
echo "Test failed. Leaving log in $BEAKERLIB_DIR"
exit $TESTRESULT_RESULT_ECODE
fi
rm -rf $BEAKERLIB_DIR
parse_beakerlib_results

View File

@ -1,26 +1,14 @@
#!/bin/bash
# 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
. $(dirname $0)/cli/lib/lib.sh
export BEAKERLIB_DIR=$(mktemp -d /tmp/composer-test.XXXXXX)
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
setup_beakerlib_env
. $BEAKERLIB_DIR/TestResults
run_beakerlib_tests "$@"
if [ $TESTRESULT_RESULT_ECODE != 0 ]; then
echo "Test failed. Leaving log in $BEAKERLIB_DIR"
exit $TESTRESULT_RESULT_ECODE
fi
rm -rf $BEAKERLIB_DIR
parse_beakerlib_results