Browse Source

db: some test cleanup

pull/1842/head
Ethan Buchman 7 years ago
parent
commit
c547caf04f
3 changed files with 21 additions and 6 deletions
  1. +9
    -5
      db/backend_test.go
  2. +11
    -0
      db/c_level_db_test.go
  3. +1
    -1
      db/db.go

+ 9
- 5
db/backend_test.go View File

@ -58,7 +58,6 @@ func TestBackendsNilKeys(t *testing.T) {
name := cmn.Fmt("test_%x", cmn.RandStr(12)) name := cmn.Fmt("test_%x", cmn.RandStr(12))
db, err := creator(name, "") db, err := creator(name, "")
assert.Nil(t, err) assert.Nil(t, err)
defer os.RemoveAll(name)
assertPanics(t, dbType, "get", func() { db.Get(nil) }) assertPanics(t, dbType, "get", func() { db.Get(nil) })
assertPanics(t, dbType, "has", func() { db.Has(nil) }) assertPanics(t, dbType, "has", func() { db.Has(nil) })
@ -68,13 +67,18 @@ func TestBackendsNilKeys(t *testing.T) {
assertPanics(t, dbType, "deletesync", func() { db.DeleteSync(nil) }) assertPanics(t, dbType, "deletesync", func() { db.DeleteSync(nil) })
db.Close() db.Close()
err = os.RemoveAll(name + ".db")
assert.Nil(t, err)
} }
} }
func TestLevelDBBackendStr(t *testing.T) {
func TestGoLevelDBBackendStr(t *testing.T) {
name := cmn.Fmt("test_%x", cmn.RandStr(12)) name := cmn.Fmt("test_%x", cmn.RandStr(12))
db := NewDB(name, LevelDBBackendStr, "") db := NewDB(name, LevelDBBackendStr, "")
defer os.RemoveAll(name)
_, ok := db.(*GoLevelDB)
assert.True(t, ok)
defer os.RemoveAll(name + ".db")
if _, ok := backends[CLevelDBBackendStr]; !ok {
_, ok := db.(*GoLevelDB)
assert.True(t, ok)
}
} }

+ 11
- 0
db/c_level_db_test.go View File

@ -5,8 +5,10 @@ package db
import ( import (
"bytes" "bytes"
"fmt" "fmt"
"os"
"testing" "testing"
"github.com/stretchr/testify/assert"
cmn "github.com/tendermint/tmlibs/common" cmn "github.com/tendermint/tmlibs/common"
) )
@ -84,3 +86,12 @@ func bytes2Int64(buf []byte) int64 {
return int64(binary.BigEndian.Uint64(buf)) return int64(binary.BigEndian.Uint64(buf))
} }
*/ */
func TestCLevelDBBackendStr(t *testing.T) {
name := cmn.Fmt("test_%x", cmn.RandStr(12))
db := NewDB(name, LevelDBBackendStr, "")
defer os.RemoveAll(name)
_, ok := db.(*CLevelDB)
assert.True(t, ok)
}

+ 1
- 1
db/db.go View File

@ -6,7 +6,7 @@ import "fmt"
// Main entry // Main entry
const ( const (
LevelDBBackendStr = "leveldb" // legacy, defaults to goleveldb.
LevelDBBackendStr = "leveldb" // legacy, defaults to goleveldb unless +gcc
CLevelDBBackendStr = "cleveldb" CLevelDBBackendStr = "cleveldb"
GoLevelDBBackendStr = "goleveldb" GoLevelDBBackendStr = "goleveldb"
MemDBBackendStr = "memdb" MemDBBackendStr = "memdb"


Loading…
Cancel
Save