mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-23 17:51:39 +00:00
db: Simplify exists check, fix IsKeyInDomain signature, Iterator Close
+ *FSDB.HasKey now uses common.FileExists to test for file existence + IsKeyInDomain takes key as a []byte slice instead of as a string to avoid extraneous []byte<-->string conversions for start and end + Iterator.Close() instead of Iterator.Release() + withDB helper to encapsulate DB creation, deferred cleanups so that for loops can use opened DBs and discard them ASAP Addressing accepted changes from review with @jaekwon
This commit is contained in:
@ -45,33 +45,37 @@ func TestBackendsGetSetDelete(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func withDB(t *testing.T, creator dbCreator, fn func(DB)) {
|
||||
name := cmn.Fmt("test_%x", cmn.RandStr(12))
|
||||
db, err := creator(name, "")
|
||||
defer cleanupDBDir("", name)
|
||||
assert.Nil(t, err)
|
||||
fn(db)
|
||||
db.Close()
|
||||
}
|
||||
|
||||
func TestBackendsNilKeys(t *testing.T) {
|
||||
// test all backends
|
||||
for dbType, creator := range backends {
|
||||
name := cmn.Fmt("test_%x", cmn.RandStr(12))
|
||||
db, err := creator(name, "")
|
||||
defer cleanupDBDir("", name)
|
||||
assert.Nil(t, err)
|
||||
|
||||
panicMsg := "expecting %s.%s to panic"
|
||||
assert.Panics(t, func() { db.Get(nil) }, panicMsg, dbType, "get")
|
||||
assert.Panics(t, func() { db.Has(nil) }, panicMsg, dbType, "has")
|
||||
assert.Panics(t, func() { db.Set(nil, []byte("abc")) }, panicMsg, dbType, "set")
|
||||
assert.Panics(t, func() { db.SetSync(nil, []byte("abc")) }, panicMsg, dbType, "setsync")
|
||||
assert.Panics(t, func() { db.Delete(nil) }, panicMsg, dbType, "delete")
|
||||
assert.Panics(t, func() { db.DeleteSync(nil) }, panicMsg, dbType, "deletesync")
|
||||
|
||||
db.Close()
|
||||
withDB(t, creator, func(db DB) {
|
||||
panicMsg := "expecting %s.%s to panic"
|
||||
assert.Panics(t, func() { db.Get(nil) }, panicMsg, dbType, "get")
|
||||
assert.Panics(t, func() { db.Has(nil) }, panicMsg, dbType, "has")
|
||||
assert.Panics(t, func() { db.Set(nil, []byte("abc")) }, panicMsg, dbType, "set")
|
||||
assert.Panics(t, func() { db.SetSync(nil, []byte("abc")) }, panicMsg, dbType, "setsync")
|
||||
assert.Panics(t, func() { db.Delete(nil) }, panicMsg, dbType, "delete")
|
||||
assert.Panics(t, func() { db.DeleteSync(nil) }, panicMsg, dbType, "deletesync")
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestGoLevelDBBackendStr(t *testing.T) {
|
||||
name := cmn.Fmt("test_%x", cmn.RandStr(12))
|
||||
db := NewDB(name, LevelDBBackendStr, "")
|
||||
defer cleanupDBDir("", name)
|
||||
|
||||
if _, ok := backends[CLevelDBBackendStr]; !ok {
|
||||
_, ok := db.(*GoLevelDB)
|
||||
assert.True(t, ok)
|
||||
}
|
||||
name := cmn.Fmt("test_%x", cmn.RandStr(12))
|
||||
db := NewDB(name, LevelDBBackendStr, "")
|
||||
defer cleanupDBDir("", name)
|
||||
|
||||
if _, ok := backends[CLevelDBBackendStr]; !ok {
|
||||
_, ok := db.(*GoLevelDB)
|
||||
assert.True(t, ok)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user