Skip to content

Commit e4cdad0

Browse files
committed
add test for img.Enable, img.IsImage
1 parent 2372724 commit e4cdad0

File tree

1 file changed

+123
-0
lines changed

1 file changed

+123
-0
lines changed
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
package img
2+
3+
import (
4+
"reflect"
5+
"testing"
6+
)
7+
8+
func TestEnable(t *testing.T) {
9+
testcases := []struct {
10+
caseName string
11+
iType ImageType
12+
expected []string
13+
}{
14+
{
15+
caseName: "Png: true",
16+
iType: ImageType{Png: true, Jpeg: false, Gif: false},
17+
expected: []string{"png"},
18+
},
19+
{
20+
caseName: "Jpeg: true",
21+
iType: ImageType{Png: false, Jpeg: true, Gif: false},
22+
expected: []string{"jpeg"},
23+
},
24+
{
25+
caseName: "Gif: true",
26+
iType: ImageType{Png: false, Jpeg: false, Gif: true},
27+
expected: []string{"gif"},
28+
},
29+
{
30+
caseName: "Png: true, Jpeg: true",
31+
iType: ImageType{Png: true, Jpeg: true, Gif: false},
32+
expected: []string{"png", "jpeg"},
33+
},
34+
{
35+
caseName: "Jpeg: true, Gif: true",
36+
iType: ImageType{Png: false, Jpeg: true, Gif: true},
37+
expected: []string{"jpeg", "gif"},
38+
},
39+
{
40+
caseName: "Png: true, Jpeg: true, Gif: true",
41+
iType: ImageType{Png: true, Jpeg: true, Gif: true},
42+
expected: []string{"png", "jpeg", "gif"},
43+
},
44+
}
45+
46+
for _, tc := range testcases {
47+
tc := tc // capture range variable. need to set when run parallel test.
48+
49+
t.Run(tc.caseName, func(t *testing.T) {
50+
t.Parallel()
51+
actual := tc.iType.Enable()
52+
if !reflect.DeepEqual(actual, tc.expected) {
53+
t.Errorf("\ncaseName:%s\nactual:%+v\niExpected:%+v\n",
54+
tc.caseName,
55+
actual,
56+
tc.expected,
57+
)
58+
}
59+
})
60+
}
61+
}
62+
63+
func TestAllImageFiles(t *testing.T) {
64+
65+
}
66+
67+
func TestExpectedImageFiles(t *testing.T) {
68+
69+
}
70+
71+
func TestIsImage(t *testing.T) {
72+
testcases := []struct {
73+
caseName string
74+
path string
75+
expected bool
76+
}{
77+
{
78+
caseName: "gif file is image file.",
79+
path: "../testdata/gLenna.gif",
80+
expected: true,
81+
},
82+
{
83+
caseName: "jpeg file is image file.",
84+
path: "../testdata/jLenna.jpg",
85+
expected: true,
86+
},
87+
{
88+
caseName: "png file is image file.",
89+
path: "../testdata/pLenna.png",
90+
expected: true,
91+
},
92+
{
93+
caseName: "empty file is not image file",
94+
path: "../testdata/this_is_not_image.gif",
95+
expected: false,
96+
},
97+
}
98+
99+
for _, tc := range testcases {
100+
tc := tc // capture range variable. need to set when run parallel test.
101+
102+
t.Run(tc.caseName, func(t *testing.T) {
103+
t.Parallel()
104+
actual := IsImage(tc.path)
105+
if !(actual == tc.expected) {
106+
t.Errorf("\ncaseName:%s\nactual:%+v\niExpected:%+v\n",
107+
tc.caseName,
108+
actual,
109+
tc.expected,
110+
)
111+
}
112+
})
113+
}
114+
115+
}
116+
117+
func TestIsExpectedImage(t *testing.T) {
118+
119+
}
120+
121+
func TestConvert(t *testing.T) {
122+
123+
}

0 commit comments

Comments
 (0)