-
Notifications
You must be signed in to change notification settings - Fork 95
/
decoder_test.go
101 lines (68 loc) · 1.78 KB
/
decoder_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
package avro_test
import (
"bytes"
"testing"
"github.com/hamba/avro/v2"
"github.com/stretchr/testify/assert"
)
func TestNewDecoder_SchemaError(t *testing.T) {
defer ConfigTeardown()
schema := "{}"
_, err := avro.NewDecoder(schema, nil)
assert.Error(t, err)
}
func TestDecoder_DecodeUnsupportedTypeError(t *testing.T) {
defer ConfigTeardown()
data := []byte{0x01}
schema := avro.NewPrimitiveSchema(avro.Type("test"), nil)
dec := avro.NewDecoderForSchema(schema, bytes.NewReader(data))
var b bool
err := dec.Decode(&b)
assert.Error(t, err)
}
func TestDecoder_DecodeEmptyReader(t *testing.T) {
defer ConfigTeardown()
data := []byte{}
schema := "boolean"
dec, _ := avro.NewDecoder(schema, bytes.NewReader(data))
var b bool
err := dec.Decode(b)
assert.Error(t, err)
}
func TestDecoder_DecodeNonPtr(t *testing.T) {
defer ConfigTeardown()
data := []byte{0x01}
schema := "boolean"
dec, _ := avro.NewDecoder(schema, bytes.NewReader(data))
var b bool
err := dec.Decode(b)
assert.Error(t, err)
}
func TestDecoder_DecodeNilPtr(t *testing.T) {
defer ConfigTeardown()
data := []byte{0x01}
schema := "boolean"
dec, _ := avro.NewDecoder(schema, bytes.NewReader(data))
err := dec.Decode((*bool)(nil))
assert.Error(t, err)
}
func TestUnmarshal(t *testing.T) {
defer ConfigTeardown()
schema := avro.MustParse("int")
var i int
err := avro.Unmarshal(schema, []byte{0xE2}, &i)
assert.NoError(t, err)
}
func TestUnmarshal_Ptr(t *testing.T) {
defer ConfigTeardown()
schema := avro.MustParse("boolean")
var b bool
err := avro.Unmarshal(schema, []byte{0x01}, b)
assert.Error(t, err)
}
func TestUnmarshal_NilPtr(t *testing.T) {
defer ConfigTeardown()
schema := avro.MustParse("boolean")
err := avro.Unmarshal(schema, []byte{0x01}, (*bool)(nil))
assert.Error(t, err)
}