integration: add requires() function

This is similar to the testRequires() function in the Docker test suite.

Signed-off-by: Aleksa Sarai <asarai@suse.de>
This commit is contained in:
Aleksa Sarai 2016-05-10 22:14:50 +10:00
parent 4fd8a7aafa
commit 72ee54918f
2 changed files with 25 additions and 3 deletions

View File

@ -12,9 +12,7 @@ function teardown() {
}
@test "checkpoint and restore" {
if [ ! -e "$CRIU" ] ; then
skip
fi
requires criu
# criu does not work with external terminals so..
# setting terminal and root:readonly: to false

View File

@ -33,10 +33,34 @@ function runc() {
run __runc "$@"
}
# Raw wrapper for runc.
function __runc() {
"$RUNC" --root "$ROOT" "$@"
}
# Fails the current test, providing the error given.
function fail() {
echo "$@" >&2
exit 1
}
# Allows a test to specify what things it requires. If the environment can't
# support it, the test is skipped with a message.
function requires() {
for var in "$@"; do
case $var in
criu)
if [ ! -e "$CRIU" ]; then
skip "Test requires ${var}."
fi
;;
*)
fail "BUG: Invalid requires ${var}."
;;
esac
done
}
# Retry a command $1 times until it succeeds. Wait $2 seconds between retries.
function retry() {
local attempts=$1