Add db type to test error outputs.

This commit is contained in:
Dave Collins 2013-10-13 22:11:12 -05:00
parent 6eebf02183
commit 06d6e5fce8

View file

@ -15,7 +15,7 @@ import (
func testInterface(t *testing.T, dbType string) { func testInterface(t *testing.T, dbType string) {
db, teardown, err := setupDB(dbType, "interface") db, teardown, err := setupDB(dbType, "interface")
if err != nil { if err != nil {
t.Errorf("Failed to create test database %v", err) t.Errorf("Failed to create test database (%s) %v", dbType, err)
return return
} }
defer teardown() defer teardown()
@ -36,13 +36,13 @@ func testInterface(t *testing.T, dbType string) {
// database. // database.
newHeight, err := db.InsertBlock(block) newHeight, err := db.InsertBlock(block)
if err != nil { if err != nil {
t.Errorf("InsertBlock: failed to insert block %v err %v", t.Errorf("InsertBlock (%s): failed to insert block %v "+
height, err) "err %v", dbType, height, err)
return return
} }
if newHeight != height { if newHeight != height {
t.Errorf("InsertBlock: height mismatch got: %v, want: %v", t.Errorf("InsertBlock (%s): height mismatch got: %v, "+
newHeight, height) "want: %v", dbType, newHeight, height)
return return
} }
@ -53,8 +53,8 @@ func testInterface(t *testing.T, dbType string) {
return return
} }
if exists := db.ExistsSha(expectedHash); !exists { if exists := db.ExistsSha(expectedHash); !exists {
t.Errorf("ExistsSha: block %v does not exist", t.Errorf("ExistsSha (%s): block %v does not exist",
expectedHash) dbType, expectedHash)
return return
} }
@ -62,11 +62,13 @@ func testInterface(t *testing.T, dbType string) {
// the same MsgBlock and raw bytes. // the same MsgBlock and raw bytes.
blockFromDb, err := db.FetchBlockBySha(expectedHash) blockFromDb, err := db.FetchBlockBySha(expectedHash)
if err != nil { if err != nil {
t.Errorf("FetchBlockBySha: %v", err) t.Errorf("FetchBlockBySha (%s): %v", dbType, err)
return
} }
if !reflect.DeepEqual(block.MsgBlock(), blockFromDb.MsgBlock()) { if !reflect.DeepEqual(block.MsgBlock(), blockFromDb.MsgBlock()) {
t.Errorf("FetchBlockBySha: block from database does "+ t.Errorf("FetchBlockBySha (%s): block from database "+
"not match stored block\ngot: %v\nwant: %v", "does not match stored block\ngot: %v\n"+
"want: %v", dbType,
spew.Sdump(blockFromDb.MsgBlock()), spew.Sdump(blockFromDb.MsgBlock()),
spew.Sdump(block.MsgBlock())) spew.Sdump(block.MsgBlock()))
return return
@ -82,9 +84,10 @@ func testInterface(t *testing.T, dbType string) {
return return
} }
if !reflect.DeepEqual(blockBytes, blockFromDbBytes) { if !reflect.DeepEqual(blockBytes, blockFromDbBytes) {
t.Errorf("FetchBlockBySha: block bytes from database "+ t.Errorf("FetchBlockBySha (%s): block bytes from "+
"do not match stored block bytes\ngot: %v\n"+ "database do not match stored block bytes\n"+
"want: %v", spew.Sdump(blockFromDbBytes), "got: %v\nwant: %v", dbType,
spew.Sdump(blockFromDbBytes),
spew.Sdump(blockBytes)) spew.Sdump(blockBytes))
return return
} }
@ -93,13 +96,13 @@ func testInterface(t *testing.T, dbType string) {
// expected value. // expected value.
hashFromDb, err := db.FetchBlockShaByHeight(height) hashFromDb, err := db.FetchBlockShaByHeight(height)
if err != nil { if err != nil {
t.Errorf("FetchBlockShaByHeight: %v", err) t.Errorf("FetchBlockShaByHeight (%s): %v", dbType, err)
return return
} }
if !hashFromDb.IsEqual(expectedHash) { if !hashFromDb.IsEqual(expectedHash) {
t.Errorf("FetchBlockShaByHeight: returned hash does "+ t.Errorf("FetchBlockShaByHeight (%s): returned hash "+
"not match expected value - got: %v, want: %v", "does not match expected value - got: %v, "+
hashFromDb, expectedHash) "want: %v", dbType, hashFromDb, expectedHash)
return return
} }
} }