File tree Expand file tree Collapse file tree 1 file changed +56
-0
lines changed
kadai2/tanaka0325/imgconv Expand file tree Collapse file tree 1 file changed +56
-0
lines changed Original file line number Diff line number Diff line change 1+ package imgconv
2+
3+ import (
4+ "testing"
5+ )
6+
7+ func TestOption_validate (t * testing.T ) {
8+ notAllowdExt := "not_allowed_ext"
9+ jpg := "jpg"
10+ png := "png"
11+ allowedList := []string {jpg , png }
12+
13+ tests := []struct {
14+ name string
15+ options Options
16+ args []string
17+ isErr bool
18+ }{
19+ {
20+ name : "err: Options.From is not allowed" ,
21+ options : Options {
22+ From : & notAllowdExt ,
23+ To : & png ,
24+ },
25+ args : allowedList ,
26+ isErr : true ,
27+ },
28+ {
29+ name : "err: Options.To is not allowed" ,
30+ options : Options {
31+ From : & jpg ,
32+ To : & notAllowdExt ,
33+ },
34+ args : allowedList ,
35+ isErr : true ,
36+ },
37+ {
38+ name : "ok" ,
39+ options : Options {
40+ From : & jpg ,
41+ To : & png ,
42+ },
43+ args : allowedList ,
44+ isErr : false ,
45+ },
46+ }
47+
48+ for _ , tt := range tests {
49+ t .Run (tt .name , func (t * testing.T ) {
50+ err := tt .options .validate (tt .args )
51+ if (tt .isErr && err == nil ) || (! tt .isErr && err != nil ) {
52+ t .Errorf ("expect err is %t, but got err is %s" , tt .isErr , err )
53+ }
54+ })
55+ }
56+ }
You can’t perform that action at this time.
0 commit comments