-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathimgconv_test.go
64 lines (58 loc) · 1.19 KB
/
imgconv_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
package imgconv
import (
"os"
"testing"
)
var tests = []struct {
name string
path string
out string
outFile string
}{
{
name: "jpg to png",
path: "../testdata/imgconv/sample.jpg",
out: "png",
outFile: "../testdata/imgconv/sample.png",
},
{
name: "jpg to gif",
path: "../testdata/imgconv/sample.jpg",
out: "gif",
outFile: "../testdata/imgconv/sample.gif",
},
{
name: "jpg to tif",
path: "../testdata/imgconv/sample.jpg",
out: "tif",
outFile: "../testdata/imgconv/sample.tif",
},
{
name: "jpg to bmp",
path: "../testdata/imgconv/sample.jpg",
out: "bmp",
outFile: "../testdata/imgconv/sample.bmp",
},
}
func TestConvert(t *testing.T) {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
img, err := Decode(test.path)
if err != nil {
t.Fatalf("unexpected error %v", err)
}
err = img.Encode(test.out)
if err != nil {
t.Fatalf("unexpected error %v", err)
}
_, err = os.Stat(test.outFile)
if err != nil {
t.Fatalf("did not create %v", test.outFile)
}
err = os.Remove(test.outFile)
if err != nil {
t.Fatalf("cannot remove %v", test.outFile)
}
})
}
}