forked from hamba/avro
-
Notifications
You must be signed in to change notification settings - Fork 0
/
reader_skip_test.go
155 lines (118 loc) · 3.03 KB
/
reader_skip_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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
package avro_test
import (
"bytes"
"testing"
"github.com/hamba/avro/v2"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestReader_SkipNBytes(t *testing.T) {
data := []byte{0x01, 0x01, 0x01, 0x36}
r := avro.NewReader(bytes.NewReader(data), 2)
r.SkipNBytes(3)
require.NoError(t, r.Error)
assert.Equal(t, int32(27), r.ReadInt())
}
func TestReader_SkipNBytesEOF(t *testing.T) {
data := []byte{0x01, 0x36}
r := avro.NewReader(bytes.NewReader(data), 2)
r.SkipNBytes(3)
assert.Error(t, r.Error)
}
func TestReader_SkipBool(t *testing.T) {
data := []byte{0x01, 0x36}
r := avro.NewReader(bytes.NewReader(data), 10)
r.SkipBool()
require.NoError(t, r.Error)
assert.Equal(t, int32(27), r.ReadInt())
}
func TestReader_SkipInt(t *testing.T) {
tests := []struct {
name string
data []byte
}{
{
name: "Skipped",
data: []byte{0x38, 0x36},
},
{
name: "Overflow",
data: []byte{0xE2, 0xA2, 0xF3, 0xAD, 0xAD, 0x36},
},
}
for _, test := range tests {
test := test
t.Run(test.name, func(t *testing.T) {
r := avro.NewReader(bytes.NewReader(test.data), 10)
r.SkipInt()
require.NoError(t, r.Error)
assert.Equal(t, int32(27), r.ReadInt())
})
}
}
func TestReader_SkipLong(t *testing.T) {
tests := []struct {
name string
data []byte
}{
{
name: "Skipped",
data: []byte{0x38, 0x36},
},
{
name: "Overflow",
data: []byte{0xE2, 0xA2, 0xF3, 0xAD, 0xAD, 0xAD, 0xE2, 0xA2, 0xF3, 0xAD, 0x36},
},
}
for _, test := range tests {
test := test
t.Run(test.name, func(t *testing.T) {
r := avro.NewReader(bytes.NewReader(test.data), 10)
r.SkipLong()
require.NoError(t, r.Error)
assert.Equal(t, int32(27), r.ReadInt())
})
}
}
func TestReader_SkipFloat(t *testing.T) {
data := []byte{0x00, 0x00, 0x00, 0x00, 0x36}
r := avro.NewReader(bytes.NewReader(data), 10)
r.SkipFloat()
require.NoError(t, r.Error)
assert.Equal(t, int32(27), r.ReadInt())
}
func TestReader_SkipDouble(t *testing.T) {
data := []byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36}
r := avro.NewReader(bytes.NewReader(data), 10)
r.SkipDouble()
require.NoError(t, r.Error)
assert.Equal(t, int32(27), r.ReadInt())
}
func TestReader_SkipString(t *testing.T) {
data := []byte{0x06, 0x66, 0x6F, 0x6F, 0x36}
r := avro.NewReader(bytes.NewReader(data), 10)
r.SkipString()
require.NoError(t, r.Error)
assert.Equal(t, int32(27), r.ReadInt())
}
func TestReader_SkipStringEmpty(t *testing.T) {
data := []byte{0x00, 0x36}
r := avro.NewReader(bytes.NewReader(data), 10)
r.SkipString()
require.NoError(t, r.Error)
assert.Equal(t, int32(27), r.ReadInt())
}
func TestReader_SkipBytes(t *testing.T) {
data := []byte{0x06, 0x66, 0x6F, 0x6F, 0x36}
r := avro.NewReader(bytes.NewReader(data), 10)
r.SkipBytes()
require.NoError(t, r.Error)
assert.Equal(t, int32(27), r.ReadInt())
}
func TestReader_SkipBytesEmpty(t *testing.T) {
data := []byte{0x00, 0x36}
r := avro.NewReader(bytes.NewReader(data), 10)
r.SkipBytes()
require.NoError(t, r.Error)
assert.Equal(t, int32(27), r.ReadInt())
}