You've already forked opentelemetry-go
mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2025-11-29 23:07:45 +02:00
refactor: replace context.Background() with t.Context()/b.Context() in tests (#7352)
Based on the Go version we currently use, the dependency already supports 1.24+, which allows using `t.Context()` and `b.Context()` in unit tests and benchmarks respectively. - Enable `context-background` and `context-todo` in [`usetesting`](https://golangci-lint.run/docs/linters/configuration/#usetesting) - Adjust the code to support linter detection --------- Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com> Co-authored-by: Tyler Yahn <codingalias@gmail.com> Co-authored-by: Damien Mathieu <42@dmathieu.com>
This commit is contained in:
@@ -57,7 +57,7 @@ func TestConfigReaderSignalsEmpty(t *testing.T) {
|
||||
require.NotNil(t, f)
|
||||
require.NotNil(t, s)
|
||||
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
assert.NoError(t, f(ctx))
|
||||
assert.NoError(t, s(ctx))
|
||||
assert.ErrorIs(t, s(ctx), ErrReaderShutdown)
|
||||
@@ -81,7 +81,7 @@ func TestConfigReaderSignalsForwarded(t *testing.T) {
|
||||
require.NotNil(t, f)
|
||||
require.NotNil(t, s)
|
||||
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
assert.NoError(t, f(ctx))
|
||||
assert.NoError(t, f(ctx))
|
||||
assert.NoError(t, s(ctx))
|
||||
@@ -102,7 +102,7 @@ func TestConfigReaderSignalsForwardedErrors(t *testing.T) {
|
||||
require.NotNil(t, f)
|
||||
require.NotNil(t, s)
|
||||
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
assert.ErrorIs(t, f(ctx), assert.AnError)
|
||||
assert.ErrorIs(t, s(ctx), assert.AnError)
|
||||
assert.ErrorIs(t, s(ctx), ErrReaderShutdown)
|
||||
@@ -118,7 +118,7 @@ func TestUnifyMultiError(t *testing.T) {
|
||||
func(context.Context) error { return e0 },
|
||||
func(context.Context) error { return e1 },
|
||||
func(context.Context) error { return e2 },
|
||||
})(context.Background())
|
||||
})(t.Context())
|
||||
assert.ErrorIs(t, err, e0)
|
||||
assert.ErrorIs(t, err, e1)
|
||||
assert.ErrorIs(t, err, e2)
|
||||
@@ -299,8 +299,8 @@ func TestWithExemplarFilterOff(t *testing.T) {
|
||||
}
|
||||
c := newConfig(tc.opts)
|
||||
assert.NotNil(t, c.exemplarFilter)
|
||||
assert.Equal(t, tc.expectFilterNotSampled, c.exemplarFilter(context.Background()))
|
||||
assert.Equal(t, tc.expectFilterSampled, c.exemplarFilter(sample(context.Background())))
|
||||
assert.Equal(t, tc.expectFilterNotSampled, c.exemplarFilter(t.Context()))
|
||||
assert.Equal(t, tc.expectFilterSampled, c.exemplarFilter(sample(t.Context())))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user