...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package internaltest
19
20 import (
21 "context"
22 "testing"
23 )
24
25 func TestTextMapPropagatorInjectExtract(t *testing.T) {
26 name := "testing"
27 ctx := context.Background()
28 carrier := NewTextMapCarrier(map[string]string{name: value})
29 propagator := NewTextMapPropagator(name)
30
31 propagator.Inject(ctx, carrier)
32
33 if carrier.SetKeyValue(t, name, "1,0") {
34
35 propagator.ExtractedN(t, ctx, 0)
36
37 propagator.InjectedN(t, carrier, 1)
38 }
39
40 ctx = propagator.Extract(ctx, carrier)
41 v := ctx.Value(ctxKeyType(name))
42 if v == nil {
43 t.Error("TextMapPropagator.Extract failed to extract state")
44 }
45 if s, ok := v.(state); !ok {
46 t.Error("TextMapPropagator.Extract did not extract proper state")
47 } else if s.Extractions != 1 {
48 t.Error("TextMapPropagator.Extract did not increment state.Extractions")
49 }
50 if carrier.GotKey(t, name) {
51
52 propagator.ExtractedN(t, ctx, 1)
53
54 propagator.InjectedN(t, carrier, 1)
55 }
56 }
57
58 func TestTextMapPropagatorFields(t *testing.T) {
59 name := "testing"
60 propagator := NewTextMapPropagator(name)
61 if got := propagator.Fields(); len(got) != 1 {
62 t.Errorf("TextMapPropagator.Fields returned %d fields, want 1", len(got))
63 } else if got[0] != name {
64 t.Errorf("TextMapPropagator.Fields returned %q, want %q", got[0], name)
65 }
66 }
67
68 func TestNewStateEmpty(t *testing.T) {
69 if want, got := (state{}), newState(""); got != want {
70 t.Errorf("newState(\"\") returned %v, want %v", got, want)
71 }
72 }
73
View as plain text