forked from azer/go-flickr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
favs_test.go
180 lines (173 loc) · 4 KB
/
favs_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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
//go:build unit
// +build unit
package flickr
import (
"bytes"
"encoding/json"
"net/http"
"net/http/httptest"
"testing"
)
func TestFavsFirstPage(t *testing.T) {
client, err := NewPhotosClientEnvVar(PaginationParams{})
if err != nil {
t.Fatalf("Unable to create client: %s", err)
}
client.Key = "XXX"
server := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
var sampleResp = []byte(`{
"photos": {
"page": 1,
"pages": 43,
"perpage": 10,
"total": 421,
"photo": [
{
"id": "51737769056",
"owner": "38134034@N04",
"secret": "0a0e8bf24c",
"server": "65535",
"farm": 66,
"title": "Take a seat",
"ispublic": 1,
"isfriend": 0,
"isfamily": 0,
"date_faved": "1639261222"
},
{
"id": "51739666614",
"owner": "80728884@N06",
"secret": "5388db9d26",
"server": "65535",
"farm": 66,
"title": "If things are shaking, you need a Friend...",
"ispublic": 1,
"isfriend": 0,
"isfamily": 0,
"date_faved": "1639261194"
},
{
"id": "51739069301",
"owner": "92986809@N05",
"secret": "c218dd924d",
"server": "65535",
"farm": 66,
"title": "Zooks Mill",
"ispublic": 1,
"isfriend": 0,
"isfamily": 0,
"date_faved": "1639261169"
},
{
"id": "51738575977",
"owner": "30430801@N06",
"secret": "903639dd92",
"server": "65535",
"farm": 66,
"title": "Sirmione, Lago di Garda",
"ispublic": 1,
"isfriend": 0,
"isfamily": 0,
"date_faved": "1639261159"
},
{
"id": "51179405040",
"owner": "53033551@N03",
"secret": "de2d6b3faa",
"server": "65535",
"farm": 66,
"title": "Berlin | (2015)",
"ispublic": 1,
"isfriend": 0,
"isfamily": 0,
"date_faved": "1639255345"
},
{
"id": "51646533603",
"owner": "53033551@N03",
"secret": "47a4d4923a",
"server": "65535",
"farm": 66,
"title": "DSC02170",
"ispublic": 1,
"isfriend": 0,
"isfamily": 0,
"date_faved": "1639255225"
},
{
"id": "50657384952",
"owner": "190970715@N04",
"secret": "46477d87ca",
"server": "65535",
"farm": 66,
"title": "Dans le Santerre, sans terre, pas de pommes de terre",
"ispublic": 1,
"isfriend": 0,
"isfamily": 0,
"date_faved": "1639244884"
},
{
"id": "51733295191",
"owner": "190970715@N04",
"secret": "eb954a0cb4",
"server": "65535",
"farm": 66,
"title": "Brumes sur la mégalopole (explore)",
"ispublic": 1,
"isfriend": 0,
"isfamily": 0,
"date_faved": "1639239960"
},
{
"id": "51734204877",
"owner": "76093456@N04",
"secret": "4f58067045",
"server": "65535",
"farm": 66,
"title": "IXPE by SpaceX",
"ispublic": 1,
"isfriend": 0,
"isfamily": 0,
"date_faved": "1639239570"
},
{
"id": "51735604885",
"owner": "28497307@N05",
"secret": "0e0c1642c4",
"server": "65535",
"farm": 66,
"title": "Making Haste",
"ispublic": 1,
"isfriend": 0,
"isfamily": 0,
"date_faved": "1639239417"
}
]
},
"stat": "ok"
}`)
compactedResp := new(bytes.Buffer)
if err := json.Compact(compactedResp, sampleResp); err != nil {
t.Fatalf("Unable to compact JSON: %s", err)
}
rw.Write(compactedResp.Bytes())
}))
defer server.Close()
client.URL = server.URL
favs, err := client.Favs("")
if err != nil {
t.Fatalf("Error getting Favs: %s", err)
}
if favs.Page != 1 {
t.Fatalf("Expecting page to be 1, but got %d", favs.Page)
}
if favs.Pages != 43 {
t.Fatalf("Expecting at 43 pages, but got %d", favs.Pages)
}
if favs.PerPage != 10 {
t.Fatalf("Expecting 100 photos per page, but got %d", favs.PerPage)
}
if len(favs.Photos) != 10 {
t.Fatalf("Expecting 10 photos, got %d", len(favs.Photos))
}
}