Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CmdSuite.TestContext failure with go 1.21 #110

Open
gibmat opened this issue Nov 11, 2023 · 1 comment
Open

CmdSuite.TestContext failure with go 1.21 #110

gibmat opened this issue Nov 11, 2023 · 1 comment

Comments

@gibmat
Copy link

gibmat commented Nov 11, 2023

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"))
@SimonRichardson
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants