-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinterceptor_test.go
102 lines (100 loc) · 2.27 KB
/
interceptor_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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package grpcConst
import (
ogcIsh "github.com/MikkelHJuul/grpcConst/examples/ogc_ish/proto"
"github.com/MikkelHJuul/grpcConst/examples/route_guide/proto"
"google.golang.org/grpc/metadata"
"reflect"
"testing"
)
func TestHeaderSetConstant(t *testing.T) {
type args struct {
v interface{}
}
var tests = []struct {
name string
args args
want metadata.MD
wantErr bool
}{
{
name: "a simple obj header",
args: args{&proto.Feature{
Name: "",
Location: &proto.Point{
Latitude: 11,
Longitude: 22,
},
}},
want: map[string][]string{
XgRPCConst: {"EgQICxAW"},
},
wantErr: false,
},
{
name: "a simple ogcish obj header",
args: args{&ogcIsh.Feature{
Type: "DeFAULT",
Geometry: &ogcIsh.Geometry{
Coordinates: &ogcIsh.Point{
Latitude: 12,
Longitude: 21,
},
},
}},
want: map[string][]string{
XgRPCConst: {"CgdEZUZBVUxUIgYSBAgMEBU="},
},
wantErr: false,
},
{
name: "an empty Obj",
args: args{&proto.Feature{}},
want: map[string][]string{
XgRPCConst: {""},
},
wantErr: false,
},
{
name: "an empty-ish Obj",
args: args{&ogcIsh.Feature{Geometry: &ogcIsh.Geometry{}}},
want: map[string][]string{
XgRPCConst: {"IgA="},
},
wantErr: false,
},
{
name: "a large obj header",
args: args{&ogcIsh.Feature{
Type: "Feature",
Properties: &ogcIsh.Properties{
Measurement: &ogcIsh.Measurement{
Name: "John",
},
Station: &ogcIsh.Station{
Name: "Some Station Name",
Metadata: "Some station's metadata, a short story",
},
},
Geometry: &ogcIsh.Geometry{
Type: "Lol",
Coordinates: &ogcIsh.Point{
Latitude: 123,
Longitude: 321,
},
},
}},
want: map[string][]string{XgRPCConst: {"CgdGZWF0dXJlGkUKBgoESm9oblI7ChFTb21lIFN0YXRpb24gTmFtZRImU29tZSBzdGF0aW9uJ3MgbWV0YWRhdGEsIGEgc2hvcnQgc3RvcnkiDAoDTG9sEgUIexDBAg=="}},
}}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := HeaderSetConstant(tt.args.v)
if (err != nil) != tt.wantErr {
t.Errorf("HeaderSetConstant() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("HeaderSetConstant() got = %v, want %v", got, tt.want)
}
})
}
}