-
Notifications
You must be signed in to change notification settings - Fork 0
/
image_url_test.go
executable file
·119 lines (79 loc) · 2.3 KB
/
image_url_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
package imageurl
import (
"os"
"path/filepath"
"testing"
"github.com/cheekybits/is"
)
/* imageURL.URI = "" */
func TestGetFileName(t *testing.T) {
is := is.New(t)
fileName := SetURI("https://dummyimage.com/600x400/000/fff.jpg").GetFileName()
is.Equal("fff.jpg", fileName)
}
func TestJPGImage(t *testing.T) {
is := is.New(t)
imageType := SetURI("https://dummyimage.com/600x400/000/fff.jpg").GetImageType()
is.Equal("jpg", imageType)
}
// TestJPEGImage ...
func TestJPEGImage(t *testing.T) {
is := is.New(t)
imageType := SetURI("https://dummyimage.com/600x400/000/fff.jpeg").GetImageType()
is.Equal("jpeg", imageType)
}
// TestPNGImage ...
func TestPNGImage(t *testing.T) {
is := is.New(t)
imageType := SetURI("https://dummyimage.com/600x400/000/fff.png").GetImageType()
is.Equal("png", imageType)
}
// TestGIFImage ...
func TestGIFImage(t *testing.T) {
is := is.New(t)
imageType := SetURI("https://dummyimage.com/600x400/000/fff.gif").GetImageType()
is.Equal("gif", imageType)
}
// TestBMPImage ...
func TestBMPImage(t *testing.T) {
is := is.New(t)
imageType := SetURI("http://eeweb.poly.edu/~yao/EL5123/image/lena_gray.bmp").GetImageType()
is.Equal("bmp", imageType)
}
// TestTIFFImage ...
func TestTIFFImage(t *testing.T) {
is := is.New(t)
imageType := SetURI("http://eeweb.poly.edu/~yao/EL5123/image/lena_color.tiff").GetImageType()
is.Equal("tiff", imageType)
}
// TestSVGImage ...
func TestSVGImage(t *testing.T) {
is := is.New(t)
imageType := SetURI("https://placeholder.pics/svg/300").GetImageType()
is.Equal("svg", imageType)
}
// TestGetImageSize ...
func TestGetImageSize(t *testing.T) {
is := is.New(t)
imageSize := SetURI("https://placeholder.pics/svg/300").GetImageSize()
is.Equal(322, imageSize)
}
// TestGetContentType ...
func TestGetContentType(t *testing.T) {
is := is.New(t)
contentType := SetURI("https://placeholder.pics/svg/300").GetContentType()
is.Equal("image/svg+xml", contentType)
}
// TestSaveImage ...
func TestSaveImage(t *testing.T) {
is := is.New(t)
image := SetURI("https://dummyimage.com/600x400/000/fff.png")
file := image.SaveImage("public/images", image.GetFileName())
file.Close()
path := filepath.Join("public/images", image.GetFileName())
if _, err := os.Stat(path); os.IsNotExist(err) {
t.Error(err)
} else {
is.OK("File Exist")
}
}