Improve test coverage
This commit is contained in:
parent
427673778f
commit
b85255196b
|
@ -172,13 +172,10 @@ const (
|
|||
// In the case of an error, withAll will continue and return a compound form of any errors that occurred.
|
||||
// For now this is just for Close and Sync, thusly it does a hard lock on the Keeper.
|
||||
func (db *DB) withAll(action withAllAction) error {
|
||||
if len(db.store) == 0 {
|
||||
if db == nil || db.store == nil || len(db.store) < 1 {
|
||||
return ErrNoStores
|
||||
}
|
||||
var errs = make([]error, len(db.store))
|
||||
if len(db.store) < 1 {
|
||||
return ErrNoStores
|
||||
}
|
||||
for name, store := range db.store {
|
||||
var err error
|
||||
if store.Bitcask == nil {
|
||||
|
|
|
@ -38,9 +38,6 @@ func (s Store) ValueExists(value []byte) (key []byte, ok bool) {
|
|||
var needle = kv.NewValue(value)
|
||||
for _, key = range s.Keys() {
|
||||
raw, _ = s.Get(key)
|
||||
if len(key) == 0 {
|
||||
continue
|
||||
}
|
||||
v := kv.NewValue(raw)
|
||||
if v.Equal(needle) {
|
||||
ok = true
|
||||
|
@ -65,10 +62,7 @@ func (s Store) PrefixScan(prefix string) (<-chan *kv.KeyValue, chan error) {
|
|||
close(errChan)
|
||||
}(err)
|
||||
err = s.Scan([]byte(prefix), func(key []byte) error {
|
||||
raw, err := s.Get(key)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
raw, _ := s.Get(key)
|
||||
if key != nil && raw != nil {
|
||||
k := kv.NewKey(key)
|
||||
resChan <- kv.NewKeyValue(k, kv.NewValue(raw))
|
||||
|
|
|
@ -150,7 +150,6 @@ func TestDB_Init(t *testing.T) { //nolint:funlen,gocognit,cyclop
|
|||
t.Fatalf("[FAIL] got compound error: %e", err)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("closeAll", func(t *testing.T) {
|
||||
t.Cleanup(func() {
|
||||
err := os.RemoveAll("./testdata")
|
||||
|
@ -165,7 +164,6 @@ func TestDB_Init(t *testing.T) { //nolint:funlen,gocognit,cyclop
|
|||
}
|
||||
db = nil
|
||||
})
|
||||
|
||||
t.Run("SyncAndCloseAll", func(t *testing.T) {
|
||||
db = newTestDB(t)
|
||||
seedRandStores(db, t)
|
||||
|
@ -229,12 +227,21 @@ func Test_Close(t *testing.T) {
|
|||
|
||||
func Test_withAll(t *testing.T) {
|
||||
var db = newTestDB(t)
|
||||
defer db.CloseAll()
|
||||
t.Run("withAllNoStores", func(t *testing.T) {
|
||||
err := db.withAll(121)
|
||||
if !errors.Is(err, ErrNoStores) {
|
||||
t.Errorf("[FAIL] got err %e, wanted err %e", err, ErrNoStores)
|
||||
}
|
||||
})
|
||||
t.Run("withAllNilMap", func(t *testing.T) {
|
||||
nilDb := newTestDB(t)
|
||||
nilDb.store = nil
|
||||
err := nilDb.withAll(dclose)
|
||||
if err == nil {
|
||||
t.Errorf("[FAIL] got nil err from trying to work on nil map, wanted err")
|
||||
}
|
||||
})
|
||||
t.Run("withAllBogusAction", func(t *testing.T) {
|
||||
err := db.Init("asdf")
|
||||
if err != nil {
|
||||
|
@ -306,6 +313,16 @@ func Test_withAll(t *testing.T) {
|
|||
}
|
||||
}
|
||||
})
|
||||
t.Run("WithAllIncludingBadStore", func(t *testing.T) {
|
||||
db.store["yeeterson"] = Store{}
|
||||
err := db.withAll(dclose)
|
||||
if err != nil {
|
||||
t.Logf(err.Error())
|
||||
}
|
||||
if err == nil {
|
||||
t.Errorf("[FAIL] got nil err, wanted any error")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func Test_WithOptions(t *testing.T) { //nolint:funlen,gocognit,cyclop
|
||||
|
@ -445,6 +462,13 @@ func Test_WithOptions(t *testing.T) { //nolint:funlen,gocognit,cyclop
|
|||
t.Errorf("[FAIL] expected 4 datafile, got %d", checkDir())
|
||||
}
|
||||
})
|
||||
t.Run("InitWithBogusOption", func(t *testing.T) {
|
||||
db := newTestDB(t)
|
||||
err := db.Init("bogus", "yeet")
|
||||
if err == nil {
|
||||
t.Errorf("[FAIL] Init should have failed with bogus option")
|
||||
}
|
||||
})
|
||||
}
|
||||
func Test_PhonyInit(t *testing.T) {
|
||||
newtmp := t.TempDir()
|
||||
|
|
Loading…
Reference in New Issue