-
Notifications
You must be signed in to change notification settings - Fork 99
/
encoder_test.go
52 lines (35 loc) · 941 Bytes
/
encoder_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
package avro_test
import (
"bytes"
"testing"
"github.com/hamba/avro/v2"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestNewEncoder_SchemaError(t *testing.T) {
defer ConfigTeardown()
schema := "{}"
_, err := avro.NewEncoder(schema, nil)
assert.Error(t, err)
}
func TestEncoder_EncodeUnsupportedType(t *testing.T) {
defer ConfigTeardown()
schema := avro.NewPrimitiveSchema(avro.Type("test"), nil)
buf := bytes.NewBuffer([]byte{})
enc := avro.NewEncoderForSchema(schema, buf)
err := enc.Encode(true)
assert.Error(t, err)
}
func TestMarshal(t *testing.T) {
defer ConfigTeardown()
schema := avro.MustParse("boolean")
b, err := avro.Marshal(schema, true)
require.NoError(t, err)
assert.Equal(t, []byte{0x01}, b)
}
func TestMarshal_Error(t *testing.T) {
defer ConfigTeardown()
schema := avro.MustParse("int")
_, err := avro.Marshal(schema, true)
assert.Error(t, err)
}