Skip to content

Commit

Permalink
test: plain map and slice options and generation
Browse files Browse the repository at this point in the history
  • Loading branch information
0xjac committed Oct 8, 2024
1 parent 28df012 commit 72cd758
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions gen/gen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,60 @@ func TestStruct_ConfigurableLogicalTypes(t *testing.T) {
}
}

func TestStruct_GenPlain(t *testing.T) {
tt := []struct {
name, schema string
lines []string
cfg gen.Config
}{
{
name: "Map",
schema: `{
"type": "record",
"name": "test",
"fields": [
{ "name": "someRegularMap", "type": {"type": "map", "values": "int"}},
{ "name": "someNullableMap", "type": ["null", {"type": "map", "values": "int"}]}
]
}`,
lines: []string{
"SomeRegularMap map[string]int `avro:\"someRegularMap\"`",
"SomeNullableMap map[string]int `avro:\"someNullableMap\"`",
},
cfg: gen.Config{PackageName: "Something", PlainMap: true},
}, {
name: "Slice",
schema: `{
"type": "record",
"name": "test",
"fields": [
{ "name": "someRegularSlice", "type": {"type": "array", "items": "int"}},
{ "name": "someNullableSlice", "type": ["null", {"type": "array", "items": "int"}]}
]
}`,
lines: []string{
"SomeRegularSlice []int `avro:\"someRegularSlice\"`",
"SomeNullableSlice []int `avro:\"someNullableSlice\"`",
},
cfg: gen.Config{PackageName: "Something", PlainSlice: true},
},
}

for _, test := range tt {
t.Run(test.name, func(t *testing.T) {
t.Parallel()

_, lines := generate(t, test.schema, test.cfg)

for _, line := range test.lines {
assert.Contains(t, lines, line)
}

})
}
}

func TestStruct_GenFromRecordSchema(t *testing.T) {
fileName := "testdata/golden.go"
gc := gen.Config{PackageName: "Something"}
Expand Down

0 comments on commit 72cd758

Please sign in to comment.