Skip to content

Commit

Permalink
Add unit test with a file as a fixture
Browse files Browse the repository at this point in the history
  • Loading branch information
papanikge committed Jul 16, 2024
1 parent dcad62d commit baeea99
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions ocf/ocf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,40 @@ func TestDecoder_WithDeflate(t *testing.T) {
assert.Equal(t, 1, count)
}

func TestDecoder_InvalidName(t *testing.T) {
type record struct {
Hello int `avro:"hello"`
What string `avro:"what"`
}
want := record{
What: "yes",
Hello: 1,
}

f, err := os.Open("testdata/invalid-name.avro")
if err != nil {
t.Error(err)
return
}
t.Cleanup(func() { _ = f.Close() })

dec, err := ocf.NewDecoder(f, ocf.WithSkipNameValidation(true))
require.NoError(t, err)

var count int
for dec.HasNext() {
count++
var got record
err = dec.Decode(&got)

require.NoError(t, err)
assert.Equal(t, want, got)
}

require.NoError(t, dec.Error())
assert.Equal(t, 1, count)
}

func TestDecoder_WithDeflateHandlesInvalidData(t *testing.T) {
f, err := os.Open("testdata/deflate-invalid-data.avro")
if err != nil {
Expand Down
Binary file modified ocf/testdata/invalid-name.avro
Binary file not shown.

0 comments on commit baeea99

Please sign in to comment.