From 85ae6e2578c4473f9cfde35bf04ecc045fb4e396 Mon Sep 17 00:00:00 2001 From: Andrey Petrov Date: Thu, 15 Aug 2019 12:56:27 -0400 Subject: [PATCH] ethdb: Move testsuite to dbtest, fix lints --- ethdb/{ => dbtest}/testsuite.go | 16 +++++++++------- ethdb/leveldb/leveldb_test.go | 3 ++- ethdb/memorydb/memorydb_test.go | 3 ++- 3 files changed, 13 insertions(+), 9 deletions(-) rename ethdb/{ => dbtest}/testsuite.go (96%) diff --git a/ethdb/testsuite.go b/ethdb/dbtest/testsuite.go similarity index 96% rename from ethdb/testsuite.go rename to ethdb/dbtest/testsuite.go index aafc646153..6bd5985bdb 100644 --- a/ethdb/testsuite.go +++ b/ethdb/dbtest/testsuite.go @@ -14,18 +14,20 @@ // You should have received a copy of the GNU Lesser General Public License // along with the go-ethereum library. If not, see . -package ethdb +package dbtest import ( "bytes" "reflect" "sort" "testing" + + "github.com/ethereum/go-ethereum/ethdb" ) // TestDatabaseSuite runs a suite of tests against a KeyValueStore database // implementation. -func TestDatabaseSuite(t *testing.T, New func() KeyValueStore) { +func TestDatabaseSuite(t *testing.T, New func() ethdb.KeyValueStore) { t.Run("Iterator", func(t *testing.T) { tests := []struct { content map[string]string @@ -166,7 +168,7 @@ func TestDatabaseSuite(t *testing.T, New func() KeyValueStore) { if got, err := db.Has(key); err != nil { t.Error(err) - } else if got != false { + } else if got { t.Errorf("wrong value: %t", got) } @@ -177,13 +179,13 @@ func TestDatabaseSuite(t *testing.T, New func() KeyValueStore) { if got, err := db.Has(key); err != nil { t.Error(err) - } else if got != true { + } else if !got { t.Errorf("wrong value: %t", got) } if got, err := db.Get(key); err != nil { t.Error(err) - } else if bytes.Compare(got, value) != 0 { + } else if !bytes.Equal(got, value) { t.Errorf("wrong value: %q", got) } @@ -193,7 +195,7 @@ func TestDatabaseSuite(t *testing.T, New func() KeyValueStore) { if got, err := db.Has(key); err != nil { t.Error(err) - } else if got != false { + } else if got { t.Errorf("wrong value: %t", got) } }) @@ -279,7 +281,7 @@ func TestDatabaseSuite(t *testing.T, New func() KeyValueStore) { } -func iterateKeys(it Iterator) []string { +func iterateKeys(it ethdb.Iterator) []string { keys := []string{} for it.Next() { keys = append(keys, string(it.Key())) diff --git a/ethdb/leveldb/leveldb_test.go b/ethdb/leveldb/leveldb_test.go index 3fa053ec22..421d9b4693 100644 --- a/ethdb/leveldb/leveldb_test.go +++ b/ethdb/leveldb/leveldb_test.go @@ -20,13 +20,14 @@ import ( "testing" "github.com/ethereum/go-ethereum/ethdb" + "github.com/ethereum/go-ethereum/ethdb/dbtest" "github.com/syndtr/goleveldb/leveldb" "github.com/syndtr/goleveldb/leveldb/storage" ) func TestLevelDB(t *testing.T) { t.Run("DatabaseSuite", func(t *testing.T) { - ethdb.TestDatabaseSuite(t, func() ethdb.KeyValueStore { + dbtest.TestDatabaseSuite(t, func() ethdb.KeyValueStore { db, err := leveldb.Open(storage.NewMemStorage(), nil) if err != nil { t.Fatal(err) diff --git a/ethdb/memorydb/memorydb_test.go b/ethdb/memorydb/memorydb_test.go index 8bfda46237..878de59137 100644 --- a/ethdb/memorydb/memorydb_test.go +++ b/ethdb/memorydb/memorydb_test.go @@ -20,11 +20,12 @@ import ( "testing" "github.com/ethereum/go-ethereum/ethdb" + "github.com/ethereum/go-ethereum/ethdb/dbtest" ) func TestMemoryDB(t *testing.T) { t.Run("DatabaseSuite", func(t *testing.T) { - ethdb.TestDatabaseSuite(t, func() ethdb.KeyValueStore { + dbtest.TestDatabaseSuite(t, func() ethdb.KeyValueStore { return New() }) })