forked from micro/go-micro
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wrapper_test.go
53 lines (46 loc) · 956 Bytes
/
wrapper_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
package micro
import (
"context"
"testing"
"github.com/micro/go-micro/metadata"
)
func TestWrapper(t *testing.T) {
testData := []struct {
existing metadata.Metadata
headers metadata.Metadata
overwrite bool
}{
{
existing: metadata.Metadata{},
headers: metadata.Metadata{
"foo": "bar",
},
overwrite: true,
},
{
existing: metadata.Metadata{
"foo": "bar",
},
headers: metadata.Metadata{
"foo": "baz",
},
overwrite: false,
},
}
for _, d := range testData {
c := &clientWrapper{
headers: d.headers,
}
ctx := metadata.NewContext(context.Background(), d.existing)
ctx = c.setHeaders(ctx)
md, _ := metadata.FromContext(ctx)
for k, v := range d.headers {
if d.overwrite && md[k] != v {
t.Fatalf("Expected %s=%s got %s=%s", k, v, k, md[k])
}
if !d.overwrite && md[k] != d.existing[k] {
t.Fatalf("Expected %s=%s got %s=%s", k, d.existing[k], k, md[k])
}
}
}
}