Skip to content

Commit

Permalink
test: plain map/slice CLI flags
Browse files Browse the repository at this point in the history
  • Loading branch information
0xjac committed Oct 7, 2024
1 parent f82931a commit 4165421
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 14 deletions.
27 changes: 27 additions & 0 deletions cmd/avrogen/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,33 @@ func TestAvroGen_GeneratesSchemaWithStrictTypes(t *testing.T) {
assert.Equal(t, want, got)
}

func TestAvroGen_GeneratePlain(t *testing.T) {
for _, opt := range []string{"map", "slice"} {
t.Run(opt, func(t *testing.T) {
t.Parallel()

path := t.TempDir()
file := filepath.Join(path, "test.go")

args := []string{"avrogen", "-pkg", "testpkg", "-o", file, "-plain-" + opt, "testdata/schema.avsc"}
gotCode := realMain(args, io.Discard, io.Discard)
require.Equal(t, 0, gotCode)

got, err := os.ReadFile(file)
require.NoError(t, err)

if *update {
err = os.WriteFile("testdata/golden_plain"+opt+".go", got, 0600)
require.NoError(t, err)
}

want, err := os.ReadFile("testdata/golden_plain" + opt + ".go")
require.NoError(t, err)
assert.Equal(t, want, got)
})
}
}

func TestParseTags(t *testing.T) {
tests := []struct {
name string
Expand Down
6 changes: 4 additions & 2 deletions cmd/avrogen/testdata/golden.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions cmd/avrogen/testdata/golden_encoders.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions cmd/avrogen/testdata/golden_encoders_fullschema.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions cmd/avrogen/testdata/golden_fullname.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions cmd/avrogen/testdata/golden_plainmap.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions cmd/avrogen/testdata/golden_plainslice.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions cmd/avrogen/testdata/golden_stricttypes.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions cmd/avrogen/testdata/schema.avsc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
"doc": "Test is a test struct",
"fields": [
{ "name": "someString", "type": "string", "doc": "SomeString is a string" },
{ "name": "someInt", "type": "int" }
{ "name": "someInt", "type": "int" },
{ "name": "someNullableMap", "type": ["null", {"type": "map", "values": "int"}]},
{ "name": "someNullableSlice", "type": ["null", {"type": "array", "items": "int"}]}
]
}
}

0 comments on commit 4165421

Please sign in to comment.