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 <kolyshkin@gmail.com>
This commit is contained in:
Kir Kolyshkin
2022-02-08 16:09:31 -08:00
parent 9e2a0463e5
commit 7da77d802e
2 changed files with 9 additions and 1 deletions
+7
View File
@@ -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 ]
+2 -1
View File
@@ -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.