-
Notifications
You must be signed in to change notification settings - Fork 1
/
da_mode_enum_test.go
59 lines (55 loc) · 1.01 KB
/
da_mode_enum_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
package data
import (
"testing"
"github.com/goccy/go-json"
"github.com/stretchr/testify/require"
)
func TestDAMode_UnmarshalJSON(t *testing.T) {
tests := []struct {
name string
want DAMode
text []byte
wantErr bool
}{
{
name: "test 1",
want: DAModeL1,
text: []byte(`{"mode":0}`),
}, {
name: "test 2",
want: DAModeL2,
text: []byte(`{"mode":1}`),
}, {
name: "test 3",
want: DAModeL1,
text: []byte(`{"mode":"L1"}`),
}, {
name: "test 4",
want: DAModeL2,
text: []byte(`{"mode":"L2"}`),
}, {
name: "test 5",
text: []byte(`{"mode":10}`),
wantErr: true,
}, {
name: "test 6",
text: []byte(`{"mode":"10"}`),
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
type buf struct {
Mode DAMode `json:"mode"`
}
var x buf
err := json.Unmarshal(tt.text, &x)
if tt.wantErr {
require.Error(t, err)
} else {
require.NoError(t, err)
require.Equal(t, tt.want, x.Mode)
}
})
}
}