Skip to content
This repository has been archived by the owner on May 23, 2023. It is now read-only.

Commit

Permalink
Add a test for the TracerContextWithSpanExtension interface
Browse files Browse the repository at this point in the history
  • Loading branch information
krnowak committed Sep 6, 2019
1 parent c848a0f commit 60fbc08
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions gocontext_test.go
Expand Up @@ -29,6 +29,41 @@ func TestContextWithSpan(t *testing.T) {
}
}

type noopExtTracer struct {
NoopTracer
}

type noopExtTracerCtxType struct{}

func (noopExtTracer) ContextWithSpanHook(ctx context.Context, span Span) context.Context {
return context.WithValue(ctx, noopExtTracerCtxType{}, noopExtTracerCtxType{})
}

var _ Tracer = noopExtTracer{}
var _ TracerContextWithSpanExtension = noopExtTracer{}

type noopExtSpan struct {
noopSpan
}

func (noopExtSpan) Tracer() Tracer {
return noopExtTracer{}
}

var _ Span = noopExtSpan{}

func TestContextWithSpanWithExtension(t *testing.T) {
span := &noopExtSpan{}
ctx := ContextWithSpan(context.Background(), span)
span2 := SpanFromContext(ctx)
if span != span2 {
t.Errorf("Not the same span returned from context, expected=%+v, actual=%+v", span, span2)
}
if _, ok := ctx.Value(noopExtTracerCtxType{}).(noopExtTracerCtxType); !ok {
t.Error("ContextWithSpanHook was not called")
}
}

func TestStartSpanFromContext(t *testing.T) {
testTracer := testTracer{}

Expand Down

0 comments on commit 60fbc08

Please sign in to comment.