What do you call your second ctx variable?

What do you call your second ctx variable?

I’m making a switch to context.Context across our codebase. But there’s a problem in the tests. A few of the tests have a testContext that holds a bunch of important objects for the test to examine, and the variable it goes in is named ctx.

Which means I can’t:

var log = blog.UseMock()
var ctx = context.Background()

because they’re both named ctx. I considered contxt but that looks really weird.

Could rename our custom object. Suggestions?

Editors and IDEs have auto completion these days. Go for readability: testCtx, testEnv, etc.
Names that would make it easier to understand the code a few months after it is written or for new devs getting up to speed.

Yep, we decided on testCtx for the return from setup().

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.