github.com/hamba/avro@v1.8.0/encoder_test.go (about) 1 package avro_test 2 3 import ( 4 "bytes" 5 "testing" 6 7 "github.com/hamba/avro" 8 "github.com/stretchr/testify/assert" 9 ) 10 11 func TestNewEncoder_SchemaError(t *testing.T) { 12 defer ConfigTeardown() 13 14 schema := "{}" 15 _, err := avro.NewEncoder(schema, nil) 16 17 assert.Error(t, err) 18 } 19 20 func TestEncoder_EncodeUnsupportedType(t *testing.T) { 21 defer ConfigTeardown() 22 23 schema := avro.NewPrimitiveSchema(avro.Type("test"), nil) 24 buf := bytes.NewBuffer([]byte{}) 25 enc := avro.NewEncoderForSchema(schema, buf) 26 27 err := enc.Encode(true) 28 29 assert.Error(t, err) 30 } 31 32 func TestMarshal(t *testing.T) { 33 defer ConfigTeardown() 34 35 schema := avro.MustParse("boolean") 36 37 b, err := avro.Marshal(schema, true) 38 39 assert.NoError(t, err) 40 assert.Equal(t, []byte{0x01}, b) 41 } 42 43 func TestMarshal_Error(t *testing.T) { 44 defer ConfigTeardown() 45 46 schema := avro.MustParse("int") 47 48 _, err := avro.Marshal(schema, true) 49 50 assert.Error(t, err) 51 }