forked from infobloxopen/atlas-app-toolkit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathheader_test.go
More file actions
64 lines (51 loc) · 1.63 KB
/
Copy pathheader_test.go
File metadata and controls
64 lines (51 loc) · 1.63 KB
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
package gateway
import (
"context"
"testing"
"google.golang.org/grpc/metadata"
)
func TestHeader(t *testing.T) {
imd := metadata.Pairs("key1", "val1")
omd := metadata.Pairs("key2", "val2", "grpcgateway-key2", "val2")
ictx := metadata.NewIncomingContext(context.Background(), imd)
ctx := metadata.NewOutgoingContext(ictx, omd)
if v, ok := Header(ctx, "key1"); !ok {
t.Error("failed to get 'key1'")
} else if v != "val1" {
t.Errorf("invalid value of 'key1': %s", v)
}
if v, ok := Header(ctx, "key2"); !ok {
t.Error("failed to get 'key2'")
} else if v != "val2" {
t.Errorf("invalid value of 'key2': %s", v)
}
}
func TestHeaderN(t *testing.T) {
imd := metadata.Pairs("key1", "val1")
omd := metadata.Pairs("key2", "val2", "grpcgateway-key2", "val2")
ictx := metadata.NewIncomingContext(context.Background(), imd)
ctx := metadata.NewOutgoingContext(ictx, omd)
if v, ok := HeaderN(ctx, "key1", -1); !ok {
t.Error("failed to get 'key1'")
} else if len(v) != 1 || v[0] != "val1" {
t.Errorf("invalid value of 'key1': %s", v)
}
if v, ok := HeaderN(ctx, "key2", 2); !ok {
t.Error("failed to get 'key2'")
} else if len(v) != 2 || v[0] != "val2" || v[1] != "val2" {
t.Errorf("invalid value of 'key2': %s", v)
}
if v, ok := HeaderN(ctx, "key1", 0); ok || v != nil {
t.Errorf("invalid result with n==0: %s, %v", v, ok)
}
if v, ok := HeaderN(ctx, "key1", 10); ok || v != nil {
t.Errorf("invalid result with n>len(md): %s, %v", v, ok)
}
}
func TestPrefixOutgoingHeaderMatcher(t *testing.T) {
key := "Content-Type"
v, ok := PrefixOutgoingHeaderMatcher(key)
if ok {
t.Errorf("header %s hasn't been discarded: %s", key, v)
}
}