forked from tracer/tracer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
propagation_test.go
83 lines (76 loc) · 2.02 KB
/
propagation_test.go
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
package tracer
import (
"bytes"
"testing"
"github.com/opentracing/opentracing-go"
)
func TestText(t *testing.T) {
sp := &Span{
raw: RawSpan{
SpanContext: SpanContext{
SpanID: 1,
ParentID: 2,
TraceID: 3,
Flags: FlagSampled,
Baggage: map[string]string{
"k1": "v1",
"k2": "",
},
},
},
}
carrier := opentracing.TextMapCarrier{}
if err := textInjecter(sp.Context().(SpanContext), carrier); err != nil {
t.Fatal("unexpected error: ", err)
}
context, err := textExtracter(carrier)
if err != nil {
t.Fatal("unexpected error: ", err)
}
if context.TraceID != sp.raw.TraceID ||
context.ParentID != sp.raw.ParentID ||
context.SpanID != sp.raw.SpanID ||
context.Flags != sp.raw.Flags ||
len(context.Baggage) != 2 ||
context.Baggage["k1"] != "v1" ||
context.Baggage["k2"] != "" {
t.Errorf("got (%d, %d, %d, %d, %v), want (%d, %d, %d, %d, %v)",
context.TraceID, context.ParentID, context.SpanID, context.Flags, context.Baggage,
sp.raw.TraceID, sp.raw.ParentID, sp.raw.SpanID, sp.raw.Flags, sp.raw.Baggage)
}
}
func TestBinary(t *testing.T) {
sp := &Span{
raw: RawSpan{
SpanContext: SpanContext{
SpanID: 1,
ParentID: 2,
TraceID: 3,
Flags: FlagSampled,
Baggage: map[string]string{
"k1": "v1",
"k2": "",
},
},
},
}
buf := &bytes.Buffer{}
if err := binaryInjecter(sp.Context().(SpanContext), buf); err != nil {
t.Fatal("unexpected error: ", err)
}
context, err := binaryExtracter(buf)
if err != nil {
t.Fatal("unexpected error: ", err)
}
if context.TraceID != sp.raw.TraceID ||
context.ParentID != sp.raw.ParentID ||
context.SpanID != sp.raw.SpanID ||
context.Flags != sp.raw.Flags ||
len(context.Baggage) != 2 ||
context.Baggage["k1"] != "v1" ||
context.Baggage["k2"] != "" {
t.Errorf("got (%d, %d, %d, %d, %v), want (%d, %d, %d, %d, %v)",
context.TraceID, context.ParentID, context.SpanID, context.Flags, context.Baggage,
sp.raw.TraceID, sp.raw.ParentID, sp.raw.SpanID, sp.raw.Flags, sp.raw.Baggage)
}
}