-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathurl_test.go
60 lines (53 loc) · 1.2 KB
/
url_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
package silverdile_test
import (
"testing"
"github.com/google/go-cmp/cmp"
"github.com/morikuni/failure"
"github.com/sinmetalcraft/silverdile"
)
func TestBuildImageOption(t *testing.T) {
cases := []struct {
name string
url string
want *silverdile.ImageOption
}{
{"s32", "/hoge/fuga/=s32", &silverdile.ImageOption{Bucket: "hoge", Object: "fuga", Size: 32}},
}
for _, tt := range cases {
tt := tt
t.Run(tt.name, func(t *testing.T) {
got, err := silverdile.BuildImageOption(tt.url)
if err != nil {
t.Fatal(err)
}
if !cmp.Equal(got, tt.want) {
t.Errorf("want %+v but got %+v", tt.want, got)
}
})
}
}
func TestBuildImageOptionError(t *testing.T) {
cases := []struct {
name string
url string
want failure.StringCode
}{
{"invalid argument", "/", silverdile.InvalidArgument},
}
for _, tt := range cases {
tt := tt
t.Run(tt.name, func(t *testing.T) {
_, err := silverdile.BuildImageOption(tt.url)
if err == nil {
t.Errorf("not error")
}
code, ok := failure.CodeOf(err)
if !ok {
t.Errorf("want %+v but got nothing code. err=%+v", tt.want, err)
}
if e, g := tt.want, code; e != g {
t.Errorf("want %+v but got %+v", e, g)
}
})
}
}