Skip to content

Commit

Permalink
Merge pull request #67 from heetch/042-empty-go-struct-fix
Browse files Browse the repository at this point in the history
avro: avoid error on empty Go struct type
  • Loading branch information
rogpeppe authored Mar 31, 2020
2 parents fdc8949 + e50f391 commit 4c8b655
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
4 changes: 3 additions & 1 deletion gotype.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,9 @@ func (gts *goTypeSchema) schemaForGoType(t reflect.Type) (interface{}, error) {
if err != nil {
return nil, err
}
var fields []interface{}
// Note: don't start with nil fields because gogen-avro
// doesn't like the nil value.
fields := []interface{}{}
for i := 0; i < t.NumField(); i++ {
f := t.Field(i)
if f.Anonymous {
Expand Down
11 changes: 11 additions & 0 deletions gotype_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,17 @@ func TestSimpleGoType(t *testing.T) {
wg.Wait()
}

func TestEmptyGoStructType(t *testing.T) {
c := qt.New(t)
type T struct{}
data, wType, err := avro.Marshal(T{})
c.Assert(err, qt.Equals, nil)
var x T
_, err = avro.Unmarshal(data, &x, wType)
c.Assert(err, qt.Equals, nil)
c.Check(x, qt.Equals, T{})
}

func TestGoTypeWithOmittedFields(t *testing.T) {
c := qt.New(t)
type R struct {
Expand Down

0 comments on commit 4c8b655

Please sign in to comment.