-
Notifications
You must be signed in to change notification settings - Fork 10
/
galleryAlbum_test.go
53 lines (41 loc) · 2.37 KB
/
galleryAlbum_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
package imgur
import (
"net/http"
"os"
"testing"
)
func TestGalleryAlbumImgurSimulated(t *testing.T) {
httpC, server := testHTTPClientJSON("{\"data\":{\"id\":\"VZQXk\",\"title\":\"As it turns out, most people cannot draw a bike.\",\"description\":null,\"datetime\":1460715031,\"cover\":\"CJCA0gW\",\"cover_width\":1200,\"cover_height\":786,\"account_url\":\"mrcassette\",\"account_id\":157430,\"privacy\":\"public\",\"layout\":\"blog\",\"views\":667581,\"link\":\"https:\\/\\/imgur.com\\/a\\/VZQXk\",\"ups\":13704,\"downs\":113,\"favorite\":false,\"nsfw\":false,\"section\":\"pics\",\"images_count\":1,\"in_gallery\":true,\"images\":[{\"id\":\"CJCA0gW\",\"title\":null,\"description\":\"by Designer Gianluca Gimini\\nhttps:\\/\\/www.behance.net\\/gallery\\/35437979\\/Velocipedia\",\"datetime\":1460715032,\"type\":\"image\\/jpeg\",\"animated\":false,\"width\":1200,\"height\":786,\"size\":362373,\"views\":4420880,\"bandwidth\":1602007548240,\"vote\":null,\"favorite\":false,\"nsfw\":null,\"section\":null,\"account_url\":null,\"account_id\":null,\"in_gallery\":false,\"link\":\"https:\\/\\/i.imgur.com\\/CJCA0gW.jpg\"}]},\"success\":true,\"status\":200}")
defer server.Close()
client, _ := NewClient(httpC, "testing", "")
alb, status, err := client.GetGalleryAlbumInfo("VZQXk")
if err != nil {
t.Errorf("GetAlbumInfo() failed with error: %v", err)
t.FailNow()
}
if alb.Title != "As it turns out, most people cannot draw a bike." || alb.Cover != "CJCA0gW" || alb.CoverWidth != 1200 || alb.CoverHeight != 786 || alb.Link != "https://imgur.com/a/VZQXk" || alb.ImagesCount != 1 || alb.Images[0].ID != "CJCA0gW" || alb.Ups != 13704 || alb.Downs != 113 {
t.Fail()
}
if status != 200 {
t.Fail()
}
}
func TestGalleryAlbumImgurReal(t *testing.T) {
key := os.Getenv("IMGURCLIENTID")
if key == "" {
t.Skip("IMGURCLIENTID environment variable not set.")
}
RapidAPIKey := os.Getenv("RapidAPIKEY")
client, _ := NewClient(new(http.Client), key, RapidAPIKey)
alb, status, err := client.GetGalleryAlbumInfo("VZQXk")
if err != nil {
t.Errorf("GetAlbumInfo() failed with error: %v", err)
t.FailNow()
}
if alb.Title != "As it turns out, most people cannot draw a bike." || alb.Cover != "CJCA0gW" || alb.CoverWidth != 1200 || alb.CoverHeight != 786 || alb.Link != "https://imgur.com/a/VZQXk" || alb.ImagesCount != 14 || alb.Images[0].ID != "CJCA0gW" {
t.Fail()
}
if status != 200 {
t.Fail()
}
}