In our own project, we have set up an util functoion TestContext(tb testing.TB) context.Context, that is used to retrieve the initial (backgrond) context used in tests. We let this context contain a logger that writes formatted output to the test instance (via t.Log(...)). A context is fetched at the start of each sub-test that calls code with takes a context parameter. We usezerolog` with a console logger for this.
I can probably replicate/copy this code to internal/testutil and replace context.Background() and context.TODO() in relevant tests.
The benifit of this, is that failing tests that runs code that produce log entries, get's easier to debug.
In our own project, we have set up an util functoion
TestContext(tb testing.TB) context.Context
, that is used to retrieve the initial (backgrond) context used in tests. We let this context contain a logger that writes formatted output to the test instance (viat.Log(...)
). A context is fetched at the start of each sub-test that calls code with takes a context parameter. We use
zerolog` with a console logger for this.I can probably replicate/copy this code to
internal/testutil
and replacecontext.Background()
andcontext.TODO()
in relevant tests.The benifit of this, is that failing tests that runs code that produce log entries, get's easier to debug.