ethdb_test: replace some "panic" instead of "t.Fatal" and "t.Fatalf"

In testcases "TestLDB_PutGet" and "TestMemoryDB_PutGet", when the expected
value does not match actual value, keyword "panic" is used in several places. It is
not so appropriate because panic would not only make the current testcase
fail, but also make all the remaining to-be-executed testcases can't be
executed.
Besides, the places where panic is used are not some vital preconditions
for the testcases, even if the current testcase fails, the remaining
to-be-executed testcases should also be executed so that we can get all
testcases' running result.
So, suggest that replace "panic" instead of "t.Fatal" and "t.Fatalf".
This commit is contained in:
Lin Corey 2018-09-30 16:53:25 +08:00
parent b69942befe
commit 976712afc0

View file

@ -18,7 +18,6 @@ package ethdb_test
import ( import (
"bytes" "bytes"
"fmt"
"io/ioutil" "io/ioutil"
"os" "os"
"strconv" "strconv"
@ -165,7 +164,7 @@ func testParallelPutGet(db ethdb.Database, t *testing.T) {
defer pending.Done() defer pending.Done()
err := db.Put([]byte(key), []byte("v"+key)) err := db.Put([]byte(key), []byte("v"+key))
if err != nil { if err != nil {
panic("put failed: " + err.Error()) t.Fatal("put failed:", err.Error())
} }
}(strconv.Itoa(i)) }(strconv.Itoa(i))
} }
@ -177,10 +176,10 @@ func testParallelPutGet(db ethdb.Database, t *testing.T) {
defer pending.Done() defer pending.Done()
data, err := db.Get([]byte(key)) data, err := db.Get([]byte(key))
if err != nil { if err != nil {
panic("get failed: " + err.Error()) t.Fatal("get failed:", err.Error())
} }
if !bytes.Equal(data, []byte("v"+key)) { if !bytes.Equal(data, []byte("v"+key)) {
panic(fmt.Sprintf("get failed, got %q expected %q", []byte(data), []byte("v"+key))) t.Fatalf("get failed, got %q expected %q", []byte(data), []byte("v"+key))
} }
}(strconv.Itoa(i)) }(strconv.Itoa(i))
} }
@ -192,7 +191,7 @@ func testParallelPutGet(db ethdb.Database, t *testing.T) {
defer pending.Done() defer pending.Done()
err := db.Delete([]byte(key)) err := db.Delete([]byte(key))
if err != nil { if err != nil {
panic("delete failed: " + err.Error()) t.Fatal("delete failed:", err.Error())
} }
}(strconv.Itoa(i)) }(strconv.Itoa(i))
} }
@ -204,7 +203,7 @@ func testParallelPutGet(db ethdb.Database, t *testing.T) {
defer pending.Done() defer pending.Done()
_, err := db.Get([]byte(key)) _, err := db.Get([]byte(key))
if err == nil { if err == nil {
panic("get succeeded") t.Fatal("get succeeded")
} }
}(strconv.Itoa(i)) }(strconv.Itoa(i))
} }