Skip to content

Commit 4bd411f

Browse files
AkihiroSudasondavidb
authored andcommitted
testutil: avoid conflict with continuity/testutil
``` === FAIL: core/metadata (0.00s) /tmp/go-build142702247/b1061/metadata.test flag redefined: test.root panic: /tmp/go-build142702247/b1061/metadata.test flag redefined: test.root goroutine 1 [running]: flag.(*FlagSet).Var(0xc0000d6000, {0x132a040, 0x190f3f3}, {0x11b4291, 0x9}, {0x11c7690, 0x1e}) /opt/hostedtoolcache/go/1.23.2/x64/src/flag/flag.go:1028 +0x54d flag.BoolVar(...) /opt/hostedtoolcache/go/1.23.2/x64/src/flag/flag.go:755 github.com/containerd/containerd/v2/pkg/testutil.init.0() /home/runner/work/containerd/containerd/pkg/testutil/helpers.go:36 +0x6b FAIL github.com/containerd/containerd/v2/core/metadata 0.028s ``` Signed-off-by: Akihiro Suda <[email protected]> (cherry picked from commit 588b7a1) Signed-off-by: David Son <[email protected]>
1 parent 2bb3c23 commit 4bd411f

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

pkg/testutil/helpers.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,17 @@ const umountflags int = 0
3333
var rootEnabled bool
3434

3535
func init() {
36-
flag.BoolVar(&rootEnabled, "test.root", false, "enable tests that require root")
36+
if flag.Lookup("test.root") == nil {
37+
flag.BoolVar(&rootEnabled, "test.root", false, "enable tests that require root")
38+
} else {
39+
// The flag is already registered by continuity/testutil
40+
for _, f := range os.Args {
41+
if f == "-test.root" || f == "-test.root=true" {
42+
rootEnabled = true
43+
break
44+
}
45+
}
46+
}
3747
}
3848

3949
// DumpDir prints the contents of the directory to the testing logger.

0 commit comments

Comments
 (0)