From 54cd91adffd3ae324dc6e0f352b731a720ed86af Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Fri, 27 Nov 2020 12:03:35 +0300 Subject: [PATCH] [#199] Simplify tests Signed-off-by: Alex Vanin --- .../metabase/v2/exists_test.go | 2 +- pkg/local_object_storage/metabase/v2/get_test.go | 2 +- .../metabase/v2/inhume_test.go | 10 ++++------ .../metabase/v2/movable_test.go | 16 ++++++---------- .../metabase/v2/select_test.go | 8 ++++---- .../metabase/v2/small_test.go | 16 ++++++---------- 6 files changed, 22 insertions(+), 32 deletions(-) diff --git a/pkg/local_object_storage/metabase/v2/exists_test.go b/pkg/local_object_storage/metabase/v2/exists_test.go index 2ebec728c..011a74f89 100644 --- a/pkg/local_object_storage/metabase/v2/exists_test.go +++ b/pkg/local_object_storage/metabase/v2/exists_test.go @@ -58,7 +58,7 @@ func TestDB_Exists(t *testing.T) { child := generateRawObjectWithCID(t, cid) child.SetParent(parent.Object().SDK()) - child.SetParentID(parent.Object().Address().ObjectID()) + child.SetParentID(parent.ID()) err := db.Put(child.Object(), nil) require.NoError(t, err) diff --git a/pkg/local_object_storage/metabase/v2/get_test.go b/pkg/local_object_storage/metabase/v2/get_test.go index 070770c57..d0de02ef1 100644 --- a/pkg/local_object_storage/metabase/v2/get_test.go +++ b/pkg/local_object_storage/metabase/v2/get_test.go @@ -64,7 +64,7 @@ func TestDB_Get(t *testing.T) { child := generateRawObjectWithCID(t, cid) child.SetParent(parent.Object().SDK()) - child.SetParentID(parent.Object().Address().ObjectID()) + child.SetParentID(parent.ID()) err := db.Put(child.Object(), nil) require.NoError(t, err) diff --git a/pkg/local_object_storage/metabase/v2/inhume_test.go b/pkg/local_object_storage/metabase/v2/inhume_test.go index 101a3fd09..b1ea9c469 100644 --- a/pkg/local_object_storage/metabase/v2/inhume_test.go +++ b/pkg/local_object_storage/metabase/v2/inhume_test.go @@ -3,7 +3,6 @@ package meta_test import ( "testing" - "github.com/nspcc-dev/neofs-node/pkg/core/object" meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase/v2" "github.com/stretchr/testify/require" ) @@ -15,18 +14,17 @@ func TestDB_Inhume(t *testing.T) { raw := generateRawObject(t) addAttribute(raw, "foo", "bar") - obj := object.NewFromV2(raw.ToV2()) tombstoneID := generateAddress() - err := db.Put(obj, nil) + err := db.Put(raw.Object(), nil) require.NoError(t, err) - err = db.Inhume(obj.Address(), tombstoneID) + err = db.Inhume(raw.Object().Address(), tombstoneID) require.NoError(t, err) - _, err = db.Exists(obj.Address()) + _, err = db.Exists(raw.Object().Address()) require.EqualError(t, err, meta.ErrAlreadyRemoved.Error()) - _, err = db.Get(obj.Address()) + _, err = db.Get(raw.Object().Address()) require.EqualError(t, err, meta.ErrAlreadyRemoved.Error()) } diff --git a/pkg/local_object_storage/metabase/v2/movable_test.go b/pkg/local_object_storage/metabase/v2/movable_test.go index 70a09c517..13e4b2062 100644 --- a/pkg/local_object_storage/metabase/v2/movable_test.go +++ b/pkg/local_object_storage/metabase/v2/movable_test.go @@ -3,7 +3,6 @@ package meta_test import ( "testing" - "github.com/nspcc-dev/neofs-node/pkg/core/object" "github.com/stretchr/testify/require" ) @@ -14,14 +13,11 @@ func TestDB_Movable(t *testing.T) { raw1 := generateRawObject(t) raw2 := generateRawObject(t) - obj1 := object.NewFromV2(raw1.ToV2()) - obj2 := object.NewFromV2(raw2.ToV2()) - // put two objects in metabase - err := db.Put(obj1, nil) + err := db.Put(raw1.Object(), nil) require.NoError(t, err) - err = db.Put(obj2, nil) + err = db.Put(raw2.Object(), nil) require.NoError(t, err) // check if toMoveIt index empty @@ -30,17 +26,17 @@ func TestDB_Movable(t *testing.T) { require.Len(t, toMoveList, 0) // mark to move object2 - err = db.ToMoveIt(obj2.Address()) + err = db.ToMoveIt(raw2.Object().Address()) require.NoError(t, err) // check if toMoveIt index contains address of object 2 toMoveList, err = db.Movable() require.NoError(t, err) require.Len(t, toMoveList, 1) - require.Contains(t, toMoveList, obj2.Address()) + require.Contains(t, toMoveList, raw2.Object().Address()) // remove from toMoveIt index non existing address - err = db.DoNotMove(obj1.Address()) + err = db.DoNotMove(raw1.Object().Address()) require.NoError(t, err) // check if toMoveIt index hasn't changed @@ -49,7 +45,7 @@ func TestDB_Movable(t *testing.T) { require.Len(t, toMoveList, 1) // remove from toMoveIt index existing address - err = db.DoNotMove(obj2.Address()) + err = db.DoNotMove(raw2.Object().Address()) require.NoError(t, err) // check if toMoveIt index is empty now diff --git a/pkg/local_object_storage/metabase/v2/select_test.go b/pkg/local_object_storage/metabase/v2/select_test.go index 4d3b29a97..b84d6562b 100644 --- a/pkg/local_object_storage/metabase/v2/select_test.go +++ b/pkg/local_object_storage/metabase/v2/select_test.go @@ -95,14 +95,14 @@ func TestDB_SelectRootPhyParent(t *testing.T) { rightChild := generateRawObjectWithCID(t, cid) rightChild.SetParent(parent.Object().SDK()) - rightChild.SetParentID(parent.Object().Address().ObjectID()) + rightChild.SetParentID(parent.ID()) err = db.Put(rightChild.Object(), nil) require.NoError(t, err) link := generateRawObjectWithCID(t, cid) link.SetParent(parent.Object().SDK()) - link.SetParentID(parent.Object().Address().ObjectID()) - link.SetChildren(leftChild.Object().Address().ObjectID(), rightChild.Object().Address().ObjectID()) + link.SetParentID(parent.ID()) + link.SetChildren(leftChild.ID(), rightChild.ID()) err = db.Put(link.Object(), nil) require.NoError(t, err) @@ -156,7 +156,7 @@ func TestDB_SelectRootPhyParent(t *testing.T) { t.Run("objects with parent", func(t *testing.T) { fs := generateSearchFilter(cid) fs.AddFilter(v2object.FilterHeaderParent, - parent.Object().Address().ObjectID().String(), + parent.ID().String(), objectSDK.MatchStringEqual) testSelect(t, db, fs, diff --git a/pkg/local_object_storage/metabase/v2/small_test.go b/pkg/local_object_storage/metabase/v2/small_test.go index 4f92a5c95..451bde1be 100644 --- a/pkg/local_object_storage/metabase/v2/small_test.go +++ b/pkg/local_object_storage/metabase/v2/small_test.go @@ -3,7 +3,6 @@ package meta_test import ( "testing" - "github.com/nspcc-dev/neofs-node/pkg/core/object" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobovnicza" "github.com/stretchr/testify/require" ) @@ -17,29 +16,26 @@ func TestDB_IsSmall(t *testing.T) { blobovniczaID := blobovnicza.ID{1, 2, 3, 4} - obj1 := object.NewFromV2(raw1.ToV2()) - obj2 := object.NewFromV2(raw2.ToV2()) - // check IsSmall from empty database - fetchedBlobovniczaID, err := db.IsSmall(obj1.Address()) + fetchedBlobovniczaID, err := db.IsSmall(raw1.Object().Address()) require.NoError(t, err) require.Nil(t, fetchedBlobovniczaID) // put one object with blobovniczaID - err = db.Put(obj1, &blobovniczaID) + err = db.Put(raw1.Object(), &blobovniczaID) require.NoError(t, err) // put one object without blobovniczaID - err = db.Put(obj2, nil) + err = db.Put(raw2.Object(), nil) require.NoError(t, err) // check IsSmall for object without blobovniczaID - fetchedBlobovniczaID, err = db.IsSmall(obj2.Address()) + fetchedBlobovniczaID, err = db.IsSmall(raw2.Object().Address()) require.NoError(t, err) require.Nil(t, fetchedBlobovniczaID) // check IsSmall for object with blobovniczaID - fetchedBlobovniczaID, err = db.IsSmall(obj1.Address()) + fetchedBlobovniczaID, err = db.IsSmall(raw1.Object().Address()) require.NoError(t, err) - require.Equal(t, blobovniczaID, *fetchedBlobovniczaID) + require.Equal(t, &blobovniczaID, fetchedBlobovniczaID) }