This repository has been archived by the owner on May 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 316
/
propagation_test.go
91 lines (78 loc) · 2.22 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
84
85
86
87
88
89
90
91
package opentracing
import (
"net/http"
"strconv"
"testing"
)
func TestTextMapCarrierInject(t *testing.T) {
m := make(map[string]string)
m["NotOT"] = "blah"
m["opname"] = "AlsoNotOT"
tracer := testTracer{}
span := tracer.StartSpan("someSpan")
fakeID := span.Context().(testSpanContext).FakeID
carrier := TextMapCarrier(m)
if err := span.Tracer().Inject(span.Context(), TextMap, carrier); err != nil {
t.Fatal(err)
}
if len(m) != 3 {
t.Errorf("Unexpected header length: %v", len(m))
}
// The prefix comes from just above; the suffix comes from
// testTracer.Inject().
if m["testprefix-fakeid"] != strconv.Itoa(fakeID) {
t.Errorf("Could not find fakeid at expected key")
}
}
func TestTextMapCarrierExtract(t *testing.T) {
m := make(map[string]string)
m["NotOT"] = "blah"
m["opname"] = "AlsoNotOT"
m["testprefix-fakeid"] = "42"
tracer := testTracer{}
carrier := TextMapCarrier(m)
extractedContext, err := tracer.Extract(TextMap, carrier)
if err != nil {
t.Fatal(err)
}
if extractedContext.(testSpanContext).FakeID != 42 {
t.Errorf("Failed to read testprefix-fakeid correctly")
}
}
func TestHTTPHeaderInject(t *testing.T) {
h := http.Header{}
h.Add("NotOT", "blah")
h.Add("opname", "AlsoNotOT")
tracer := testTracer{}
span := tracer.StartSpan("someSpan")
fakeID := span.Context().(testSpanContext).FakeID
// Use HTTPHeadersCarrier to wrap around `h`.
carrier := HTTPHeadersCarrier(h)
if err := span.Tracer().Inject(span.Context(), HTTPHeaders, carrier); err != nil {
t.Fatal(err)
}
if len(h) != 3 {
t.Errorf("Unexpected header length: %v", len(h))
}
// The prefix comes from just above; the suffix comes from
// testTracer.Inject().
if h.Get("testprefix-fakeid") != strconv.Itoa(fakeID) {
t.Errorf("Could not find fakeid at expected key")
}
}
func TestHTTPHeaderExtract(t *testing.T) {
h := http.Header{}
h.Add("NotOT", "blah")
h.Add("opname", "AlsoNotOT")
h.Add("testprefix-fakeid", "42")
tracer := testTracer{}
// Use HTTPHeadersCarrier to wrap around `h`.
carrier := HTTPHeadersCarrier(h)
spanContext, err := tracer.Extract(HTTPHeaders, carrier)
if err != nil {
t.Fatal(err)
}
if spanContext.(testSpanContext).FakeID != 42 {
t.Errorf("Failed to read testprefix-fakeid correctly")
}
}