1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package internaltest
19
20 import (
21 "reflect"
22 "testing"
23 )
24
25 var key, value = "test", "true"
26
27 func TestTextMapCarrierKeys(t *testing.T) {
28 tmc := NewTextMapCarrier(map[string]string{key: value})
29 expected, actual := []string{key}, tmc.Keys()
30 if !reflect.DeepEqual(actual, expected) {
31 t.Errorf("expected tmc.Keys() to be %v but it was %v", expected, actual)
32 }
33 }
34
35 func TestTextMapCarrierGet(t *testing.T) {
36 tmc := NewTextMapCarrier(map[string]string{key: value})
37 tmc.GotN(t, 0)
38 if got := tmc.Get("empty"); got != "" {
39 t.Errorf("TextMapCarrier.Get returned %q for an empty key", got)
40 }
41 tmc.GotKey(t, "empty")
42 tmc.GotN(t, 1)
43 if got := tmc.Get(key); got != value {
44 t.Errorf("TextMapCarrier.Get(%q) returned %q, want %q", key, got, value)
45 }
46 tmc.GotKey(t, key)
47 tmc.GotN(t, 2)
48 }
49
50 func TestTextMapCarrierSet(t *testing.T) {
51 tmc := NewTextMapCarrier(nil)
52 tmc.SetN(t, 0)
53 tmc.Set(key, value)
54 if got, ok := tmc.data[key]; !ok {
55 t.Errorf("TextMapCarrier.Set(%q,%q) failed to store pair", key, value)
56 } else if got != value {
57 t.Errorf("TextMapCarrier.Set(%q,%q) stored (%q,%q), not (%q,%q)", key, value, key, got, key, value)
58 }
59 tmc.SetKeyValue(t, key, value)
60 tmc.SetN(t, 1)
61 }
62
63 func TestTextMapCarrierReset(t *testing.T) {
64 tmc := NewTextMapCarrier(map[string]string{key: value})
65 tmc.GotN(t, 0)
66 tmc.SetN(t, 0)
67 tmc.Reset(nil)
68 tmc.GotN(t, 0)
69 tmc.SetN(t, 0)
70 if got := tmc.Get(key); got != "" {
71 t.Error("TextMapCarrier.Reset() failed to clear initial data")
72 }
73 tmc.GotN(t, 1)
74 tmc.GotKey(t, key)
75 tmc.Set(key, value)
76 tmc.SetKeyValue(t, key, value)
77 tmc.SetN(t, 1)
78 tmc.Reset(nil)
79 tmc.GotN(t, 0)
80 tmc.SetN(t, 0)
81 if got := tmc.Get(key); got != "" {
82 t.Error("TextMapCarrier.Reset() failed to clear data")
83 }
84 }
85
View as plain text