Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion db.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,10 @@ func (db *DB) Exist(key []byte) (bool, error) {
// validateOptions validates the given options.
func validateOptions(options *Options) error {
if options.DirPath == "" {
return ErrDBDirectoryISEmpty
options.DirPath = tempDBDir()
if options.DirPath == "" {
return ErrDBDirectoryISEmpty
}
}
if options.MemtableSize <= 0 {
options.MemtableSize = DefaultOptions.MemtableSize
Expand Down
9 changes: 6 additions & 3 deletions db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,14 @@ func TestDBOpen(t *testing.T) {
err = db.Close()
assert.NoError(t, err)
})
t.Run("Invalid options - no directory path", func(t *testing.T) {
t.Run("Empty directory path uses temporary directory", func(t *testing.T) {
options := DefaultOptions
options.DirPath = ""
_, err := Open(options)
require.Error(t, err, "Open should return an error")
db, err := Open(options)
require.NoError(t, err)
require.NotNil(t, db)
defer destroyDB(db)
assert.NotEmpty(t, db.options.DirPath)
})
}

Expand Down
2 changes: 1 addition & 1 deletion options.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ const (
)

var DefaultOptions = Options{
DirPath: tempDBDir(),
DirPath: "",
//nolint:gomnd // default
MemtableSize: 64 * MB,
//nolint:gomnd // default
Expand Down