-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathheader_test.go
64 lines (56 loc) · 1.27 KB
/
header_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
package pkg
import (
"bytes"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
var varHeadTests = []VarHeader{
{},
{
SchemaWireBytes: []byte{},
UserData: map[string]string{},
},
{
SchemaWireBytes: []byte("012"),
UserData: map[string]string{},
},
{
SchemaWireBytes: []byte("012345"),
UserData: map[string]string{"abc": "def", "0": "world"},
},
}
func TestVarHeaderSerialization(t *testing.T) {
for _, orig := range varHeadTests {
var buf bytes.Buffer
err := orig.Serialize(&buf)
require.NoError(t, err)
var cpy VarHeader
err = cpy.Deserialize(&buf)
require.NoError(t, err)
if len(orig.SchemaWireBytes) == 0 {
assert.True(t, len(cpy.SchemaWireBytes) == 0)
} else {
assert.EqualValues(t, orig.SchemaWireBytes, cpy.SchemaWireBytes)
}
if len(orig.UserData) == 0 {
assert.True(t, len(cpy.UserData) == 0)
} else {
assert.EqualValues(t, orig.UserData, cpy.UserData)
}
}
}
func FuzzVarHeaderDeserialize(f *testing.F) {
for _, hdr := range varHeadTests {
var buf bytes.Buffer
err := hdr.Serialize(&buf)
require.NoError(f, err)
f.Add(buf.Bytes())
}
f.Fuzz(
func(t *testing.T, data []byte) {
var hdr VarHeader
_ = hdr.Deserialize(bytes.NewBuffer(data))
},
)
}