cmd icon indicating copy to clipboard operation
cmd copied to clipboard

CmdSuite.TestContext failure with go 1.21

Open gibmat opened this issue 2 years ago • 1 comments

Running tests using go 1.21 results in a test failure:

	cd _build && go test -vet=off -v -p 16 github.com/juju/cmd github.com/juju/cmd/cmdtesting
=== RUN   TestPackage

----------------------------------------------------------------------
FAIL: cmd_test.go:41: CmdSuite.TestContext

cmd_test.go:42:
    c.Check(s.ctx.Context, jc.DeepEquals, context.Background())
... obtained context.todoCtx = context.todoCtx{emptyCtx:context.emptyCtx{}} ("context.TODO")
... expected context.backgroundCtx = context.backgroundCtx{emptyCtx:context.emptyCtx{}} ("context.Background")
... mismatch at top level: type mismatch context.todoCtx vs context.backgroundCtx; obtained context.todoCtx{emptyCtx:context.emptyCtx{}}; expected context.backgroundCtx{emptyCtx:context.emptyCtx{}}

OOPS: 122 passed, 1 FAILED
--- FAIL: TestPackage (0.07s)

Debian packaging has applied the following patch:

diff --git a/cmd_test.go b/cmd_test.go
index b4281f7..6df3bbb 100644
--- a/cmd_test.go
+++ b/cmd_test.go
@@ -39,7 +39,7 @@ func (s *CmdSuite) SetUpTest(c *gc.C) {
 }
 
 func (s *CmdSuite) TestContext(c *gc.C) {
-	c.Check(s.ctx.Context, jc.DeepEquals, context.Background())
+	c.Check(s.ctx.Context, jc.DeepEquals, context.TODO())
 	c.Check(s.ctx.AbsPath("/foo/bar"), gc.Equals, "/foo/bar")
 	c.Check(s.ctx.AbsPath("/foo/../bar"), gc.Equals, "/bar")
 	c.Check(s.ctx.AbsPath("foo/bar"), gc.Equals, filepath.Join(s.ctx.Dir, "foo/bar"))

gibmat avatar Nov 11 '23 14:11 gibmat

Thanks for this.

This is a bad test. We should test that it's assignable to a context. We don't care if it is a context.TODO vs context.Background in this particular instance.

SimonRichardson avatar Feb 08 '24 09:02 SimonRichardson