Skip to content

Commit

Permalink
leveldb: fix empty opts causing panic and add test
Browse files Browse the repository at this point in the history
  • Loading branch information
postables committed May 9, 2020
1 parent 862d402 commit cc52fd8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
5 changes: 4 additions & 1 deletion leveldb/datastore.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ type Options = opt.Options

// NewDatastore returns a new datastore backed by leveldb
func NewDatastore(path string, opts *Options) (*Datastore, error) {
noSync := opts.NoSync
var noSync bool
if opts != nil {
noSync = opts.NoSync
}
db, err := leveldb.OpenFile(path, opts)
if err != nil {
return nil, err
Expand Down
12 changes: 12 additions & 0 deletions leveldb/ds_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,18 @@ func testQuery(t *testing.T, d *Datastore) {
expectOrderedMatches(t, keys, rs)
}

func TestEmptyOpts(t *testing.T) {
path := "emptyoptstest"
ds, err := NewDatastore(path, nil)
if err != nil {
t.Fatal(err)
}
if err := ds.Close(); err != nil {
t.Fatal(err)
}
os.RemoveAll(path)
}

func TestQuery(t *testing.T) {
d, close := newDS(t)
defer close()
Expand Down

0 comments on commit cc52fd8

Please sign in to comment.