forked from h2non/bimg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtype_test.go
89 lines (78 loc) · 1.55 KB
/
type_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
package bimg
import (
"io/ioutil"
"os"
"path"
"testing"
)
func TestDeterminateImageType(t *testing.T) {
files := []struct {
name string
expected ImageType
}{
{"test.jpg", JPEG},
{"test.png", PNG},
{"test.webp", WEBP},
{"test.gif", GIF},
{"test.pdf", PDF},
{"test.svg", SVG},
}
for _, file := range files {
img, _ := os.Open(path.Join("fixtures", file.name))
buf, _ := ioutil.ReadAll(img)
defer img.Close()
if DetermineImageType(buf) != file.expected {
t.Fatal("Image type is not valid")
}
}
}
func TestDeterminateImageTypeName(t *testing.T) {
files := []struct {
name string
expected string
}{
{"test.jpg", "jpeg"},
{"test.png", "png"},
{"test.webp", "webp"},
{"test.gif", "gif"},
{"test.pdf", "pdf"},
{"test.svg", "svg"},
}
for _, file := range files {
img, _ := os.Open(path.Join("fixtures", file.name))
buf, _ := ioutil.ReadAll(img)
defer img.Close()
if DetermineImageTypeName(buf) != file.expected {
t.Fatal("Image type is not valid")
}
}
}
func TestIsTypeSupported(t *testing.T) {
types := []struct {
name ImageType
}{
{JPEG}, {PNG}, {WEBP}, {GIF}, {PDF},
}
for _, n := range types {
if IsTypeSupported(n.name) == false {
t.Fatal("Image type is not valid")
}
}
}
func TestIsTypeNameSupported(t *testing.T) {
types := []struct {
name string
expected bool
}{
{"jpeg", true},
{"png", true},
{"webp", true},
{"gif", true},
{"pdf", true},
}
for _, n := range types {
if IsTypeNameSupported(n.name) != n.expected {
t.Fatal("Image type is not valid")
}
}
}