From 2271944064e8cb9eee3fc862479e0975243149a6 Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Wed, 27 Oct 2021 13:56:30 +0300 Subject: [PATCH] [#945] metabase: Use cleanup instead of defer in tests Cleanup is more idiomatic way to clean test data Signed-off-by: Alex Vanin --- pkg/local_object_storage/metabase/containers_test.go | 5 +---- pkg/local_object_storage/metabase/control_test.go | 1 - pkg/local_object_storage/metabase/db_test.go | 10 +++++----- pkg/local_object_storage/metabase/delete_test.go | 3 --- pkg/local_object_storage/metabase/exists_test.go | 1 - pkg/local_object_storage/metabase/get_test.go | 1 - pkg/local_object_storage/metabase/graveyard_test.go | 1 - pkg/local_object_storage/metabase/inhume_test.go | 2 -- pkg/local_object_storage/metabase/iterators_test.go | 2 -- pkg/local_object_storage/metabase/movable_test.go | 1 - pkg/local_object_storage/metabase/put_test.go | 1 - pkg/local_object_storage/metabase/select_test.go | 8 -------- pkg/local_object_storage/metabase/small_test.go | 1 - 13 files changed, 6 insertions(+), 31 deletions(-) diff --git a/pkg/local_object_storage/metabase/containers_test.go b/pkg/local_object_storage/metabase/containers_test.go index d5d8e0915..1f3df3ab9 100644 --- a/pkg/local_object_storage/metabase/containers_test.go +++ b/pkg/local_object_storage/metabase/containers_test.go @@ -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 diff --git a/pkg/local_object_storage/metabase/control_test.go b/pkg/local_object_storage/metabase/control_test.go index f4590ebb3..a74ab7964 100644 --- a/pkg/local_object_storage/metabase/control_test.go +++ b/pkg/local_object_storage/metabase/control_test.go @@ -11,7 +11,6 @@ import ( func TestReset(t *testing.T) { db := newDB(t) - defer releaseDB(db) err := db.Reset() require.NoError(t, err) diff --git a/pkg/local_object_storage/metabase/db_test.go b/pkg/local_object_storage/metabase/db_test.go index bf30cbbe3..c4eb63d90 100644 --- a/pkg/local_object_storage/metabase/db_test.go +++ b/pkg/local_object_storage/metabase/db_test.go @@ -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 { diff --git a/pkg/local_object_storage/metabase/delete_test.go b/pkg/local_object_storage/metabase/delete_test.go index ef7923a0a..4593b9da6 100644 --- a/pkg/local_object_storage/metabase/delete_test.go +++ b/pkg/local_object_storage/metabase/delete_test.go @@ -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() diff --git a/pkg/local_object_storage/metabase/exists_test.go b/pkg/local_object_storage/metabase/exists_test.go index 851f34b3d..0b08ca83d 100644 --- a/pkg/local_object_storage/metabase/exists_test.go +++ b/pkg/local_object_storage/metabase/exists_test.go @@ -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) diff --git a/pkg/local_object_storage/metabase/get_test.go b/pkg/local_object_storage/metabase/get_test.go index 16929f53c..3155dc2ad 100644 --- a/pkg/local_object_storage/metabase/get_test.go +++ b/pkg/local_object_storage/metabase/get_test.go @@ -13,7 +13,6 @@ import ( func TestDB_Get(t *testing.T) { db := newDB(t) - defer releaseDB(db) raw := generateRawObject(t) diff --git a/pkg/local_object_storage/metabase/graveyard_test.go b/pkg/local_object_storage/metabase/graveyard_test.go index 154db6599..f854a0177 100644 --- a/pkg/local_object_storage/metabase/graveyard_test.go +++ b/pkg/local_object_storage/metabase/graveyard_test.go @@ -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) diff --git a/pkg/local_object_storage/metabase/inhume_test.go b/pkg/local_object_storage/metabase/inhume_test.go index 55cecfb67..737a40bf0 100644 --- a/pkg/local_object_storage/metabase/inhume_test.go +++ b/pkg/local_object_storage/metabase/inhume_test.go @@ -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 diff --git a/pkg/local_object_storage/metabase/iterators_test.go b/pkg/local_object_storage/metabase/iterators_test.go index f1abe01e8..696eafeaf 100644 --- a/pkg/local_object_storage/metabase/iterators_test.go +++ b/pkg/local_object_storage/metabase/iterators_test.go @@ -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() diff --git a/pkg/local_object_storage/metabase/movable_test.go b/pkg/local_object_storage/metabase/movable_test.go index 859f72187..3715d7d5c 100644 --- a/pkg/local_object_storage/metabase/movable_test.go +++ b/pkg/local_object_storage/metabase/movable_test.go @@ -9,7 +9,6 @@ import ( func TestDB_Movable(t *testing.T) { db := newDB(t) - defer releaseDB(db) raw1 := generateRawObject(t) raw2 := generateRawObject(t) diff --git a/pkg/local_object_storage/metabase/put_test.go b/pkg/local_object_storage/metabase/put_test.go index c5a90001d..f50ae1330 100644 --- a/pkg/local_object_storage/metabase/put_test.go +++ b/pkg/local_object_storage/metabase/put_test.go @@ -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} diff --git a/pkg/local_object_storage/metabase/select_test.go b/pkg/local_object_storage/metabase/select_test.go index e8511983a..7d5e8817f 100644 --- a/pkg/local_object_storage/metabase/select_test.go +++ b/pkg/local_object_storage/metabase/select_test.go @@ -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() diff --git a/pkg/local_object_storage/metabase/small_test.go b/pkg/local_object_storage/metabase/small_test.go index c119f0ca0..fefaa4ed3 100644 --- a/pkg/local_object_storage/metabase/small_test.go +++ b/pkg/local_object_storage/metabase/small_test.go @@ -10,7 +10,6 @@ import ( func TestDB_IsSmall(t *testing.T) { db := newDB(t) - defer releaseDB(db) raw1 := generateRawObject(t) raw2 := generateRawObject(t)