hack/bats: fix root/rootless logic
The ROOT{,LESS}_ONLY logic is confusing and unmaintainable.
Change it to an easier-to-read positive check.
@@ -63,8 +63,8 @@ chcon -t container_runtime_exec_t $PODMAN
TESTS=test/system
REMOTE=
-ROOT_ONLY=
-ROOTLESS_ONLY=
+TEST_ROOT=1
+TEST_ROOTLESS=1
declare -a bats_opts=()
@@ -74,8 +74,8 @@ for i;do
value=`expr "$i" : '[^=]*=\(.*\)'`
case "$i" in
-h|--help) echo "$usage"; exit 0;;
- --root) ROOT_ONLY=1 ;;
- --rootless) ROOTLESS_ONLY=1 ;;
+ --root) TEST_ROOTLESS= ;;
+ --rootless) TEST_ROOT= ;;
--remote) REMOTE=remote; echo "--remote is TBI"; exit 1;;
--ts|-T) bats_opts+=("-T") ;;
*/*.bats) TESTS=$i ;;
@@ -106,7 +106,7 @@ fi
export PODMAN_ROOTLESS_USER=$(id -un)
# Root
-if [ -z "$ROOTLESS_ONLY" ]; then
+if [[ "$TEST_ROOT" ]]; then
echo "# bats ${bats_filter[*]} $TESTS"
sudo --preserve-env=PODMAN \
--preserve-env=QUADLET \
@@ -119,7 +119,7 @@ if [ -z "$ROOTLESS_ONLY" ]; then
fi
# Rootless. (Only if we're not already root)
-if [[ -z "$ROOT_ONLY" && "$(id -u)" != 0 ]]; then
+if [[ "$TEST_ROOTLESS" && "$(id -u)" != 0 ]]; then
echo "--------------------------------------------------"
echo "\$ bats ${bats_filter[*]} $TESTS"
bats "${bats_opts[@]}" "${bats_filter[@]}" $TESTS
