forked from koffeinsource/go-imgur
-
Notifications
You must be signed in to change notification settings - Fork 0
/
image_test.go
53 lines (41 loc) · 1.69 KB
/
image_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 TestImageImgurSimulated(t *testing.T) {
httpC, server := testHTTPClientJSON("{\"data\":{\"id\":\"ClF8rLe\",\"title\":null,\"description\":null,\"datetime\":1451248840,\"type\":\"image\\/jpeg\",\"animated\":false,\"width\":2448,\"height\":3264,\"size\":1071339,\"views\":176,\"bandwidth\":188555664,\"vote\":null,\"favorite\":false,\"nsfw\":null,\"section\":null,\"account_url\":null,\"account_id\":null,\"in_gallery\":false,\"link\":\"https:\\/\\/i.imgur.com\\/ClF8rLe.jpg\"},\"success\":true,\"status\":200}")
defer server.Close()
client, _ := NewClient(httpC, "testing", "")
img, status, err := client.GetImageInfo("ClF8rLe")
if err != nil {
t.Errorf("GetImageInfo() failed with error: %v", err)
t.FailNow()
}
if img.Animated != false || img.Bandwidth != 188555664 || img.Datetime != 1451248840 || img.Description != "" || img.Height != 3264 || img.Width != 2448 || img.ID != "ClF8rLe" || img.Link != "https://i.imgur.com/ClF8rLe.jpg" || img.Views != 176 {
t.Fail()
}
if status != 200 {
t.Fail()
}
}
func TestImageImgurReal(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)
img, status, err := client.GetImageInfo("ClF8rLe")
if err != nil {
t.Errorf("GetImageInfo() failed with error: %v", err)
t.FailNow()
}
if img.Animated != false || img.Datetime != 1451248840 || img.Description != "" || img.Height != 3264 || img.Width != 2448 || img.ID != "ClF8rLe" || img.Link != "https://i.imgur.com/ClF8rLe.jpg" {
t.Fail()
}
if status != 200 {
t.Fail()
}
}