-
Notifications
You must be signed in to change notification settings - Fork 12
/
request_test.go
133 lines (122 loc) · 2.36 KB
/
request_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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
package grpc
import (
"testing"
"github.com/gojek/fiber"
"github.com/gojek/fiber/protocol"
"github.com/stretchr/testify/assert"
"google.golang.org/grpc/metadata"
)
func TestRequest_Clone(t *testing.T) {
tests := []struct {
name string
req *Request
}{
{
name: "empty",
req: &Request{},
},
{
name: "simple",
req: &Request{
Metadata: metadata.New(map[string]string{"test": "1"}),
Message: []byte("Testing"),
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
clone, err := tt.req.Clone()
assert.NoError(t, err)
assert.Equal(t, tt.req, clone)
})
}
}
func TestRequest_Header(t *testing.T) {
tests := []struct {
name string
req Request
want map[string][]string
}{
{
name: "no metadata",
req: Request{},
want: nil,
},
{
name: "ok metadata",
req: Request{
Metadata: metadata.New(map[string]string{"test": "123"}),
},
want: map[string][]string{"test": {"123"}},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equal(t, tt.want, tt.req.Header())
})
}
}
func TestRequest_OperationName(t *testing.T) {
tests := []struct {
name string
req Request
expected string
}{
{
name: "empty request",
req: Request{},
expected: "grpc",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equal(t, tt.expected, tt.req.OperationName())
})
}
}
func TestRequest_Payload(t *testing.T) {
tests := []struct {
name string
req Request
expected []byte
}{
{
name: "ok payload",
req: Request{
Message: []byte("Testing"),
},
expected: []byte("Testing"),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equal(t, tt.expected, tt.req.Payload())
})
}
}
func TestRequest_Protocol(t *testing.T) {
req := Request{}
assert.Equal(t, protocol.GRPC, req.Protocol())
}
func TestRequest_Transform(t *testing.T) {
tests := []struct {
name string
req Request
backend fiber.Backend
expected Request
}{
{
name: "",
req: Request{},
backend: nil,
expected: Request{},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := tt.req.Transform(tt.backend)
assert.NoError(t, err)
assert.EqualValues(t, tt.expected, *got.(*Request), "Transform(%v)", tt.backend)
})
}
}