Skip to content

Commit

Permalink
tests/rootless.sh: use set -e -u -o pipefail
Browse files Browse the repository at this point in the history
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 <kolyshkin@gmail.com>
  • Loading branch information
kolyshkin committed Jan 15, 2021
1 parent 6750ca8 commit ca488d8
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions tests/rootless.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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%%+})"
Expand All @@ -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
Expand All @@ -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

0 comments on commit ca488d8

Please sign in to comment.