-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathconvert_test.go
70 lines (58 loc) · 1.32 KB
/
convert_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
package imgconv
import (
"bytes"
"io"
"os"
"testing"
)
func TestDecodeWrite(t *testing.T) {
var formats = []string{
"jpg",
"png",
"gif",
"tif",
"bmp",
"webp",
"pdf",
}
for _, i := range formats {
b, err := os.ReadFile("testdata/video-001." + i)
if err != nil {
t.Fatal(err)
}
img, err := Decode(bytes.NewBuffer(b))
if err != nil {
t.Fatal("Failed to decode", i)
}
if err := Write(io.Discard, img, &FormatOption{}); err != nil {
t.Fatal("Failed to write", i)
}
if _, _, err := DecodeConfig(bytes.NewBuffer(b)); err != nil {
t.Fatal("Failed to decode", i, "config")
}
}
if _, err := Decode(bytes.NewBufferString("Hello")); err == nil {
t.Fatal("Decode string want error")
}
}
func TestOpenSave(t *testing.T) {
if _, err := Open("/invalid/path"); err == nil {
t.Error("Open invalid path want error")
}
if _, err := Open("go.mod"); err == nil {
t.Error("Open invalid image want error")
}
img, err := Open("testdata/video-001.png")
if err != nil {
t.Fatal("Fail to open image", err)
}
if err := Save("/invalid/path", img, defaultFormat); err == nil {
t.Fatal("Save invalid path want error")
}
if err := Save("testdata/tmp", img, defaultFormat); err != nil {
t.Fatal("Fail to save image", err)
}
if err := os.Remove("testdata/tmp"); err != nil {
t.Fatal(err)
}
}