d574a3af6d
This commit contains the entire btcdb repository along with several changes needed to move all of the files into the database directory in order to prepare it for merging. This does NOT update btcd or any of the other packages to use the new location as that will be done separately. - All import paths in the old btcdb test files have been changed to the new location - All references to btcdb as the package name have been chagned to database - The coveralls badge has been removed since it unfortunately doesn't support coverage of sub-packages This is ongoing work toward #214.
63 lines
1.4 KiB
Go
63 lines
1.4 KiB
Go
// Copyright (c) 2013-2014 Conformal Systems LLC.
|
|
// Use of this source code is governed by an ISC
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package ldb_test
|
|
|
|
import (
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/btcsuite/btcd/database"
|
|
"github.com/btcsuite/btcwire"
|
|
)
|
|
|
|
// we need to test for an empty database and make certain it returns the proper
|
|
// values
|
|
|
|
func TestEmptyDB(t *testing.T) {
|
|
|
|
dbname := "tstdbempty"
|
|
dbnamever := dbname + ".ver"
|
|
_ = os.RemoveAll(dbname)
|
|
_ = os.RemoveAll(dbnamever)
|
|
db, err := database.CreateDB("leveldb", dbname)
|
|
if err != nil {
|
|
t.Errorf("Failed to open test database %v", err)
|
|
return
|
|
}
|
|
defer os.RemoveAll(dbname)
|
|
defer os.RemoveAll(dbnamever)
|
|
|
|
sha, height, err := db.NewestSha()
|
|
if !sha.IsEqual(&btcwire.ShaHash{}) {
|
|
t.Errorf("sha not zero hash")
|
|
}
|
|
if height != -1 {
|
|
t.Errorf("height not -1 %v", height)
|
|
}
|
|
|
|
// This is a reopen test
|
|
if err := db.Close(); err != nil {
|
|
t.Errorf("Close: unexpected error: %v", err)
|
|
}
|
|
|
|
db, err = database.OpenDB("leveldb", dbname)
|
|
if err != nil {
|
|
t.Errorf("Failed to open test database %v", err)
|
|
return
|
|
}
|
|
defer func() {
|
|
if err := db.Close(); err != nil {
|
|
t.Errorf("Close: unexpected error: %v", err)
|
|
}
|
|
}()
|
|
|
|
sha, height, err = db.NewestSha()
|
|
if !sha.IsEqual(&btcwire.ShaHash{}) {
|
|
t.Errorf("sha not zero hash")
|
|
}
|
|
if height != -1 {
|
|
t.Errorf("height not -1 %v", height)
|
|
}
|
|
}
|