-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrequest_client_internal_test.go
90 lines (70 loc) · 1.78 KB
/
request_client_internal_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
package grpcsteps
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
"go.nhat.io/grpcmock/service"
"github.com/godogx/grpcsteps/internal/grpctest"
)
func TestClientRequestInContext(t *testing.T) {
t.Parallel()
ctx := context.Background()
// Case 1: no request in context.
assert.Equal(t, missingClientRequest{}, clientRequestFromContext(ctx))
// Case 2: request in context.
ctx = clientRequestToContext(ctx, &clientRequestInvoker{})
assert.Equal(t, &clientRequestInvoker{}, clientRequestFromContext(ctx))
}
func TestMissingClientRequest(t *testing.T) {
t.Parallel()
expected := `no client request in context, did you forget to setup a gprc request in the scenario?
For example:
When I request a gRPC method "/grpctest.ItemService/GetItem" with payload:
"""
{
"id": 42
}
"""
`
r := missingClientRequest{}
result, err := r.Do()
assert.Nil(t, result)
assert.EqualError(t, err, expected)
}
func TestNewServerOutput(t *testing.T) {
t.Parallel()
testCases := []struct {
scenario string
methodtype service.Type
expected interface{}
}{
{
scenario: "unary",
methodtype: service.TypeUnary,
expected: &grpctest.Item{},
},
{
scenario: "client stream",
methodtype: service.TypeClientStream,
expected: &grpctest.Item{},
},
{
scenario: "server stream",
methodtype: service.TypeServerStream,
expected: &[]*grpctest.Item{},
},
{
scenario: "bidirectional",
methodtype: service.TypeBidirectionalStream,
expected: &[]*grpctest.Item{},
},
}
for _, tc := range testCases {
tc := tc
t.Run(tc.scenario, func(t *testing.T) {
t.Parallel()
actual := newServerOutput(tc.methodtype, grpctest.Item{})
assert.Equal(t, tc.expected, actual)
})
}
}