From 7da77d802e5734b76b8bd7d9a76c51690de8e3b4 Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Tue, 8 Feb 2022 16:09:31 -0800 Subject: [PATCH] tests/int: don't add --root if $ROOT is not set Some tests (those in help.bats and version.bats) do not use setup_bundle (as they do not need to start any containers), and thus they do not set $ROOT. As a consequence, these tests now call "runc --root /state" which is not nice. Make adding --root conditional (only if $ROOT is set). Amazingly, this change breaks help.bats tests under rootless, because "sudo rootless" does not change the value of XDG_RUNTIME_DIR which still points to root-owned directory, and as a result we have this: > runc foo -h (status=1): > the path in $XDG_RUNTIME_DIR must be writable by the user > time="2022-02-08T07:04:57Z" level=error msg="mkdir /run/user/0/runc: permission denied" This could be fixed by adding proper $ROOT, but it's easier just to skip those tests under non-root. NOTE that version.bats is not broken because -v is handled by urfave/cli very early, so app.Before function is not run. Signed-off-by: Kir Kolyshkin --- tests/integration/help.bats | 7 +++++++ tests/integration/helpers.bash | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/tests/integration/help.bats b/tests/integration/help.bats index c512d7a9e..04bbc80cf 100644 --- a/tests/integration/help.bats +++ b/tests/integration/help.bats @@ -2,6 +2,13 @@ load helpers +function setup() { + # It does not make sense to repeat these trivial tests for non-root. + # Also, they fail due to $ROOT not being set and XDG_RUNTIME_DIR + # pointing to another user's directory after sudo rootless. + requires root +} + @test "runc -h" { runc -h [ "$status" -eq 0 ] diff --git a/tests/integration/helpers.bash b/tests/integration/helpers.bash index 91cd9967c..bc6bf4b98 100644 --- a/tests/integration/helpers.bash +++ b/tests/integration/helpers.bash @@ -54,7 +54,8 @@ function runc() { # Raw wrapper for runc. function __runc() { - "$RUNC" ${RUNC_USE_SYSTEMD+--systemd-cgroup} --root "$ROOT/state" "$@" + "$RUNC" ${RUNC_USE_SYSTEMD+--systemd-cgroup} \ + ${ROOT:+--root "$ROOT/state"} "$@" } # Wrapper for runc spec.