Skip to content

Commit

Permalink
add test for error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
jtarchie committed Mar 16, 2024
1 parent 94bcb10 commit dbde008
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ linters:

- wrapcheck
- ireturn
- forbidigo

# linters deprecated
- deadcode
Expand Down
11 changes: 11 additions & 0 deletions sqlite_zstd_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,15 @@ var _ = Describe("SqliteZSTD", func() {

waiter.Wait()
})

When("file does not exist", func() {
It("returns an error", func() {
client, err := sql.Open("sqlite3", "file:some.db?vfs=zstd")
Expect(err).ToNot(HaveOccurred())
defer client.Close()

row := client.QueryRow("SELECT * FROM entries ORDER BY RANDOM() LIMIT 1;")
Expect(row.Err()).To(HaveOccurred())
})
})
})
6 changes: 3 additions & 3 deletions vfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,17 @@ func (z *ZstdVFS) FullPathname(name string) string {
func (z *ZstdVFS) Open(name string, flags sqlite3vfs.OpenFlag) (sqlite3vfs.File, sqlite3vfs.OpenFlag, error) {
file, err := os.Open(name)
if err != nil {
return nil, 0, fmt.Errorf("could not open file: %w", err)
return nil, 0, sqlite3vfs.CantOpenError
}

decoder, err := zstd.NewReader(nil)
if err != nil {
return nil, 0, fmt.Errorf("could not create reader: %w", err)
return nil, 0, sqlite3vfs.CantOpenError
}

seekable, err := seekable.NewReader(file, decoder)
if err != nil {
return nil, 0, fmt.Errorf("could not create seekable: %w", err)
return nil, 0, sqlite3vfs.CantOpenError
}

return &ZstdFile{
Expand Down

0 comments on commit dbde008

Please sign in to comment.