forked from zeromicro/go-zero
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcarrier_test.go
58 lines (52 loc) · 1.06 KB
/
carrier_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
package trace
import (
"net/http"
"net/http/httptest"
"testing"
"github.com/stretchr/testify/assert"
"github.com/tal-tech/go-zero/core/stringx"
)
func TestHttpCarrier(t *testing.T) {
tests := []map[string]string{
{},
{
"first": "a",
"second": "b",
},
}
for _, test := range tests {
t.Run(stringx.RandId(), func(t *testing.T) {
req := httptest.NewRequest(http.MethodGet, "http://localhost", nil)
carrier := httpCarrier(req.Header)
for k, v := range test {
carrier.Set(k, v)
}
for k, v := range test {
assert.Equal(t, v, carrier.Get(k))
}
assert.Equal(t, "", carrier.Get("none"))
})
}
}
func TestGrpcCarrier(t *testing.T) {
tests := []map[string]string{
{},
{
"first": "a",
"second": "b",
},
}
for _, test := range tests {
t.Run(stringx.RandId(), func(t *testing.T) {
m := make(map[string][]string)
carrier := grpcCarrier(m)
for k, v := range test {
carrier.Set(k, v)
}
for k, v := range test {
assert.Equal(t, v, carrier.Get(k))
}
assert.Equal(t, "", carrier.Get("none"))
})
}
}