Repository navigation
Expand file tree
/
Copy pathtracing_test.go
More file actions
93 lines (76 loc) · 1.9 KB
/
Copy pathtracing_test.go
File metadata and controls
93 lines (76 loc) · 1.9 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package axio
import (
"context"
"testing"
)
func TestNoopTracer(t *testing.T) {
tracer := NoopTracer{}
traceID, spanID, ok := tracer.Extract(context.Background())
assertEqual(t, traceID, "")
assertEqual(t, spanID, "")
if ok {
t.Error("NoopTracer should return false")
}
}
func TestNoopTracing(t *testing.T) {
tracer := NoopTracing()
if tracer == nil {
t.Error("NoopTracing should return a non-nil tracer")
}
_, ok := tracer.(NoopTracer)
if !ok {
t.Error("NoopTracing should return a NoopTracer")
}
}
func TestOtel_NoSpan(t *testing.T) {
tracer := Otel()
traceID, spanID, ok := tracer.Extract(context.Background())
assertEqual(t, traceID, "")
assertEqual(t, spanID, "")
if ok {
t.Error("should return false when no span in context")
}
}
func TestBuildTracer(t *testing.T) {
t.Run("custom_tracer_takes_precedence", func(t *testing.T) {
custom := NoopTracer{}
config := Config{tracer: custom}
tracer := buildTracer(config)
_, ok := tracer.(NoopTracer)
if !ok {
t.Error("should return custom tracer")
}
})
t.Run("otel_type", func(t *testing.T) {
config := Config{TracerType: "otel"}
tracer := buildTracer(config)
_, ok := tracer.(*otelTraceExtractor)
if !ok {
t.Error("should return otelTraceExtractor")
}
})
t.Run("noop_type", func(t *testing.T) {
config := Config{TracerType: "noop"}
tracer := buildTracer(config)
_, ok := tracer.(NoopTracer)
if !ok {
t.Error("should return NoopTracer")
}
})
t.Run("empty_type", func(t *testing.T) {
config := Config{TracerType: ""}
tracer := buildTracer(config)
_, ok := tracer.(NoopTracer)
if !ok {
t.Error("should return NoopTracer for empty type")
}
})
t.Run("unknown_type_falls_back_to_noop", func(t *testing.T) {
config := Config{TracerType: "unknown"}
tracer := buildTracer(config)
_, ok := tracer.(NoopTracer)
if !ok {
t.Error("should return NoopTracer for unknown type")
}
})
}