-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathvolume_stream_test.go
77 lines (73 loc) · 1.88 KB
/
volume_stream_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
package gotwtr_test
import (
"context"
"io"
"net/http"
"strings"
"testing"
"github.com/google/go-cmp/cmp"
"github.com/sivchari/gotwtr"
)
func Test_sampledStream(t *testing.T) {
t.Parallel()
type args struct {
ctx context.Context
client *http.Client
opt []*gotwtr.VolumeStreamsOption
}
tests := []struct {
name string
args args
want *gotwtr.VolumeStreamsResponse
wantErr bool
}{
{
name: "200 ok default payload",
args: args{
ctx: context.Background(),
client: mockHTTPClient(func(request *http.Request) *http.Response {
body := `{
"data": {
"id": "1067094924124872705",
"text": "Just getting started with Twitter APIs? Find out what you need in order to build an app. Watch this video! https://t.co/Hg8nkfoizN"
}
}`
return &http.Response{
StatusCode: http.StatusOK,
Body: io.NopCloser(strings.NewReader(body)),
}
}),
opt: []*gotwtr.VolumeStreamsOption{},
},
want: &gotwtr.VolumeStreamsResponse{
Tweet: &gotwtr.Tweet{
ID: "1067094924124872705",
Text: "Just getting started with Twitter APIs? Find out what you need in order to build an app. Watch this video! https://t.co/Hg8nkfoizN",
},
},
wantErr: false,
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
ch := make(chan gotwtr.VolumeStreamsResponse)
errCh := make(chan error)
c := gotwtr.New("key", gotwtr.WithHTTPClient(tt.args.client))
c.VolumeStreams(tt.args.ctx, ch, errCh, tt.args.opt...)
select {
case got := <-ch:
if diff := cmp.Diff(tt.want, &got); diff != "" {
t.Errorf("client.VolumeStreams() mismatch (-want +got):\n%s", diff)
return
}
case err := <-errCh:
if (err != nil) != tt.wantErr {
t.Errorf("client.VolumeStreams() error = %v, wantErr %v", err, tt.wantErr)
return
}
}
})
}
}