-
Notifications
You must be signed in to change notification settings - Fork 14
/
me_test.go
70 lines (65 loc) · 1.38 KB
/
me_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
package gotwtr_test
import (
"context"
_ "embed"
"io"
"net/http"
"strings"
"testing"
"github.com/google/go-cmp/cmp"
"github.com/sivchari/gotwtr"
)
//go:embed testdata/me.json
var me []byte
func Test_me(t *testing.T) {
t.Parallel()
type args struct {
ctx context.Context
client *http.Client
opt []*gotwtr.MeOption
}
tests := []struct {
name string
args args
want *gotwtr.MeResponse
wantErr bool
}{
{
name: "200 ok default payload",
args: args{
ctx: context.Background(),
client: mockHTTPClient(func(request *http.Request) *http.Response {
return &http.Response{
StatusCode: http.StatusOK,
Body: io.NopCloser(strings.NewReader(string(me))),
}
}),
opt: []*gotwtr.MeOption{},
},
want: &gotwtr.MeResponse{
Me: &gotwtr.Me{
ID: "2244994945",
Name: "TwitterDev",
UserName: "Twitter Dev",
},
},
wantErr: false,
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
c := gotwtr.New("key", gotwtr.WithHTTPClient(tt.args.client))
got, err := c.Me(tt.args.ctx, tt.args.opt...)
if (err != nil) != tt.wantErr {
t.Errorf("client.Me() error = %v, wantErr %v", err, tt.wantErr)
return
}
if diff := cmp.Diff(tt.want, got); diff != "" {
t.Errorf("client.Me() mismatch (-want +got):\n%s", diff)
return
}
})
}
}