-
Notifications
You must be signed in to change notification settings - Fork 2
/
client_internal_test.go
107 lines (71 loc) · 2.93 KB
/
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package grpcsteps
import (
"context"
"testing"
"github.com/cucumber/godog"
"github.com/stretchr/testify/assert"
"google.golang.org/grpc/test/bufconn"
"github.com/godogx/grpcsteps/internal/grpctest"
)
func TestClient_iRequestWithPayload_InvalidMethod(t *testing.T) {
t.Parallel()
_, err := NewClient().iRequestWithPayload(context.Background(), "", "")
expected := `invalid grpc method`
assert.EqualError(t, err, expected)
}
func TestClient_iRequestWithPayload_InvalidPayload(t *testing.T) {
t.Parallel()
_, err := NewClient(
RegisterService(grpctest.RegisterItemServiceServer),
).iRequestWithPayload(context.Background(), "/grpctest.ItemService/GetItem", "42")
expected := `json: cannot unmarshal number into Go value of type grpctest.GetItemRequest`
assert.EqualError(t, err, expected)
}
func TestClient_iRequestWithPayloadFromFile_ReadFileError(t *testing.T) {
t.Parallel()
_, err := NewClient(
RegisterService(grpctest.RegisterItemServiceServer),
).iRequestWithPayloadFromFile(context.Background(), "/grpctest.ItemService/GetItem", "not_found")
expected := `open not_found: no such file or directory`
assert.EqualError(t, err, expected)
}
func TestClient_iShouldHaveResponseWithPayloadFromFile_ReadFileError(t *testing.T) {
t.Parallel()
err := NewClient(
RegisterService(grpctest.RegisterItemServiceServer),
).iShouldHaveResponseWithPayloadFromFile(context.Background(), "not_found")
expected := `open not_found: no such file or directory`
assert.EqualError(t, err, expected)
}
func TestClient_iShouldHaveResponseWithCode_InvalidCode(t *testing.T) {
t.Parallel()
err := NewClient().iShouldHaveResponseWithCode(context.Background(), `not a code`)
expected := `invalid code: "\"NOT A CODE\""`
assert.EqualError(t, err, expected)
}
func TestClient_iShouldHaveResponseWithCodeAndErrorMessage_InvalidCode(t *testing.T) {
t.Parallel()
err := NewClient().iShouldHaveResponseWithCodeAndErrorMessage(context.Background(), `not a code`, "")
expected := `invalid code: "\"NOT A CODE\""`
assert.EqualError(t, err, expected)
}
func TestClient_iShouldHaveResponseWithCodeAndErrorMessageFromDocString_InvalidCode(t *testing.T) {
t.Parallel()
err := NewClient().iShouldHaveResponseWithCodeAndErrorMessageFromDocString(context.Background(), `not a code`, &godog.DocString{})
expected := `invalid code: "\"NOT A CODE\""`
assert.EqualError(t, err, expected)
}
func TestWithAddr(t *testing.T) {
t.Parallel()
addr := "127.0.0.1:9000"
c := NewClient(RegisterService(grpctest.RegisterItemServiceServer, WithAddr(addr)))
assert.Equal(t, addr, c.services["/grpctest.ItemService/GetItem"].Address)
}
func TestWithAddressProvider(t *testing.T) {
t.Parallel()
provider := bufconn.Listen(1024 * 1024)
addr := "bufconn"
defer provider.Close() // nolint: errcheck
c := NewClient(RegisterService(grpctest.RegisterItemServiceServer, WithAddressProvider(provider)))
assert.Equal(t, addr, c.services["/grpctest.ItemService/ListItems"].Address)
}