generated from gopherdojo/template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions_test.go
57 lines (52 loc) · 1.02 KB
/
options_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
package imgconv_test
import (
"testing"
"github.com/gopherdojo/dojo8/kadai2/tanaka0325/imgconv"
)
func TestOptionsValidate(t *testing.T) {
notAllowdExt := "not_allowed_ext"
jpg := "jpg"
png := "png"
allowedList := []string{jpg, png}
tests := []struct {
name string
options imgconv.Options
args []string
isErr bool
}{
{
name: "err:Options.From is not allowed",
options: imgconv.Options{
From: ¬AllowdExt,
To: &png,
},
args: allowedList,
isErr: true,
},
{
name: "err:Options.To is not allowed",
options: imgconv.Options{
From: &jpg,
To: ¬AllowdExt,
},
args: allowedList,
isErr: true,
},
{
name: "ok",
options: imgconv.Options{
From: &jpg,
To: &png,
},
args: allowedList,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := tt.options.Validate(tt.args)
if (tt.isErr && err == nil) || (!tt.isErr && err != nil) {
t.Errorf("expect err is %t, but got err is %s", tt.isErr, err)
}
})
}
}