Skip to content

Commit

Permalink
Add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
nhulston committed Nov 8, 2024
1 parent 488acf6 commit 4915d91
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions internal/extension/extension_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,34 @@ func TestExtensionEndInvocationError(t *testing.T) {
assert.Contains(t, logOutput, "could not send end invocation payload to the extension")
}

type mockSpanContext struct {
ddtrace.SpanContext
}

func (m mockSpanContext) TraceID() uint64 { return 123 }
func (m mockSpanContext) SpanID() uint64 { return 456 }
func (m mockSpanContext) SamplingPriority() (int, bool) { return -1, true }

type mockSpan struct{ ddtrace.Span }

func (m mockSpan) Context() ddtrace.SpanContext { return mockSpanContext{} }

func TestExtensionEndInvocationSamplingPriority(t *testing.T) {
headers := http.Header{}
em := &ExtensionManager{httpClient: capturingClient{hdr: headers}}
span := &mockSpan{}

// When priority in context, use that value
ctx := context.WithValue(context.Background(), DdTraceId, "123")
ctx = context.WithValue(ctx, DdSamplingPriority, "2")
em.SendEndInvocationRequest(ctx, span, ddtrace.FinishConfig{})
assert.Equal(t, "2", headers.Get("X-Datadog-Sampling-Priority"))

// When no context, get priority from span
em.SendEndInvocationRequest(context.Background(), span, ddtrace.FinishConfig{})
assert.Equal(t, "-1", headers.Get("X-Datadog-Sampling-Priority"))
}

type capturingClient struct {
hdr http.Header
}
Expand Down

0 comments on commit 4915d91

Please sign in to comment.