@@ -50,7 +50,7 @@ func TestEnable(t *testing.T) {
50
50
t .Parallel ()
51
51
actual := tc .iType .Enable ()
52
52
if ! reflect .DeepEqual (actual , tc .expected ) {
53
- t .Errorf ("\n caseName:%s\n actual:%+v\n iExpected :%+v\n " ,
53
+ t .Errorf ("\n caseName:%s\n actual:%+v\n Expected :%+v\n " ,
54
54
tc .caseName ,
55
55
actual ,
56
56
tc .expected ,
@@ -65,6 +65,86 @@ func TestAllImageFiles(t *testing.T) {
65
65
}
66
66
67
67
func TestExpectedImageFiles (t * testing.T ) {
68
+ testcases := []struct {
69
+ caseName string
70
+ files []string
71
+ iType ImageType
72
+ expected []string
73
+ }{
74
+ {
75
+ caseName : "png is expected image type." ,
76
+ files : []string {
77
+ "../testdata/pLenna.png" ,
78
+ "../testdata/jLenna.jpg" ,
79
+ "../testdata/gLenna.gif" ,
80
+ "../testdata/chdir/pLenna.png" ,
81
+ "../testdata/chdir/jLenna.jpeg" ,
82
+ "../testdata/chdir/gLenna.gif" ,
83
+ "../testdata/this_is_not_image.png" ,
84
+ "../testdata/this_is_not_image.jpg" ,
85
+ "../testdata/this_is_not_image.gif" ,
86
+ },
87
+ iType : ImageType {Png : true , Jpeg : false , Gif : false },
88
+ expected : []string {
89
+ "../testdata/pLenna.png" ,
90
+ "../testdata/chdir/pLenna.png" ,
91
+ },
92
+ },
93
+ {
94
+ caseName : "jpg is expected image type." ,
95
+ files : []string {
96
+ "../testdata/pLenna.png" ,
97
+ "../testdata/jLenna.jpg" ,
98
+ "../testdata/gLenna.gif" ,
99
+ "../testdata/chdir/pLenna.png" ,
100
+ "../testdata/chdir/jLenna.jpeg" ,
101
+ "../testdata/chdir/gLenna.gif" ,
102
+ "../testdata/this_is_not_image.png" ,
103
+ "../testdata/this_is_not_image.jpg" ,
104
+ "../testdata/this_is_not_image.gif" ,
105
+ },
106
+ iType : ImageType {Png : false , Jpeg : true , Gif : false },
107
+ expected : []string {
108
+ "../testdata/jLenna.jpg" ,
109
+ "../testdata/chdir/jLenna.jpeg" ,
110
+ },
111
+ },
112
+ {
113
+ caseName : "gif is expected image type." ,
114
+ files : []string {
115
+ "../testdata/pLenna.png" ,
116
+ "../testdata/jLenna.jpg" ,
117
+ "../testdata/gLenna.gif" ,
118
+ "../testdata/chdir/pLenna.png" ,
119
+ "../testdata/chdir/jLenna.jpeg" ,
120
+ "../testdata/chdir/gLenna.gif" ,
121
+ "../testdata/this_is_not_image.png" ,
122
+ "../testdata/this_is_not_image.jpg" ,
123
+ "../testdata/this_is_not_image.gif" ,
124
+ },
125
+ iType : ImageType {Png : false , Jpeg : false , Gif : true },
126
+ expected : []string {
127
+ "../testdata/gLenna.gif" ,
128
+ "../testdata/chdir/gLenna.gif" ,
129
+ },
130
+ },
131
+ }
132
+
133
+ for _ , tc := range testcases {
134
+ tc := tc // capture range variable. need to set when run parallel test.
135
+
136
+ t .Run (tc .caseName , func (t * testing.T ) {
137
+ t .Parallel ()
138
+ actual := ExpectedImageFiles (tc .files , tc .iType )
139
+ if ! reflect .DeepEqual (actual , tc .expected ) {
140
+ t .Errorf ("\n caseName:%s\n actual:%+v\n Expected:%+v\n " ,
141
+ tc .caseName ,
142
+ actual ,
143
+ tc .expected ,
144
+ )
145
+ }
146
+ })
147
+ }
68
148
69
149
}
70
150
@@ -108,7 +188,7 @@ func TestIsImage(t *testing.T) {
108
188
t .Parallel ()
109
189
actual := IsImage (tc .path )
110
190
if ! (actual == tc .expected ) {
111
- t .Errorf ("\n caseName:%s\n actual:%+v\n iExpected :%+v\n " ,
191
+ t .Errorf ("\n caseName:%s\n actual:%+v\n Expected :%+v\n " ,
112
192
tc .caseName ,
113
193
actual ,
114
194
tc .expected ,
@@ -120,6 +200,72 @@ func TestIsImage(t *testing.T) {
120
200
}
121
201
122
202
func TestIsExpectedImage (t * testing.T ) {
203
+ testcases := []struct {
204
+ caseName string
205
+ path string
206
+ iType ImageType
207
+ expected bool
208
+ }{
209
+ {
210
+ caseName : "png file is expected image file." ,
211
+ path : "../testdata/pLenna.png" ,
212
+ iType : ImageType {Png : true , Jpeg : false , Gif : false },
213
+ expected : true ,
214
+ },
215
+ {
216
+ caseName : "jpeg file is expected image file." ,
217
+ path : "../testdata/jLenna.jpg" ,
218
+ iType : ImageType {Png : false , Jpeg : true , Gif : false },
219
+ expected : true ,
220
+ },
221
+ {
222
+ caseName : "gif file is expected image file." ,
223
+ path : "../testdata/gLenna.gif" ,
224
+ iType : ImageType {Png : false , Jpeg : false , Gif : true },
225
+ expected : true ,
226
+ },
227
+
228
+ {
229
+ caseName : "png file is unexpected image file." ,
230
+ path : "../testdata/pLenna.png" ,
231
+ iType : ImageType {Png : false , Jpeg : true , Gif : true },
232
+ expected : false ,
233
+ },
234
+ {
235
+ caseName : "jpeg file is unexpected image file." ,
236
+ path : "../testdata/jLenna.jpg" ,
237
+ iType : ImageType {Png : true , Jpeg : false , Gif : true },
238
+ expected : false ,
239
+ },
240
+ {
241
+ caseName : "gif file is unexpected image file." ,
242
+ path : "../testdata/gLenna.gif" ,
243
+ iType : ImageType {Png : true , Jpeg : true , Gif : false },
244
+ expected : false ,
245
+ },
246
+
247
+ {
248
+ caseName : "does not existed." ,
249
+ path : "../testdata/does_not_existed.gif" ,
250
+ expected : false ,
251
+ },
252
+ }
253
+
254
+ for _ , tc := range testcases {
255
+ tc := tc // capture range variable. need to set when run parallel test.
256
+
257
+ t .Run (tc .caseName , func (t * testing.T ) {
258
+ t .Parallel ()
259
+ actual := IsExpectedImage (tc .path , tc .iType )
260
+ if ! (actual == tc .expected ) {
261
+ t .Errorf ("\n caseName:%s\n actual:%+v\n Expected:%+v\n " ,
262
+ tc .caseName ,
263
+ actual ,
264
+ tc .expected ,
265
+ )
266
+ }
267
+ })
268
+ }
123
269
124
270
}
125
271
0 commit comments