1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2025-11-23 22:34:47 +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:
Flc゛
2025-09-23 15:52:45 +08:00
committed by GitHub
parent 2389f4488f
commit 80cb909774
106 changed files with 763 additions and 778 deletions

View File

@@ -4,7 +4,6 @@
package trace
import (
"context"
"testing"
)
@@ -24,7 +23,7 @@ func TestNoopTracerProviderTracer(t *testing.T) {
}
func TestNoopTracerStart(t *testing.T) {
ctx := context.Background()
ctx := t.Context()
tracer := NewNoopTracerProvider().Tracer("test instrumentation")
var span Span
@@ -48,7 +47,7 @@ func TestNoopTracerStart(t *testing.T) {
func TestNoopSpan(t *testing.T) {
tracer := NewNoopTracerProvider().Tracer("test instrumentation")
_, s := tracer.Start(context.Background(), "test span")
_, s := tracer.Start(t.Context(), "test span")
span := s.(noopSpan)
if got, want := span.SpanContext(), (SpanContext{}); !assertSpanContextEqual(got, want) {
@@ -71,7 +70,7 @@ func TestNonRecordingSpanTracerStart(t *testing.T) {
}
sc := NewSpanContext(SpanContextConfig{TraceID: tid, SpanID: sid})
ctx := ContextWithSpanContext(context.Background(), sc)
ctx := ContextWithSpanContext(t.Context(), sc)
_, span := NewNoopTracerProvider().Tracer("test instrumentation").Start(ctx, "span1")
if got, want := span.SpanContext(), sc; !assertSpanContextEqual(got, want) {