[#945] metabase: Use cleanup instead of defer in tests

Cleanup is more idiomatic way to clean test data

Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
Alex Vanin 2021-10-27 13:56:30 +03:00 committed by Alex Vanin
parent e41aba610d
commit 2271944064
13 changed files with 6 additions and 31 deletions

View file

@ -15,7 +15,6 @@ import (
func TestDB_Containers(t *testing.T) {
db := newDB(t)
defer releaseDB(db)
const N = 10
@ -76,7 +75,6 @@ func TestDB_Containers(t *testing.T) {
func TestDB_ContainersCount(t *testing.T) {
db := newDB(t)
t.Cleanup(func() { releaseDB(db) })
const R, T, SG = 10, 11, 12 // amount of object per type
@ -86,7 +84,7 @@ func TestDB_ContainersCount(t *testing.T) {
}{
{R, objectSDK.TypeRegular},
{T, objectSDK.TypeTombstone},
{SG, objectSDK.TypeTombstone},
{SG, objectSDK.TypeStorageGroup},
}
expected := make([]*cid.ID, 0, R+T+SG)
@ -119,7 +117,6 @@ func TestDB_ContainersCount(t *testing.T) {
func TestDB_ContainerSize(t *testing.T) {
db := newDB(t)
defer releaseDB(db)
const (
C = 3

View file

@ -11,7 +11,6 @@ import (
func TestReset(t *testing.T) {
db := newDB(t)
defer releaseDB(db)
err := db.Reset()
require.NoError(t, err)

View file

@ -51,12 +51,12 @@ func newDB(t testing.TB) *meta.DB {
require.NoError(t, bdb.Open())
return bdb
}
t.Cleanup(func() {
bdb.Close()
os.Remove(bdb.DumpInfo().Path)
})
func releaseDB(db *meta.DB) {
db.Close()
os.Remove(db.DumpInfo().Path)
return bdb
}
func generateRawObject(t *testing.T) *object.RawObject {

View file

@ -12,7 +12,6 @@ import (
func TestDB_Delete(t *testing.T) {
db := newDB(t)
defer releaseDB(db)
cid := cidtest.Generate()
parent := generateRawObjectWithCID(t, cid)
@ -69,7 +68,6 @@ func TestDB_Delete(t *testing.T) {
func TestDeleteAllChildren(t *testing.T) {
db := newDB(t)
defer releaseDB(db)
cid := cidtest.Generate()
@ -106,7 +104,6 @@ func TestDeleteAllChildren(t *testing.T) {
func TestGraveOnlyDelete(t *testing.T) {
db := newDB(t)
defer releaseDB(db)
addr := generateAddress()

View file

@ -12,7 +12,6 @@ import (
func TestDB_Exists(t *testing.T) {
db := newDB(t)
defer releaseDB(db)
t.Run("no object", func(t *testing.T) {
nonExist := generateRawObject(t)

View file

@ -13,7 +13,6 @@ import (
func TestDB_Get(t *testing.T) {
db := newDB(t)
defer releaseDB(db)
raw := generateRawObject(t)

View file

@ -10,7 +10,6 @@ import (
func TestDB_IterateOverGraveyard(t *testing.T) {
db := newDB(t)
defer releaseDB(db)
// generate and put 2 objects
obj1 := generateRawObject(t)

View file

@ -11,7 +11,6 @@ import (
func TestDB_Inhume(t *testing.T) {
db := newDB(t)
defer releaseDB(db)
raw := generateRawObject(t)
addAttribute(raw, "foo", "bar")
@ -33,7 +32,6 @@ func TestDB_Inhume(t *testing.T) {
func TestInhumeTombOnTomb(t *testing.T) {
db := newDB(t)
defer releaseDB(db)
var (
err error

View file

@ -12,7 +12,6 @@ import (
func TestDB_IterateExpired(t *testing.T) {
db := newDB(t)
defer releaseDB(db)
const epoch = 13
@ -59,7 +58,6 @@ func putWithExpiration(t *testing.T, db *meta.DB, typ object.Type, expiresAt uin
func TestDB_IterateCoveredByTombstones(t *testing.T) {
db := newDB(t)
defer releaseDB(db)
ts := generateAddress()
protected1 := generateAddress()

View file

@ -9,7 +9,6 @@ import (
func TestDB_Movable(t *testing.T) {
db := newDB(t)
defer releaseDB(db)
raw1 := generateRawObject(t)
raw2 := generateRawObject(t)

View file

@ -10,7 +10,6 @@ import (
func TestDB_PutBlobovnicaUpdate(t *testing.T) {
db := newDB(t)
defer releaseDB(db)
raw1 := generateRawObject(t)
blobovniczaID := blobovnicza.ID{1, 2, 3, 4}

View file

@ -14,7 +14,6 @@ import (
func TestDB_SelectUserAttributes(t *testing.T) {
db := newDB(t)
defer releaseDB(db)
cid := cidtest.Generate()
@ -137,7 +136,6 @@ func TestDB_SelectUserAttributes(t *testing.T) {
func TestDB_SelectRootPhyParent(t *testing.T) {
db := newDB(t)
defer releaseDB(db)
cid := cidtest.Generate()
@ -305,7 +303,6 @@ func TestDB_SelectRootPhyParent(t *testing.T) {
func TestDB_SelectInhume(t *testing.T) {
db := newDB(t)
defer releaseDB(db)
cid := cidtest.Generate()
@ -338,7 +335,6 @@ func TestDB_SelectInhume(t *testing.T) {
func TestDB_SelectPayloadHash(t *testing.T) {
db := newDB(t)
defer releaseDB(db)
cid := cidtest.Generate()
@ -374,7 +370,6 @@ func TestDB_SelectPayloadHash(t *testing.T) {
func TestDB_SelectWithSlowFilters(t *testing.T) {
db := newDB(t)
defer releaseDB(db)
cid := cidtest.Generate()
@ -473,7 +468,6 @@ func TestDB_SelectWithSlowFilters(t *testing.T) {
func TestDB_SelectObjectID(t *testing.T) {
db := newDB(t)
defer releaseDB(db)
cid := cidtest.Generate()
@ -582,7 +576,6 @@ func TestDB_SelectObjectID(t *testing.T) {
func TestDB_SelectSplitID(t *testing.T) {
db := newDB(t)
defer releaseDB(db)
cid := cidtest.Generate()
@ -637,7 +630,6 @@ func TestDB_SelectSplitID(t *testing.T) {
func TestDB_SelectContainerID(t *testing.T) {
db := newDB(t)
defer releaseDB(db)
cid := cidtest.Generate()

View file

@ -10,7 +10,6 @@ import (
func TestDB_IsSmall(t *testing.T) {
db := newDB(t)
defer releaseDB(db)
raw1 := generateRawObject(t)
raw2 := generateRawObject(t)