-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathlayer_test.go
69 lines (62 loc) · 1.42 KB
/
layer_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
package layer
import (
"encoding/json"
"fmt"
"testing"
"github.com/google/go-cmp/cmp"
)
func TestLayer(t *testing.T) {
t.Parallel()
tests := []struct {
name string
in []byte
want *Layer
wantError bool
}{
{
name: "simple",
in: []byte("[\"hoge\",\"bar\"]"),
want: &Layer{
Packages: []string{"hoge", "bar"},
Inside: nil,
Raw: []interface{}{"hoge", "bar"},
},
},
{
name: "nested",
in: []byte("[\"hoge\",\"bar\",12,[\"nesthoge\",\"nestbar\"]]"),
want: &Layer{
Packages: []string{"hoge", "bar"},
Inside: &Layer{
Packages: []string{"nesthoge", "nestbar"},
Inside: nil,
Raw: []interface{}{"nesthoge", "nestbar"},
},
Raw: []interface{}{"hoge", "bar", float64(12), []interface{}{"nesthoge", "nestbar"}},
},
},
{
name: "error",
in: []byte("[\"hoge\",\"bar\"}]"),
wantError: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
got := &Layer{}
if err := json.Unmarshal(tt.in, got); tt.wantError && err == nil {
t.Fatalf("want error, but not error")
} else if !tt.wantError && err != nil {
t.Fatalf("want no err, but has error %#v", err)
}
if !tt.wantError {
if diff := cmp.Diff(got, tt.want); diff != "" {
fmt.Printf("got = %+v\n", got)
fmt.Printf("tt.want = %+v\n", tt.want)
t.Fatalf("diff from want\n%s\n", diff)
}
}
})
}
}