1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 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
}
|