Skip to content

Commit

Permalink
testutil: make test.root NOP
Browse files Browse the repository at this point in the history
This flag is not actually needed and can be replaced by checking `os.Geteuid() == 0`.

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
  • Loading branch information
AkihiroSuda committed Oct 28, 2024
1 parent 2fab5e9 commit 6671e3f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
8 changes: 5 additions & 3 deletions testutil/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ import (
"flag"
)

var rootEnabled bool

func init() {
flag.BoolVar(&rootEnabled, "test.root", false, "enable tests that require root")
if flag.Lookup("test.root") == nil { // avoid conflict with containerd testutil
var dummy bool
// Register this dummy flag for compatibility with existing test scripts
flag.BoolVar(&dummy, "test.root", false, "(Ignored)")
}
}
4 changes: 0 additions & 4 deletions testutil/helpers_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ func Unmount(t *testing.T, mountPoint string) {
// RequiresRoot skips tests that require root, unless the test.root flag has
// been set
func RequiresRoot(t testing.TB) {
if !rootEnabled {
t.Skip("skipping test that requires root")
return
}
if os.Getuid() != 0 {
t.Error("This test must be run as root.")
}
Expand Down

0 comments on commit 6671e3f

Please sign in to comment.