Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
4 changes: 3 additions & 1 deletion storage/filedb/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ func NewDB(opts ...Option) *DB {
}
}

db.fs = afero.NewBasePathFs(afero.NewOsFs(), db.rootDir)
if db.fs == nil {
db.fs = afero.NewBasePathFs(afero.NewOsFs(), db.rootDir)
}
Comment thread
bar-bera marked this conversation as resolved.
return db
}

Expand Down
6 changes: 0 additions & 6 deletions storage/filedb/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,13 +181,11 @@ func TestDB_SetExistingKey_CreateError(t *testing.T) {

t.Run(test.name, func(t *testing.T) {
t.Parallel()
fs := afero.NewMemMapFs()
db := file.NewDB(
file.WithRootDirectory("/etc"),
file.WithFileExtension("txt"),
file.WithDirectoryPermissions(0700),
file.WithLogger(log.NewNopLogger()),
file.WithAferoFS(fs),
)
Comment thread
bar-bera marked this conversation as resolved.

if test.setupFunc != nil {
Expand Down Expand Up @@ -237,13 +235,11 @@ func TestDB_SetHas_NotDirError(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
fs := afero.NewMemMapFs()
db := file.NewDB(
file.WithRootDirectory("/etc/passwd"),
file.WithFileExtension("txt"),
file.WithDirectoryPermissions(0700),
file.WithLogger(log.NewNopLogger()),
file.WithAferoFS(fs),
)
Comment thread
bar-bera marked this conversation as resolved.

if tt.setupFunc != nil {
Expand Down Expand Up @@ -280,13 +276,11 @@ func TestDB_Set_MkDirError(t *testing.T) {

t.Run(test.name, func(t *testing.T) {
t.Parallel()
fs := afero.NewMemMapFs()
db := file.NewDB(
file.WithRootDirectory("/etc/test"),
file.WithFileExtension("txt"),
file.WithDirectoryPermissions(0700),
file.WithLogger(log.NewNopLogger()),
file.WithAferoFS(fs),
)
Comment thread
bar-bera marked this conversation as resolved.

if test.setupFunc != nil {
Expand Down
12 changes: 6 additions & 6 deletions storage/filedb/range_db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ func TestRangeDB_Invariants(t *testing.T) {
},
testFunc: func(t *testing.T, rdb *file.RangeDB) {
t.Helper()
requireNotExist(t, rdb, 0, lastConsequetiveNilIndex(rdb))
requireNotExist(t, rdb, 0, lastConsecutiveNilIndex(rdb))
},
},
{
Expand All @@ -303,7 +303,7 @@ func TestRangeDB_Invariants(t *testing.T) {
testFunc: func(t *testing.T, rdb *file.RangeDB) {
t.Helper()
_ = rdb.Delete(2, []byte("key"))
requireNotExist(t, rdb, 0, lastConsequetiveNilIndex(rdb))
requireNotExist(t, rdb, 0, lastConsecutiveNilIndex(rdb))
},
},
{
Expand All @@ -314,7 +314,7 @@ func TestRangeDB_Invariants(t *testing.T) {
testFunc: func(t *testing.T, rdb *file.RangeDB) {
t.Helper()
_ = rdb.Prune(0, 3)
requireNotExist(t, rdb, 0, lastConsequetiveNilIndex(rdb))
requireNotExist(t, rdb, 0, lastConsecutiveNilIndex(rdb))
},
},
{
Expand All @@ -328,7 +328,7 @@ func TestRangeDB_Invariants(t *testing.T) {
t.Fatalf("Prune() error = %v", err)
}
_ = populateTestDB(rdb, 5, 10)
requireNotExist(t, rdb, 0, lastConsequetiveNilIndex(rdb))
requireNotExist(t, rdb, 0, lastConsecutiveNilIndex(rdb))
},
},
}
Expand All @@ -343,7 +343,7 @@ func TestRangeDB_Invariants(t *testing.T) {
t,
rdb,
0,
lastConsequetiveNilIndex(rdb),
lastConsecutiveNilIndex(rdb),
)
}
}
Expand Down Expand Up @@ -408,7 +408,7 @@ func getFirstNonNilIndex(rdb *file.RangeDB) uint64 {
return reflect.ValueOf(rdb).Elem().FieldByName("lowerBoundIndex").Uint()
}

func lastConsequetiveNilIndex(rdb *file.RangeDB) uint64 {
func lastConsecutiveNilIndex(rdb *file.RangeDB) uint64 {
return uint64(max(int64(getFirstNonNilIndex(rdb))-1, 0))
}

Expand Down
Loading