forked from TrueCloudLab/frostfs-node
[#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:
parent
e41aba610d
commit
2271944064
13 changed files with 6 additions and 31 deletions
|
@ -15,7 +15,6 @@ import (
|
||||||
|
|
||||||
func TestDB_Containers(t *testing.T) {
|
func TestDB_Containers(t *testing.T) {
|
||||||
db := newDB(t)
|
db := newDB(t)
|
||||||
defer releaseDB(db)
|
|
||||||
|
|
||||||
const N = 10
|
const N = 10
|
||||||
|
|
||||||
|
@ -76,7 +75,6 @@ func TestDB_Containers(t *testing.T) {
|
||||||
|
|
||||||
func TestDB_ContainersCount(t *testing.T) {
|
func TestDB_ContainersCount(t *testing.T) {
|
||||||
db := newDB(t)
|
db := newDB(t)
|
||||||
t.Cleanup(func() { releaseDB(db) })
|
|
||||||
|
|
||||||
const R, T, SG = 10, 11, 12 // amount of object per type
|
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},
|
{R, objectSDK.TypeRegular},
|
||||||
{T, objectSDK.TypeTombstone},
|
{T, objectSDK.TypeTombstone},
|
||||||
{SG, objectSDK.TypeTombstone},
|
{SG, objectSDK.TypeStorageGroup},
|
||||||
}
|
}
|
||||||
|
|
||||||
expected := make([]*cid.ID, 0, R+T+SG)
|
expected := make([]*cid.ID, 0, R+T+SG)
|
||||||
|
@ -119,7 +117,6 @@ func TestDB_ContainersCount(t *testing.T) {
|
||||||
|
|
||||||
func TestDB_ContainerSize(t *testing.T) {
|
func TestDB_ContainerSize(t *testing.T) {
|
||||||
db := newDB(t)
|
db := newDB(t)
|
||||||
defer releaseDB(db)
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
C = 3
|
C = 3
|
||||||
|
|
|
@ -11,7 +11,6 @@ import (
|
||||||
|
|
||||||
func TestReset(t *testing.T) {
|
func TestReset(t *testing.T) {
|
||||||
db := newDB(t)
|
db := newDB(t)
|
||||||
defer releaseDB(db)
|
|
||||||
|
|
||||||
err := db.Reset()
|
err := db.Reset()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
|
@ -51,12 +51,12 @@ func newDB(t testing.TB) *meta.DB {
|
||||||
|
|
||||||
require.NoError(t, bdb.Open())
|
require.NoError(t, bdb.Open())
|
||||||
|
|
||||||
return bdb
|
t.Cleanup(func() {
|
||||||
}
|
bdb.Close()
|
||||||
|
os.Remove(bdb.DumpInfo().Path)
|
||||||
|
})
|
||||||
|
|
||||||
func releaseDB(db *meta.DB) {
|
return bdb
|
||||||
db.Close()
|
|
||||||
os.Remove(db.DumpInfo().Path)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func generateRawObject(t *testing.T) *object.RawObject {
|
func generateRawObject(t *testing.T) *object.RawObject {
|
||||||
|
|
|
@ -12,7 +12,6 @@ import (
|
||||||
|
|
||||||
func TestDB_Delete(t *testing.T) {
|
func TestDB_Delete(t *testing.T) {
|
||||||
db := newDB(t)
|
db := newDB(t)
|
||||||
defer releaseDB(db)
|
|
||||||
|
|
||||||
cid := cidtest.Generate()
|
cid := cidtest.Generate()
|
||||||
parent := generateRawObjectWithCID(t, cid)
|
parent := generateRawObjectWithCID(t, cid)
|
||||||
|
@ -69,7 +68,6 @@ func TestDB_Delete(t *testing.T) {
|
||||||
|
|
||||||
func TestDeleteAllChildren(t *testing.T) {
|
func TestDeleteAllChildren(t *testing.T) {
|
||||||
db := newDB(t)
|
db := newDB(t)
|
||||||
defer releaseDB(db)
|
|
||||||
|
|
||||||
cid := cidtest.Generate()
|
cid := cidtest.Generate()
|
||||||
|
|
||||||
|
@ -106,7 +104,6 @@ func TestDeleteAllChildren(t *testing.T) {
|
||||||
|
|
||||||
func TestGraveOnlyDelete(t *testing.T) {
|
func TestGraveOnlyDelete(t *testing.T) {
|
||||||
db := newDB(t)
|
db := newDB(t)
|
||||||
defer releaseDB(db)
|
|
||||||
|
|
||||||
addr := generateAddress()
|
addr := generateAddress()
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,6 @@ import (
|
||||||
|
|
||||||
func TestDB_Exists(t *testing.T) {
|
func TestDB_Exists(t *testing.T) {
|
||||||
db := newDB(t)
|
db := newDB(t)
|
||||||
defer releaseDB(db)
|
|
||||||
|
|
||||||
t.Run("no object", func(t *testing.T) {
|
t.Run("no object", func(t *testing.T) {
|
||||||
nonExist := generateRawObject(t)
|
nonExist := generateRawObject(t)
|
||||||
|
|
|
@ -13,7 +13,6 @@ import (
|
||||||
|
|
||||||
func TestDB_Get(t *testing.T) {
|
func TestDB_Get(t *testing.T) {
|
||||||
db := newDB(t)
|
db := newDB(t)
|
||||||
defer releaseDB(db)
|
|
||||||
|
|
||||||
raw := generateRawObject(t)
|
raw := generateRawObject(t)
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,6 @@ import (
|
||||||
|
|
||||||
func TestDB_IterateOverGraveyard(t *testing.T) {
|
func TestDB_IterateOverGraveyard(t *testing.T) {
|
||||||
db := newDB(t)
|
db := newDB(t)
|
||||||
defer releaseDB(db)
|
|
||||||
|
|
||||||
// generate and put 2 objects
|
// generate and put 2 objects
|
||||||
obj1 := generateRawObject(t)
|
obj1 := generateRawObject(t)
|
||||||
|
|
|
@ -11,7 +11,6 @@ import (
|
||||||
|
|
||||||
func TestDB_Inhume(t *testing.T) {
|
func TestDB_Inhume(t *testing.T) {
|
||||||
db := newDB(t)
|
db := newDB(t)
|
||||||
defer releaseDB(db)
|
|
||||||
|
|
||||||
raw := generateRawObject(t)
|
raw := generateRawObject(t)
|
||||||
addAttribute(raw, "foo", "bar")
|
addAttribute(raw, "foo", "bar")
|
||||||
|
@ -33,7 +32,6 @@ func TestDB_Inhume(t *testing.T) {
|
||||||
|
|
||||||
func TestInhumeTombOnTomb(t *testing.T) {
|
func TestInhumeTombOnTomb(t *testing.T) {
|
||||||
db := newDB(t)
|
db := newDB(t)
|
||||||
defer releaseDB(db)
|
|
||||||
|
|
||||||
var (
|
var (
|
||||||
err error
|
err error
|
||||||
|
|
|
@ -12,7 +12,6 @@ import (
|
||||||
|
|
||||||
func TestDB_IterateExpired(t *testing.T) {
|
func TestDB_IterateExpired(t *testing.T) {
|
||||||
db := newDB(t)
|
db := newDB(t)
|
||||||
defer releaseDB(db)
|
|
||||||
|
|
||||||
const epoch = 13
|
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) {
|
func TestDB_IterateCoveredByTombstones(t *testing.T) {
|
||||||
db := newDB(t)
|
db := newDB(t)
|
||||||
defer releaseDB(db)
|
|
||||||
|
|
||||||
ts := generateAddress()
|
ts := generateAddress()
|
||||||
protected1 := generateAddress()
|
protected1 := generateAddress()
|
||||||
|
|
|
@ -9,7 +9,6 @@ import (
|
||||||
|
|
||||||
func TestDB_Movable(t *testing.T) {
|
func TestDB_Movable(t *testing.T) {
|
||||||
db := newDB(t)
|
db := newDB(t)
|
||||||
defer releaseDB(db)
|
|
||||||
|
|
||||||
raw1 := generateRawObject(t)
|
raw1 := generateRawObject(t)
|
||||||
raw2 := generateRawObject(t)
|
raw2 := generateRawObject(t)
|
||||||
|
|
|
@ -10,7 +10,6 @@ import (
|
||||||
|
|
||||||
func TestDB_PutBlobovnicaUpdate(t *testing.T) {
|
func TestDB_PutBlobovnicaUpdate(t *testing.T) {
|
||||||
db := newDB(t)
|
db := newDB(t)
|
||||||
defer releaseDB(db)
|
|
||||||
|
|
||||||
raw1 := generateRawObject(t)
|
raw1 := generateRawObject(t)
|
||||||
blobovniczaID := blobovnicza.ID{1, 2, 3, 4}
|
blobovniczaID := blobovnicza.ID{1, 2, 3, 4}
|
||||||
|
|
|
@ -14,7 +14,6 @@ import (
|
||||||
|
|
||||||
func TestDB_SelectUserAttributes(t *testing.T) {
|
func TestDB_SelectUserAttributes(t *testing.T) {
|
||||||
db := newDB(t)
|
db := newDB(t)
|
||||||
defer releaseDB(db)
|
|
||||||
|
|
||||||
cid := cidtest.Generate()
|
cid := cidtest.Generate()
|
||||||
|
|
||||||
|
@ -137,7 +136,6 @@ func TestDB_SelectUserAttributes(t *testing.T) {
|
||||||
|
|
||||||
func TestDB_SelectRootPhyParent(t *testing.T) {
|
func TestDB_SelectRootPhyParent(t *testing.T) {
|
||||||
db := newDB(t)
|
db := newDB(t)
|
||||||
defer releaseDB(db)
|
|
||||||
|
|
||||||
cid := cidtest.Generate()
|
cid := cidtest.Generate()
|
||||||
|
|
||||||
|
@ -305,7 +303,6 @@ func TestDB_SelectRootPhyParent(t *testing.T) {
|
||||||
|
|
||||||
func TestDB_SelectInhume(t *testing.T) {
|
func TestDB_SelectInhume(t *testing.T) {
|
||||||
db := newDB(t)
|
db := newDB(t)
|
||||||
defer releaseDB(db)
|
|
||||||
|
|
||||||
cid := cidtest.Generate()
|
cid := cidtest.Generate()
|
||||||
|
|
||||||
|
@ -338,7 +335,6 @@ func TestDB_SelectInhume(t *testing.T) {
|
||||||
|
|
||||||
func TestDB_SelectPayloadHash(t *testing.T) {
|
func TestDB_SelectPayloadHash(t *testing.T) {
|
||||||
db := newDB(t)
|
db := newDB(t)
|
||||||
defer releaseDB(db)
|
|
||||||
|
|
||||||
cid := cidtest.Generate()
|
cid := cidtest.Generate()
|
||||||
|
|
||||||
|
@ -374,7 +370,6 @@ func TestDB_SelectPayloadHash(t *testing.T) {
|
||||||
|
|
||||||
func TestDB_SelectWithSlowFilters(t *testing.T) {
|
func TestDB_SelectWithSlowFilters(t *testing.T) {
|
||||||
db := newDB(t)
|
db := newDB(t)
|
||||||
defer releaseDB(db)
|
|
||||||
|
|
||||||
cid := cidtest.Generate()
|
cid := cidtest.Generate()
|
||||||
|
|
||||||
|
@ -473,7 +468,6 @@ func TestDB_SelectWithSlowFilters(t *testing.T) {
|
||||||
|
|
||||||
func TestDB_SelectObjectID(t *testing.T) {
|
func TestDB_SelectObjectID(t *testing.T) {
|
||||||
db := newDB(t)
|
db := newDB(t)
|
||||||
defer releaseDB(db)
|
|
||||||
|
|
||||||
cid := cidtest.Generate()
|
cid := cidtest.Generate()
|
||||||
|
|
||||||
|
@ -582,7 +576,6 @@ func TestDB_SelectObjectID(t *testing.T) {
|
||||||
|
|
||||||
func TestDB_SelectSplitID(t *testing.T) {
|
func TestDB_SelectSplitID(t *testing.T) {
|
||||||
db := newDB(t)
|
db := newDB(t)
|
||||||
defer releaseDB(db)
|
|
||||||
|
|
||||||
cid := cidtest.Generate()
|
cid := cidtest.Generate()
|
||||||
|
|
||||||
|
@ -637,7 +630,6 @@ func TestDB_SelectSplitID(t *testing.T) {
|
||||||
|
|
||||||
func TestDB_SelectContainerID(t *testing.T) {
|
func TestDB_SelectContainerID(t *testing.T) {
|
||||||
db := newDB(t)
|
db := newDB(t)
|
||||||
defer releaseDB(db)
|
|
||||||
|
|
||||||
cid := cidtest.Generate()
|
cid := cidtest.Generate()
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,6 @@ import (
|
||||||
|
|
||||||
func TestDB_IsSmall(t *testing.T) {
|
func TestDB_IsSmall(t *testing.T) {
|
||||||
db := newDB(t)
|
db := newDB(t)
|
||||||
defer releaseDB(db)
|
|
||||||
|
|
||||||
raw1 := generateRawObject(t)
|
raw1 := generateRawObject(t)
|
||||||
raw2 := generateRawObject(t)
|
raw2 := generateRawObject(t)
|
||||||
|
|
Loading…
Reference in a new issue