-
Notifications
You must be signed in to change notification settings - Fork 10
/
album_test.go
101 lines (87 loc) · 3.54 KB
/
album_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
package imgur
import (
"net/http"
"os"
"testing"
)
func TestAlbumImgurSimulated(t *testing.T) {
httpC, server := testHTTPClientJSON("{\"data\":{\"id\":\"VZQXk\",\"title\":\"Gianluca Gimini's bikes\",\"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\",\"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.GetAlbumInfo("VZQXk")
if err != nil {
t.Errorf("GetAlbumInfo() failed with error: %v", err)
t.FailNow()
}
if alb.Title != "Gianluca Gimini's bikes" || alb.Cover != "CJCA0gW" || alb.CoverWidth != 1200 || alb.CoverHeight != 786 || alb.Link != "https://imgur.com/a/VZQXk" || alb.ImagesCount != 1 || alb.Images[0].ID != "CJCA0gW" {
t.Error("Data comparison failed.")
if alb.Title != "Gianluca Gimini's bikes" {
t.Errorf("Title is %v.\n", alb.Title)
}
if alb.Cover != "CJCA0gW" {
t.Errorf("Cover is %v.\n", alb.Cover)
}
if alb.CoverWidth != 1200 {
t.Errorf("CoverWidth is %v.\n", alb.CoverWidth)
}
if alb.CoverHeight != 786 {
t.Errorf("CoverHeight is %v.\n", alb.CoverHeight)
}
if alb.Link != "https://imgur.com/a/VZQXk" {
t.Errorf("Link is %v.\n", alb.Link)
}
if alb.ImagesCount != 14 {
t.Errorf("ImagesCount is %v.\n", alb.ImagesCount)
}
if alb.Images[0].ID != "CJCA0gW" {
t.Errorf("Images is %v.\n", alb.Images)
}
t.Fail()
}
if status != 200 {
t.Errorf("Statsu != 200. It was %v.", status)
t.Fail()
}
}
func TestAlbumImgurReal(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.GetAlbumInfo("VZQXk")
if err != nil {
t.Errorf("GetAlbumInfo() failed with error: %v", err)
t.FailNow()
}
if alb.Title != "Gianluca Gimini's bikes" || 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.Error("Data comparison failed.")
if alb.Title != "Gianluca Gimini's bikes" {
t.Errorf("Title is %v.\n", alb.Title)
}
if alb.Cover != "CJCA0gW" {
t.Errorf("Cover is %v.\n", alb.Cover)
}
if alb.CoverWidth != 1200 {
t.Errorf("CoverWidth is %v.\n", alb.CoverWidth)
}
if alb.CoverHeight != 786 {
t.Errorf("CoverHeight is %v.\n", alb.CoverHeight)
}
if alb.Link != "https://imgur.com/a/VZQXk" {
t.Errorf("Link is %v.\n", alb.Link)
}
if alb.ImagesCount != 14 {
t.Errorf("ImagesCount is %v.\n", alb.ImagesCount)
}
if alb.Images[0].ID != "CJCA0gW" {
t.Errorf("Images is %v.\n", alb.Images)
}
t.Fail()
}
if status != 200 {
t.Errorf("Statsu != 200. It was %v.", status)
t.Fail()
}
}