From ca488d8eb4af7676e5efc760a8b034e0d3615620 Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Fri, 15 Jan 2021 11:23:49 -0800 Subject: [PATCH] tests/rootless.sh: use set -e -u -o pipefail Currently, set -e ("exit on error") is only set before running tests. The bad consequence is the script may fail to set up test environment but will still run the tests. Use "set -e -u -o pipefail" for the whole script to catch potential issues with test setup and/or the script itself. Note we have to set RUNC_USE_SYSTEMD to an empty value if it is unset, so that the subsequent checks like [ -z "$RUNC_USE_SYSTEMD" ] won't trigger a "unbound variable" errors. Signed-off-by: Kir Kolyshkin --- tests/rootless.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/rootless.sh b/tests/rootless.sh index 70623659300..ced022012bc 100755 --- a/tests/rootless.sh +++ b/tests/rootless.sh @@ -19,6 +19,9 @@ # a new feature, please match the existing style. Add an entry to $ALL_FEATURES, # and add an enable_* and disable_* hook. +set -e -u -o pipefail +[ -v RUNC_USE_SYSTEMD ] || RUNC_USE_SYSTEMD= + ALL_FEATURES=("idmap" "cgroup") # cgroup is managed by systemd when RUNC_USE_SYSTEMD is set if [[ -n "${RUNC_USE_SYSTEMD}" ]]; then @@ -150,6 +153,7 @@ features_powerset="$(powerset "${ALL_FEATURES[@]}")" # Iterate over the powerset of all features. IFS=: +idx=0 for enabled_features in $features_powerset; do idx="$(($idx + 1))" echo "[$(printf '%.2d' "$idx")] run rootless tests ... (${enabled_features%%+})" @@ -162,7 +166,6 @@ for enabled_features in $features_powerset; do done # Run the test suite! - set -e echo path: $PATH export ROOTLESS_FEATURES="$enabled_features" if [[ -n "${RUNC_USE_SYSTEMD}" ]]; then @@ -173,6 +176,5 @@ for enabled_features in $features_powerset; do else sudo -HE -u rootless PATH="$PATH" $(which bats) -t "$ROOT/tests/integration$ROOTLESS_TESTPATH" fi - set +e cleanup done