From 72ee54918faef6080e3b128e0135a23cbf017fcc Mon Sep 17 00:00:00 2001 From: Aleksa Sarai Date: Tue, 10 May 2016 22:14:50 +1000 Subject: [PATCH] integration: add requires() function This is similar to the testRequires() function in the Docker test suite. Signed-off-by: Aleksa Sarai --- tests/integration/checkpoint.bats | 4 +--- tests/integration/helpers.bash | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/tests/integration/checkpoint.bats b/tests/integration/checkpoint.bats index 1cac3c15..97194d03 100644 --- a/tests/integration/checkpoint.bats +++ b/tests/integration/checkpoint.bats @@ -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 diff --git a/tests/integration/helpers.bash b/tests/integration/helpers.bash index bd4abf51..c2678890 100644 --- a/tests/integration/helpers.bash +++ b/tests/integration/helpers.bash @@ -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