-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvideos_test.go
121 lines (108 loc) · 4.02 KB
/
videos_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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package twch
import (
"fmt"
"net/http"
"reflect"
"testing"
)
func TestGetVideo(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/videos/1", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
fmt.Fprint(w, `{ "recorded_at": "2012-08-09T20:49:47Z", "title": "t", "url": "u", "_id": "i", "_links": { "self": "s", "owner": "o" }, "views": 1, "description": "d", "length": 1, "game": "g", "preview": "p" }`)
})
want := &Video{
ID: stringPtr("i"),
URL: stringPtr("u"),
Title: stringPtr("t"),
Views: intPtr(1),
Description: stringPtr("d"),
Length: intPtr(1),
Game: stringPtr("g"),
Preview: stringPtr("p"),
RecordedAt: stringPtr("2012-08-09T20:49:47Z"),
}
got, _, err := client.Videos.GetVideo(1)
if err != nil {
t.Errorf("Videos.GetVideo: request returned error %+v", err)
}
if !reflect.DeepEqual(got, want) {
t.Errorf("Videos.GetVideo response did not match:\nwant: %+v\ngot: %+v", want, got)
}
}
func TestListTop(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/videos/top", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testParams(t, r, params{
"limit": "1",
"offset": "1",
"game": "g",
"period": "week",
})
fmt.Fprint(w, `{ "_links": { "next": "https://api.twitch.tv/kraken/videos/top?game=League+of+Legends&limit=10&offset=10&period=month", "self": "https://api.twitch.tv/kraken/videos/top?game=League+of+Legends&limit=10&offset=0&period=month" }, "videos": [ { "recorded_at": "2013-03-13T09:51:31Z", "preview": "p", "description": "d", "url": "u", "title": "t", "channel": { "name": "n", "display_name": "d" }, "length": 1, "game": "g", "views": 1, "_id": "i", "_links": { "channel": "c", "self": "s" } } ] }`)
})
opts := &VideoRequestOptions{Game: "g", Period: "week", ListOptions: ListOptions{Limit: 1, Offset: 1}}
got, resp, err := client.Videos.ListTop(opts)
if err != nil {
t.Errorf("Videos.ListTop: returned error: %v", err)
}
testListResponse(t, resp, nil, intPtr(10), nil)
want := []Video{
Video{
ID: stringPtr("i"),
Preview: stringPtr("p"),
Description: stringPtr("d"),
URL: stringPtr("u"),
Title: stringPtr("t"),
Game: stringPtr("g"),
Views: intPtr(1),
Length: intPtr(1),
RecordedAt: stringPtr("2013-03-13T09:51:31Z"),
Channel: &Channel{
Name: stringPtr("n"),
DisplayName: stringPtr("d"),
},
},
}
if !reflect.DeepEqual(got, want) {
t.Errorf("Videos.ListTop response did not match:\nwant: %+v\ngot: %+v", want, got)
}
}
func TestListChannelVideos(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/channels/test_channel/videos", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testParams(t, r, params{
"limit": "1",
"offset": "1",
"broadcasts": "true",
})
fmt.Fprint(w, `{ "videos": [ { "title": "t", "recorded_at": "2011-10-02T19:57:06Z", "_id": "i", "_links": { "self": "s", "owner": "o" }, "url": "u", "views": 1, "preview": "p", "length": 1, "game": "g", "description": "d" } ], "_links": { "self": "https://api.twitch.tv/kraken/channels/vanillatv/videos?limit=10&offset=0", "next": "https://api.twitch.tv/kraken/channels/vanillatv/videos?limit=10&offset=10" } }`)
})
opts := &VideoChannelOptions{Broadcasts: true, ListOptions: ListOptions{Limit: 1, Offset: 1}}
got, resp, err := client.Videos.ListChannelVideos("test_channel", opts)
if err != nil {
t.Errorf("Videos.ListChannelVideos returned error - %v", err)
}
testListResponse(t, resp, nil, intPtr(10), nil)
want := []Video{
Video{
ID: stringPtr("i"),
Preview: stringPtr("p"),
Description: stringPtr("d"),
URL: stringPtr("u"),
Title: stringPtr("t"),
Game: stringPtr("g"),
Views: intPtr(1),
Length: intPtr(1),
RecordedAt: stringPtr("2011-10-02T19:57:06Z"),
},
}
if !reflect.DeepEqual(got, want) {
t.Errorf("Videos.ListChannelVideos response did not match:\nwant: %+v\ngot: %+v", want, got)
}
}