diff --git a/database/corruptabledb/db_test.go b/database/corruptabledb/db_test.go index 566a6b084e19..5c7a48a64c4d 100644 --- a/database/corruptabledb/db_test.go +++ b/database/corruptabledb/db_test.go @@ -18,19 +18,19 @@ import ( var errTest = errors.New("non-nil error") -func TestInterface(t *testing.T) { - for _, test := range database.Tests { - baseDB := memdb.New() - db := New(baseDB) - test(t, db) - } -} - func newDB() *Database { baseDB := memdb.New() return New(baseDB) } +func TestInterface(t *testing.T) { + for name, test := range database.Tests { + t.Run(name, func(t *testing.T) { + test(t, newDB()) + }) + } +} + func FuzzKeyValue(f *testing.F) { database.FuzzKeyValue(f, newDB()) } diff --git a/database/encdb/db_test.go b/database/encdb/db_test.go index d659bd3ba455..b3dfdfed68e7 100644 --- a/database/encdb/db_test.go +++ b/database/encdb/db_test.go @@ -16,12 +16,14 @@ import ( const testPassword = "lol totally a secure password" //nolint:gosec func TestInterface(t *testing.T) { - for _, test := range database.Tests { - unencryptedDB := memdb.New() - db, err := New([]byte(testPassword), unencryptedDB) - require.NoError(t, err) - - test(t, db) + for name, test := range database.Tests { + t.Run(name, func(t *testing.T) { + unencryptedDB := memdb.New() + db, err := New([]byte(testPassword), unencryptedDB) + require.NoError(t, err) + + test(t, db) + }) } } diff --git a/database/leveldb/db_test.go b/database/leveldb/db_test.go index 748958086d7c..ad8d60cbbc4f 100644 --- a/database/leveldb/db_test.go +++ b/database/leveldb/db_test.go @@ -16,14 +16,16 @@ import ( ) func TestInterface(t *testing.T) { - for _, test := range database.Tests { - folder := t.TempDir() - db, err := New(folder, nil, logging.NoLog{}, "", prometheus.NewRegistry()) - require.NoError(t, err) + for name, test := range database.Tests { + t.Run(name, func(t *testing.T) { + folder := t.TempDir() + db, err := New(folder, nil, logging.NoLog{}, "", prometheus.NewRegistry()) + require.NoError(t, err) - test(t, db) + test(t, db) - _ = db.Close() + _ = db.Close() + }) } } diff --git a/database/memdb/db_test.go b/database/memdb/db_test.go index 7408409f13fd..90dc459f3602 100644 --- a/database/memdb/db_test.go +++ b/database/memdb/db_test.go @@ -11,8 +11,10 @@ import ( ) func TestInterface(t *testing.T) { - for _, test := range database.Tests { - test(t, New()) + for name, test := range database.Tests { + t.Run(name, func(t *testing.T) { + test(t, New()) + }) } } diff --git a/database/meterdb/db_test.go b/database/meterdb/db_test.go index f11944b39df5..eee3f1c23c01 100644 --- a/database/meterdb/db_test.go +++ b/database/meterdb/db_test.go @@ -16,12 +16,14 @@ import ( ) func TestInterface(t *testing.T) { - for _, test := range database.Tests { - baseDB := memdb.New() - db, err := New("", prometheus.NewRegistry(), baseDB) - require.NoError(t, err) - - test(t, db) + for name, test := range database.Tests { + t.Run(name, func(t *testing.T) { + baseDB := memdb.New() + db, err := New("", prometheus.NewRegistry(), baseDB) + require.NoError(t, err) + + test(t, db) + }) } } diff --git a/database/pebble/db_test.go b/database/pebble/db_test.go index 357f5db58119..5c8650dbf183 100644 --- a/database/pebble/db_test.go +++ b/database/pebble/db_test.go @@ -23,10 +23,12 @@ func newDB(t testing.TB) *Database { } func TestInterface(t *testing.T) { - for _, test := range database.Tests { - db := newDB(t) - test(t, db) - _ = db.Close() + for name, test := range database.Tests { + t.Run(name, func(t *testing.T) { + db := newDB(t) + test(t, db) + _ = db.Close() + }) } } diff --git a/database/prefixdb/db_test.go b/database/prefixdb/db_test.go index 7cc1ee25b878..f928d2f635a4 100644 --- a/database/prefixdb/db_test.go +++ b/database/prefixdb/db_test.go @@ -12,14 +12,16 @@ import ( ) func TestInterface(t *testing.T) { - for _, test := range database.Tests { - db := memdb.New() - test(t, New([]byte("hello"), db)) - test(t, New([]byte("world"), db)) - test(t, New([]byte("wor"), New([]byte("ld"), db))) - test(t, New([]byte("ld"), New([]byte("wor"), db))) - test(t, NewNested([]byte("wor"), New([]byte("ld"), db))) - test(t, NewNested([]byte("ld"), New([]byte("wor"), db))) + for name, test := range database.Tests { + t.Run(name, func(t *testing.T) { + db := memdb.New() + test(t, New([]byte("hello"), db)) + test(t, New([]byte("world"), db)) + test(t, New([]byte("wor"), New([]byte("ld"), db))) + test(t, New([]byte("ld"), New([]byte("wor"), db))) + test(t, NewNested([]byte("wor"), New([]byte("ld"), db))) + test(t, NewNested([]byte("ld"), New([]byte("wor"), db))) + }) } } diff --git a/database/rpcdb/db_test.go b/database/rpcdb/db_test.go index 6fe2ea02125c..a309ea01298b 100644 --- a/database/rpcdb/db_test.go +++ b/database/rpcdb/db_test.go @@ -54,11 +54,13 @@ func setupDB(t testing.TB) *testDatabase { } func TestInterface(t *testing.T) { - for _, test := range database.Tests { - db := setupDB(t) - test(t, db.client) + for name, test := range database.Tests { + t.Run(name, func(t *testing.T) { + db := setupDB(t) + test(t, db.client) - db.closeFn() + db.closeFn() + }) } } diff --git a/database/test_database.go b/database/test_database.go index 1ce32bb54257..792b038012cb 100644 --- a/database/test_database.go +++ b/database/test_database.go @@ -24,44 +24,44 @@ import ( ) // Tests is a list of all database tests -var Tests = []func(t *testing.T, db Database){ - TestSimpleKeyValue, - TestOverwriteKeyValue, - TestEmptyKey, - TestKeyEmptyValue, - TestSimpleKeyValueClosed, - TestNewBatchClosed, - TestBatchPut, - TestBatchDelete, - TestBatchReset, - TestBatchReuse, - TestBatchRewrite, - TestBatchReplay, - TestBatchReplayPropagateError, - TestBatchInner, - TestBatchLargeSize, - TestIteratorSnapshot, - TestIterator, - TestIteratorStart, - TestIteratorPrefix, - TestIteratorStartPrefix, - TestIteratorMemorySafety, - TestIteratorClosed, - TestIteratorError, - TestIteratorErrorAfterRelease, - TestCompactNoPanic, - TestMemorySafetyDatabase, - TestMemorySafetyBatch, - TestAtomicClear, - TestClear, - TestAtomicClearPrefix, - TestClearPrefix, - TestModifyValueAfterPut, - TestModifyValueAfterBatchPut, - TestModifyValueAfterBatchPutReplay, - TestConcurrentBatches, - TestManySmallConcurrentKVPairBatches, - TestPutGetEmpty, +var Tests = map[string]func(t *testing.T, db Database){ + "SimpleKeyValue": TestSimpleKeyValue, + "OverwriteKeyValue": TestOverwriteKeyValue, + "EmptyKey": TestEmptyKey, + "KeyEmptyValue": TestKeyEmptyValue, + "SimpleKeyValueClosed": TestSimpleKeyValueClosed, + "NewBatchClosed": TestNewBatchClosed, + "BatchPut": TestBatchPut, + "BatchDelete": TestBatchDelete, + "BatchReset": TestBatchReset, + "BatchReuse": TestBatchReuse, + "BatchRewrite": TestBatchRewrite, + "BatchReplay": TestBatchReplay, + "BatchReplayPropagateError": TestBatchReplayPropagateError, + "BatchInner": TestBatchInner, + "BatchLargeSize": TestBatchLargeSize, + "IteratorSnapshot": TestIteratorSnapshot, + "Iterator": TestIterator, + "IteratorStart": TestIteratorStart, + "IteratorPrefix": TestIteratorPrefix, + "IteratorStartPrefix": TestIteratorStartPrefix, + "IteratorMemorySafety": TestIteratorMemorySafety, + "IteratorClosed": TestIteratorClosed, + "IteratorError": TestIteratorError, + "IteratorErrorAfterRelease": TestIteratorErrorAfterRelease, + "CompactNoPanic": TestCompactNoPanic, + "MemorySafetyDatabase": TestMemorySafetyDatabase, + "MemorySafetyBatch": TestMemorySafetyBatch, + "AtomicClear": TestAtomicClear, + "Clear": TestClear, + "AtomicClearPrefix": TestAtomicClearPrefix, + "ClearPrefix": TestClearPrefix, + "ModifyValueAfterPut": TestModifyValueAfterPut, + "ModifyValueAfterBatchPut": TestModifyValueAfterBatchPut, + "ModifyValueAfterBatchPutReplay": TestModifyValueAfterBatchPutReplay, + "ConcurrentBatches": TestConcurrentBatches, + "ManySmallConcurrentKVPairBatches": TestManySmallConcurrentKVPairBatches, + "PutGetEmpty": TestPutGetEmpty, } // TestSimpleKeyValue tests to make sure that simple Put + Get + Delete + Has diff --git a/database/versiondb/db_test.go b/database/versiondb/db_test.go index fb94eae01fd6..0ff801dfe0dd 100644 --- a/database/versiondb/db_test.go +++ b/database/versiondb/db_test.go @@ -14,9 +14,11 @@ import ( ) func TestInterface(t *testing.T) { - for _, test := range database.Tests { - baseDB := memdb.New() - test(t, New(baseDB)) + for name, test := range database.Tests { + t.Run(name, func(t *testing.T) { + baseDB := memdb.New() + test(t, New(baseDB)) + }) } } diff --git a/x/merkledb/db_test.go b/x/merkledb/db_test.go index 6329f0e4be97..48703556b72a 100644 --- a/x/merkledb/db_test.go +++ b/x/merkledb/db_test.go @@ -99,10 +99,12 @@ func Test_MerkleDB_GetValues_Safety(t *testing.T) { func Test_MerkleDB_DB_Interface(t *testing.T) { for _, bf := range validBranchFactors { - for _, test := range database.Tests { - db, err := getBasicDBWithBranchFactor(bf) - require.NoError(t, err) - test(t, db) + for name, test := range database.Tests { + t.Run(fmt.Sprintf("%s_%d", name, bf), func(t *testing.T) { + db, err := getBasicDBWithBranchFactor(bf) + require.NoError(t, err) + test(t, db) + }) } } }