Skip to content

Commit

Permalink
Add nil context test case
Browse files Browse the repository at this point in the history
  • Loading branch information
josephwoodward committed Oct 28, 2022
1 parent e390757 commit 4ea32cb
Showing 1 changed file with 36 additions and 21 deletions.
57 changes: 36 additions & 21 deletions client/opentelemetry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,43 @@ func Test_OpenTelemetryRuntime_submit(t *testing.T) {
assertOpenTelemetrySubmit(t, testOperation(ctx), exporter, 1)
}

// func Test_OpenTelemetryRuntime_submit_nilAuthInfo(t *testing.T) {
// t.Parallel()
// tracer := mocktracer.New()
// _, ctx := opentracing.StartSpanFromContextWithTracer(context.Background(), tracer, "op")
// operation := testOperation(ctx)
// operation.AuthInfo = nil
// testOpenTelemetrySubmit(t, operation, tracer, 1)
// }
func Test_OpenTelemetryRuntime_submit_nilAuthInfo(t *testing.T) {
t.Parallel()

// func Test_OpenTelemetryRuntime_submit_nilContext(t *testing.T) {
// t.Parallel()
// tracer := mocktracer.New()
// _, ctx := opentracing.StartSpanFromContextWithTracer(context.Background(), tracer, "op")
// operation := testOperation(ctx)
// operation.Context = nil
// testOpenTelemetrySubmit(t, operation, tracer, 0) // just don't panic
// }
exporter := tracetest.NewInMemoryExporter()

tp := tracesdk.NewTracerProvider(
tracesdk.WithSampler(tracesdk.AlwaysSample()),
tracesdk.WithSyncer(exporter),
)

otel.SetTracerProvider(tp)

tracer := tp.Tracer("go-runtime")
ctx, _ := tracer.Start(context.Background(), "op")

operation := testOperation(ctx)
operation.AuthInfo = nil
assertOpenTelemetrySubmit(t, operation, exporter, 1)
}

func Test_OpenTelemetryRuntime_submit_nilContext(t *testing.T) {
exporter := tracetest.NewInMemoryExporter()

tp := tracesdk.NewTracerProvider(
tracesdk.WithSampler(tracesdk.AlwaysSample()),
tracesdk.WithSyncer(exporter),
)

otel.SetTracerProvider(tp)

tracer := tp.Tracer("go-runtime")
ctx, _ := tracer.Start(context.Background(), "op")
operation := testOperation(ctx)
operation.Context = nil

assertOpenTelemetrySubmit(t, operation, exporter, 0) // just don't panic
}

// func Test_injectOpenTelemetrySpanContext(t *testing.T) {
// t.Parallel()
Expand All @@ -69,11 +89,6 @@ func assertOpenTelemetrySubmit(t *testing.T, operation *runtime.ClientOperation,
"remote_host",
[]trace.SpanStartOption{})

// // opentracing.Tag{
// Key: string(ext.PeerService),
// Value: "service",
// }

_, err := r.Submit(operation)
require.NoError(t, err)

Expand Down

0 comments on commit 4ea32cb

Please sign in to comment.