This repository has been archived by the owner on Mar 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests from API check suite (#47)
- Loading branch information
1 parent
7be4bbc
commit 4f57fa6
Showing
1 changed file
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package basictracer | ||
|
||
import ( | ||
"testing" | ||
|
||
ot "github.com/opentracing/opentracing-go" | ||
"github.com/opentracing/opentracing-go/harness" | ||
) | ||
|
||
// newTracer creates a new tracer for each test, and returns a nil cleanup function. | ||
func newTracer() (tracer ot.Tracer, closer func()) { | ||
tracer = NewWithOptions(Options{ | ||
Recorder: NewInMemoryRecorder(), | ||
ShouldSample: func(traceID uint64) bool { return true }, // always sample | ||
}) | ||
return tracer, nil | ||
} | ||
|
||
func TestAPICheck(t *testing.T) { | ||
harness.RunAPIChecks(t, | ||
newTracer, | ||
harness.CheckEverything(), | ||
harness.UseProbe(apiCheckProbe{}), | ||
) | ||
} | ||
|
||
// implements harness.APICheckProbe | ||
type apiCheckProbe struct{} | ||
|
||
// SameTrace helps tests assert that this tracer's spans are from the same trace. | ||
func (apiCheckProbe) SameTrace(first, second ot.Span) bool { | ||
span1, ok := first.(*spanImpl) | ||
if !ok { // some other tracer's span | ||
return false | ||
} | ||
span2, ok := second.(*spanImpl) | ||
if !ok { // some other tracer's span | ||
return false | ||
} | ||
return span1.raw.Context.TraceID == span2.raw.Context.TraceID | ||
} | ||
|
||
// SameSpanContext helps tests assert that a span and a context are from the same trace and span. | ||
func (apiCheckProbe) SameSpanContext(span ot.Span, spanContext ot.SpanContext) bool { | ||
sp, ok := span.(*spanImpl) | ||
if !ok { | ||
return false | ||
} | ||
ctx, ok := spanContext.(SpanContext) | ||
if !ok { | ||
return false | ||
} | ||
return sp.raw.Context.TraceID == ctx.TraceID && sp.raw.Context.SpanID == ctx.SpanID | ||
} |