storage: deduplicate storage closing in tests

This commit is contained in:
Roman Khimov 2022-02-14 15:42:57 +03:00
parent 261552516b
commit c4b49a2d52

View file

@ -19,10 +19,6 @@ type dbSetup struct {
type dbTestFunction func(*testing.T, Store) type dbTestFunction func(*testing.T, Store)
func testStoreClose(t *testing.T, s Store) {
require.NoError(t, s.Close())
}
func testStorePutAndGet(t *testing.T, s Store) { func testStorePutAndGet(t *testing.T, s Store) {
key := []byte("foo") key := []byte("foo")
value := []byte("bar") value := []byte("bar")
@ -32,8 +28,6 @@ func testStorePutAndGet(t *testing.T, s Store) {
result, err := s.Get(key) result, err := s.Get(key)
assert.Nil(t, err) assert.Nil(t, err)
require.Equal(t, value, result) require.Equal(t, value, result)
require.NoError(t, s.Close())
} }
func testStoreGetNonExistent(t *testing.T, s Store) { func testStoreGetNonExistent(t *testing.T, s Store) {
@ -41,7 +35,6 @@ func testStoreGetNonExistent(t *testing.T, s Store) {
_, err := s.Get(key) _, err := s.Get(key)
assert.Equal(t, err, ErrKeyNotFound) assert.Equal(t, err, ErrKeyNotFound)
require.NoError(t, s.Close())
} }
func testStorePutBatch(t *testing.T, s Store) { func testStorePutBatch(t *testing.T, s Store) {
@ -63,7 +56,6 @@ func testStorePutBatch(t *testing.T, s Store) {
assert.Nil(t, err) assert.Nil(t, err)
require.Equal(t, value, newVal) require.Equal(t, value, newVal)
assert.Equal(t, value, newVal) assert.Equal(t, value, newVal)
require.NoError(t, s.Close())
} }
func testStoreSeek(t *testing.T, s Store) { func testStoreSeek(t *testing.T, s Store) {
@ -338,15 +330,12 @@ func testStoreSeek(t *testing.T, s Store) {
}) })
}) })
}) })
require.NoError(t, s.Close())
} }
func testStoreDeleteNonExistent(t *testing.T, s Store) { func testStoreDeleteNonExistent(t *testing.T, s Store) {
key := []byte("sparse") key := []byte("sparse")
assert.NoError(t, s.Delete(key)) assert.NoError(t, s.Delete(key))
require.NoError(t, s.Close())
} }
func testStorePutAndDelete(t *testing.T, s Store) { func testStorePutAndDelete(t *testing.T, s Store) {
@ -365,8 +354,6 @@ func testStorePutAndDelete(t *testing.T, s Store) {
// Double delete. // Double delete.
err = s.Delete(key) err = s.Delete(key)
assert.Nil(t, err) assert.Nil(t, err)
require.NoError(t, s.Close())
} }
func testStorePutBatchWithDelete(t *testing.T, s Store) { func testStorePutBatchWithDelete(t *testing.T, s Store) {
@ -435,7 +422,6 @@ func testStorePutBatchWithDelete(t *testing.T, s Store) {
assert.Equal(t, ErrKeyNotFound, err, "%s:%s", k, v) assert.Equal(t, ErrKeyNotFound, err, "%s:%s", k, v)
} }
} }
require.NoError(t, s.Close())
} }
func testStoreSeekGC(t *testing.T, s Store) { func testStoreSeekGC(t *testing.T, s Store) {
@ -480,7 +466,7 @@ func TestAllDBs(t *testing.T) {
{"MemCached", newMemCachedStoreForTesting}, {"MemCached", newMemCachedStoreForTesting},
{"Memory", newMemoryStoreForTesting}, {"Memory", newMemoryStoreForTesting},
} }
var tests = []dbTestFunction{testStoreClose, testStorePutAndGet, var tests = []dbTestFunction{testStorePutAndGet,
testStoreGetNonExistent, testStorePutBatch, testStoreSeek, testStoreGetNonExistent, testStorePutBatch, testStoreSeek,
testStoreDeleteNonExistent, testStorePutAndDelete, testStoreDeleteNonExistent, testStorePutAndDelete,
testStorePutBatchWithDelete, testStoreSeekGC} testStorePutBatchWithDelete, testStoreSeekGC}
@ -492,6 +478,7 @@ func TestAllDBs(t *testing.T) {
} }
fname := runtime.FuncForPC(reflect.ValueOf(test).Pointer()).Name() fname := runtime.FuncForPC(reflect.ValueOf(test).Pointer()).Name()
t.Run(db.name+"/"+fname, twrapper) t.Run(db.name+"/"+fname, twrapper)
require.NoError(t, s.Close())
} }
} }
} }