Skip to content

CmdSuite.TestContext failure with go 1.21 #110

Open
@gibmat

Description

@gibmat

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"))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions