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

This commit is contained in:
Alexander Todorov 2019-10-22 07:59:21 -04:00 committed by Alexander Todorov
parent cb7e391792
commit b197e448ff
3 changed files with 37 additions and 38 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/bin/qemu-system-$(uname -m)"
export QEMU="$QEMU_BIN -machine accel=kvm:tcg"
export SSH_PORT=2222

View File

@ -5,7 +5,6 @@ set -eu
. $(dirname $0)/cli/lib/lib.sh
export BEAKERLIB_DIR=$(mktemp -d /tmp/composer-test.XXXXXX)
CLI="${CLI:-}"
function setup_tests {
@ -105,19 +104,9 @@ if [ -e "/var/tmp/test-results" ]; then
rm -rf "/var/tmp/test-results"
fi
export BEAKERLIB_JOURNAL=0
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
@ -132,11 +121,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