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 <akihiro.suda.cz@hco.ntt.co.jp>
This commit is contained in:
Akihiro Suda 2024-10-28 11:56:35 +09:00
parent 181491032d
commit 588b7a100a
No known key found for this signature in database
GPG Key ID: 49524C6F9F638F1A

View File

@ -33,7 +33,17 @@ const umountflags int = 0
var rootEnabled bool var rootEnabled bool
func init() { func init() {
flag.BoolVar(&rootEnabled, "test.root", false, "enable tests that require root") if flag.Lookup("test.root") == nil {
flag.BoolVar(&rootEnabled, "test.root", false, "enable tests that require root")
} else {
// The flag is already registered by continuity/testutil
for _, f := range os.Args {
if f == "-test.root" || f == "-test.root=true" {
rootEnabled = true
break
}
}
}
} }
// DumpDir prints the contents of the directory to the testing logger. // DumpDir prints the contents of the directory to the testing logger.