-
Notifications
You must be signed in to change notification settings - Fork 1
/
parse_test.go
88 lines (81 loc) · 1.62 KB
/
parse_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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package bstore
import (
"errors"
"reflect"
"testing"
"time"
)
func FuzzParse(f *testing.F) {
type Sub struct {
ID int
Email string
}
type Mapkey struct {
K1 int
K2 string
}
type Mapvalue struct {
Data []byte
Time *time.Time
}
type User struct {
ID int64
Name string
Registered time.Time
Byte byte
Int8 int8
Int16 int16
Int32 int32
Int64 int64
Uint64 uint64
Float32 float32
Float64 float64
String string
Bytes []byte
Struct Sub
Slice []string
Map map[string]struct{}
Map2 map[Mapkey]Mapvalue
Time time.Time
Coords [2]float64
BM bm
Byteptr *byte
Int8ptr *int8
Int16ptr *int16
Int32ptr *int32
Int64ptr *int64
Uint64ptr *uint64
Float32ptr *float32
Float64ptr *float64
Stringptr *string
Bytesptr *[]byte
Structptr *Sub
Sliceptr *[]string
Mapptr *map[string]struct{}
Map2ptr *map[Mapkey]Mapvalue
Timeptr *time.Time
CoordsPtr *[2]float64
BMptr *bm
}
t := reflect.TypeOf(User{})
tv, err := gatherTypeVersion(t)
if err != nil {
f.Fatalf("type version: %v", err)
}
st := storeType{
Type: t,
Current: tv,
Versions: map[uint32]*typeVersion{tv.Version: tv},
}
f.Fuzz(func(t *testing.T, key, value []byte) {
v := reflect.New(st.Type).Elem()
err := st.parse(v, value)
if err != nil && !errors.Is(err, ErrStore) && !errors.Is(err, ErrZero) {
t.Errorf("unexpected error %v", err)
}
_, err = parseMap(st.Versions, key, value)
if err != nil && !errors.Is(err, ErrStore) && !errors.Is(err, ErrZero) {
t.Errorf("unexpected error %v", err)
}
})
}