diff --git a/db.go b/db.go index c5a028d..85716c9 100644 --- a/db.go +++ b/db.go @@ -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 diff --git a/db_test.go b/db_test.go index 5c479f8..cdca990 100644 --- a/db_test.go +++ b/db_test.go @@ -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) }) } diff --git a/options.go b/options.go index 274a4ff..33a6550 100644 --- a/options.go +++ b/options.go @@ -130,7 +130,7 @@ const ( ) var DefaultOptions = Options{ - DirPath: tempDBDir(), + DirPath: "", //nolint:gomnd // default MemtableSize: 64 * MB, //nolint:gomnd // default