-
Notifications
You must be signed in to change notification settings - Fork 16
/
fastimage_test.go
139 lines (103 loc) · 2.5 KB
/
fastimage_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
package fastimage
import (
"testing"
)
func TestPNGImage(t *testing.T) {
t.Parallel()
url := "http://fc08.deviantart.net/fs71/f/2012/214/7/c/futurama__bender_by_suzura-d59kq1p.png"
imagetype, size, err := DetectImageType(url)
if err != nil {
t.Error("Failed to detect image type")
}
if size == nil {
t.Error("Failed to detect image size")
}
if imagetype != PNG {
t.Error("Image is not PNG")
}
if size.Width != 988 {
t.Error("Image width is wrong")
}
if size.Height != 1240 {
t.Error("Image height is wrong")
}
}
func TestJPEGImage(t *testing.T) {
t.Parallel()
url := "http://upload.wikimedia.org/wikipedia/commons/9/9a/SKA_dishes_big.jpg"
imagetype, size, err := DetectImageType(url)
if err != nil {
t.Error("Failed to detect image type")
}
if size == nil {
t.Error("Failed to detect image size")
}
if imagetype != JPEG {
t.Error("Image is not JPEG")
}
if size.Width != 5000 {
t.Error("Image width is wrong")
}
if size.Height != 2813 {
t.Error("Image height is wrong")
}
}
func TestGIFImage(t *testing.T) {
t.Parallel()
url := "http://media.giphy.com/media/gXcIuJBbRi2Va/giphy.gif"
imagetype, size, err := DetectImageType(url)
if err != nil {
t.Error("Failed to detect image type")
}
if size == nil {
t.Error("Failed to detect image size")
}
if imagetype != GIF {
t.Error("Image is not GIF")
}
if size.Width != 500 {
t.Error("Image width is wrong")
}
if size.Height != 286 {
t.Error("Image height is wrong")
}
}
func TestBMPImage(t *testing.T) {
t.Parallel()
url := "http://www.ac-grenoble.fr/ien.vienne1-2/spip/IMG/bmp_Image004.bmp"
imagetype, size, err := DetectImageType(url)
if err != nil {
t.Error("Failed to detect image type")
}
if imagetype != BMP {
t.Error("Image is not BMP")
}
if size != nil {
t.Error("We can't detect BMP size yet")
}
}
func TestTIFFImage(t *testing.T) {
t.Parallel()
url := "http://www.fileformat.info/format/tiff/sample/c44cf1326c2240d38e9fca073bd7a805/download"
imagetype, size, err := DetectImageType(url)
if err != nil {
t.Error("Failed to detect image type")
}
if imagetype != TIFF {
t.Error("Image is not TIFF")
}
if size != nil {
t.Error("We can't detect TIFF size yet")
}
}
func TestCustomTimeout(t *testing.T) {
t.Parallel()
url := "http://loremflickr.com/500/500"
imagetype, size, err := DetectImageTypeWithTimeout(url, 1000)
t.Logf("imageType: %v", imagetype)
t.Logf("size: %v", size)
t.Logf("error: %v", err)
if err == nil {
t.Error("Timeout expected, but not occurred")
}
}