forked from hamba/avro
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathencoder_enum_test.go
49 lines (35 loc) · 1.02 KB
/
encoder_enum_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
package avro_test
import (
"bytes"
"testing"
"github.com/hamba/avro"
"github.com/stretchr/testify/assert"
)
func TestEncoder_EnumInvalidType(t *testing.T) {
defer ConfigTeardown()
schema := `{"type":"enum", "name": "test", "symbols": ["foo", "bar"]}`
buf := bytes.NewBuffer([]byte{})
enc, err := avro.NewEncoder(schema, buf)
assert.NoError(t, err)
err = enc.Encode(27)
assert.Error(t, err)
}
func TestEncoder_Enum(t *testing.T) {
defer ConfigTeardown()
schema := `{"type":"enum", "name": "test", "symbols": ["foo", "bar"]}`
buf := bytes.NewBuffer([]byte{})
enc, err := avro.NewEncoder(schema, buf)
assert.NoError(t, err)
err = enc.Encode("bar")
assert.NoError(t, err)
assert.Equal(t, []byte{0x02}, buf.Bytes())
}
func TestEncoder_EnumInvalidSymbol(t *testing.T) {
defer ConfigTeardown()
schema := `{"type":"enum", "name": "test", "symbols": ["foo", "bar"]}`
buf := bytes.NewBuffer([]byte{})
enc, err := avro.NewEncoder(schema, buf)
assert.NoError(t, err)
err = enc.Encode("baz")
assert.Error(t, err)
}