-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimage_test.go
103 lines (99 loc) ยท 2.83 KB
/
image_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
package main
import (
"bytes"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
"io/ioutil"
"testing"
)
// echo์ request handler์์ file์ decode ํ๋ ๊ณผ์ ์ ํ
์คํธ
func TestDecodeImageFile(t *testing.T) {
for i, tc := range []struct {
filename string
expectedExt string
}{
{filename: "test/test_bmp.bmp", expectedExt: "png"},
{filename: "test/test_bmp", expectedExt: "png"},
{filename: "test/test_gif", expectedExt: "gif"},
{filename: "test/test_gif.gif", expectedExt: "gif"},
{filename: "test/test_jpeg", expectedExt: "jpeg"},
{filename: "test/test_jpeg.jpg", expectedExt: "jpeg"},
{filename: "test/test_jpeg.jpeg", expectedExt: "jpeg"},
{filename: "test/test_png", expectedExt: "png"},
{filename: "test/test_png.png", expectedExt: "png"},
} {
logrus.Infof("Test Case[%d] - %s", i, tc)
data, err := ioutil.ReadFile(tc.filename)
assert.NoError(t, err)
imageData, _, gifImageData, ext, err := DecodeImageFile(bytes.NewReader(data))
assert.NoError(t, err)
assert.Equal(t, tc.expectedExt, ext)
if tc.expectedExt == "gif" {
assert.Nil(t, imageData)
assert.NotNil(t, gifImageData)
} else {
assert.NotNil(t, imageData)
assert.Nil(t, gifImageData)
}
}
}
//type parseImageFileNameTestCase struct {
// originalFileName string
// parsedFileName string
// extensionName string
// isError bool
//}
//
//func TestParseImageFileName(t *testing.T) {
// cases := []*parseImageFileNameTestCase{
// &parseImageFileNameTestCase{
// originalFileName: "abc.jpg",
// parsedFileName: "abc",
// extensionName: "jpeg",
// },
// &parseImageFileNameTestCase{
// originalFileName: "abc.jpeg",
// parsedFileName: "abc",
// extensionName: "jpeg",
// },
// &parseImageFileNameTestCase{
// originalFileName: "abc.png",
// parsedFileName: "abc",
// extensionName: "png",
// },
// &parseImageFileNameTestCase{
// originalFileName: "my.name.is.jinsu.jpg",
// parsedFileName: "my.name.is.jinsu",
// extensionName: "jpeg", // jpg๋ ์ฌ์ฉํ์ง ์์.
// },
// &parseImageFileNameTestCase{
// originalFileName: "my name is jinsu.jpg",
// parsedFileName: "my name is jinsu",
// extensionName: "jpeg",
// },
// &parseImageFileNameTestCase{
// originalFileName: ".bit",
// isError: true,
// },
// &parseImageFileNameTestCase{
// originalFileName: "cowboy",
// isError: true,
// },
// &parseImageFileNameTestCase{
// originalFileName: "",
// isError: true,
// },
// }
// for _, c := range cases {
// t.Run(c.originalFileName, func(t *testing.T) {
// name, ext, err := ParseImageFileName(c.originalFileName)
// if c.isError {
// assert.NotNil(t, err)
// } else {
// assert.Nil(t, err)
// assert.Equal(t, c.parsedFileName, name)
// assert.Equal(t, c.extensionName, ext)
// }
// })
// }
//}