-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathworker_test.go
71 lines (66 loc) · 1.37 KB
/
worker_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
package main
import (
"fmt"
"testing"
)
type rptestcase struct {
Path string
Size string
Output string
}
func Test_resizedPath(t *testing.T) {
var testCases = []rptestcase{
{"/foo/bar/image.jpg", "100w", "/foo/bar/100w.jpg"},
{"image.jpg", "200w", "./200w.jpg"},
// this is current behavior, but should it fail instead?
{"/foo/bar/image.jpg", "", "/foo/bar/.jpg"},
}
for _, tc := range testCases {
if tc.Output != resizedPath(tc.Path, tc.Size) {
t.Error("incorrect output")
}
}
}
type catestcase struct {
Size string
Path string
ConvertBin string
Output []string
}
func Test_convertArgs(t *testing.T) {
var testCases = []catestcase{
{"100s", "/foo/bar/image.jpg", "/usr/bin/convert",
[]string{
"/usr/bin/convert",
"-resize",
"100x100^",
"-auto-orient",
"-gravity",
"center",
"-extent",
"100x100",
"/foo/bar/image.jpg",
"/foo/bar/100s.jpg",
},
},
{"100w", "/foo/bar/image.jpg", "/usr/bin/convert",
[]string{
"/usr/bin/convert",
"-auto-orient",
"-resize",
"100",
"/foo/bar/image.jpg",
"/foo/bar/100w.jpg",
},
},
}
for _, tc := range testCases {
output := convertArgs(tc.Size, tc.Path, tc.ConvertBin)
for i := range output {
if tc.Output[i] != output[i] {
fmt.Printf("%s %s\n", tc.Output[i], output[i])
t.Error("incorrect convert args")
}
}
}
}