-
Notifications
You must be signed in to change notification settings - Fork 3
/
static_client_test.go
82 lines (75 loc) · 1.74 KB
/
static_client_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
package api2
import (
"context"
"testing"
)
func TestGetMethod(t *testing.T) {
type FooRequest struct {
}
type FooResponse struct {
}
var foo func(ctx context.Context, req *FooRequest) (*FooResponse, error)
type BarArgs struct {
}
type BarReply struct {
}
var bar func(ctx context.Context, req *BarArgs) (*BarReply, error)
type BazRequest struct {
}
type BazResponse struct {
}
type BazService interface {
Baz(ctx context.Context, req *BazRequest) (*BazResponse, error)
}
var baz BazService
var badFoo func(ctx context.Context, req *FooRequest) (*BarReply, error)
var badFoo2 func(ctx context.Context, req []int) ([]string, error)
cases := []struct {
handler interface{}
name, request, response string
wantErr bool
}{
{
handler: foo,
name: "Foo",
request: "FooRequest",
response: "FooResponse",
},
{
handler: bar,
name: "Bar",
request: "BarArgs",
response: "BarReply",
},
{
handler: Method(&baz, "Baz"),
name: "Baz",
request: "BazRequest",
response: "BazResponse",
},
{
handler: badFoo,
wantErr: true,
},
{
handler: badFoo2,
wantErr: true,
},
}
for i, tc := range cases {
name, request, response, err := getMethod(tc.handler)
if tc.wantErr {
if err == nil {
t.Errorf("case %d: want error, not got", i)
}
} else if !tc.wantErr && err != nil {
t.Errorf("case %d: got error: %v", i, err)
} else if name != tc.name {
t.Errorf("case %d: want name %q, got %q", i, tc.name, name)
} else if request != tc.request {
t.Errorf("case %d: want request %q, got %q", i, tc.request, request)
} else if response != tc.response {
t.Errorf("case %d: want response %q, got %q", i, tc.response, response)
}
}
}