Skip to content
This repository has been archived by the owner on Nov 16, 2023. It is now read-only.

Commit

Permalink
add tests for creating reader with broken file
Browse files Browse the repository at this point in the history
this test illustrates the need for New(Generic)ReaderWithError
  • Loading branch information
SgtCoDFish committed Aug 11, 2022
1 parent 3db15e7 commit 07c2849
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 0 deletions.
4 changes: 4 additions & 0 deletions file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ var testdataFiles []string
func init() {
entries, _ := os.ReadDir("testdata")
for _, e := range entries {
if e.IsDir() {
continue
}

testdataFiles = append(testdataFiles, filepath.Join("testdata", e.Name()))
}
}
Expand Down
18 changes: 18 additions & 0 deletions reader_go18_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"fmt"
"io"
"math/rand"
"os"
"path/filepath"
"reflect"
"testing"

Expand Down Expand Up @@ -161,3 +163,19 @@ func benchmarkGenericReader[Row generator[Row]](b *testing.B) {
})
})
}

func TestGenericReaderFailure(t *testing.T) {
invalidFileName := filepath.Join("testdata", "invalid", "not_enough_columns.invalid.parquet")

file, err := os.Open(invalidFileName)
if err != nil {
t.Fatalf("failed to read %q: %s", invalidFileName, err.Error())
}

defer file.Close()

_, err = parquet.NewGenericReaderWithError[map[string]any](file)
if err == nil {
t.Fatalf("expected an error when trying to open invalid file %q, but didn't get one", invalidFileName)
}
}
18 changes: 18 additions & 0 deletions reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"io"
"math"
"math/rand"
"os"
"path/filepath"
"reflect"
"testing"

Expand Down Expand Up @@ -535,3 +537,19 @@ func TestSeekToRowDictReadMultiplePages(t *testing.T) {
t.Fatalf("read != write")
}
}

func TestReaderFailure(t *testing.T) {
invalidFileName := filepath.Join("testdata", "invalid", "not_enough_columns.invalid.parquet")

file, err := os.Open(invalidFileName)
if err != nil {
t.Fatalf("failed to read %q: %s", invalidFileName, err.Error())
}

defer file.Close()

_, err = parquet.NewReaderWithError(file)
if err == nil {
t.Fatalf("expected an error when trying to open invalid file %q, but didn't get one", invalidFileName)
}
}
Binary file added testdata/invalid/not_enough_columns.invalid.parquet
Binary file not shown.

0 comments on commit 07c2849

Please sign in to comment.