From 588b7a100abbf98079d6f6bc5f0bed0b79ef99aa Mon Sep 17 00:00:00 2001 From: Akihiro Suda Date: Mon, 28 Oct 2024 11:56:35 +0900 Subject: [PATCH] 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 --- pkg/testutil/helpers.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/pkg/testutil/helpers.go b/pkg/testutil/helpers.go index ec7246c33..6d2523fec 100644 --- a/pkg/testutil/helpers.go +++ b/pkg/testutil/helpers.go @@ -33,7 +33,17 @@ const umountflags int = 0 var rootEnabled bool 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.