[#199] Simplify tests

Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
Alex Vanin 2020-11-27 12:03:35 +03:00
parent a8d76f2ebb
commit 54cd91adff
6 changed files with 22 additions and 32 deletions

View file

@ -58,7 +58,7 @@ func TestDB_Exists(t *testing.T) {
child := generateRawObjectWithCID(t, cid) child := generateRawObjectWithCID(t, cid)
child.SetParent(parent.Object().SDK()) child.SetParent(parent.Object().SDK())
child.SetParentID(parent.Object().Address().ObjectID()) child.SetParentID(parent.ID())
err := db.Put(child.Object(), nil) err := db.Put(child.Object(), nil)
require.NoError(t, err) require.NoError(t, err)

View file

@ -64,7 +64,7 @@ func TestDB_Get(t *testing.T) {
child := generateRawObjectWithCID(t, cid) child := generateRawObjectWithCID(t, cid)
child.SetParent(parent.Object().SDK()) child.SetParent(parent.Object().SDK())
child.SetParentID(parent.Object().Address().ObjectID()) child.SetParentID(parent.ID())
err := db.Put(child.Object(), nil) err := db.Put(child.Object(), nil)
require.NoError(t, err) require.NoError(t, err)

View file

@ -3,7 +3,6 @@ package meta_test
import ( import (
"testing" "testing"
"github.com/nspcc-dev/neofs-node/pkg/core/object"
meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase/v2" meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase/v2"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
@ -15,18 +14,17 @@ func TestDB_Inhume(t *testing.T) {
raw := generateRawObject(t) raw := generateRawObject(t)
addAttribute(raw, "foo", "bar") addAttribute(raw, "foo", "bar")
obj := object.NewFromV2(raw.ToV2())
tombstoneID := generateAddress() tombstoneID := generateAddress()
err := db.Put(obj, nil) err := db.Put(raw.Object(), nil)
require.NoError(t, err) require.NoError(t, err)
err = db.Inhume(obj.Address(), tombstoneID) err = db.Inhume(raw.Object().Address(), tombstoneID)
require.NoError(t, err) require.NoError(t, err)
_, err = db.Exists(obj.Address()) _, err = db.Exists(raw.Object().Address())
require.EqualError(t, err, meta.ErrAlreadyRemoved.Error()) 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()) require.EqualError(t, err, meta.ErrAlreadyRemoved.Error())
} }

View file

@ -3,7 +3,6 @@ package meta_test
import ( import (
"testing" "testing"
"github.com/nspcc-dev/neofs-node/pkg/core/object"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
@ -14,14 +13,11 @@ func TestDB_Movable(t *testing.T) {
raw1 := generateRawObject(t) raw1 := generateRawObject(t)
raw2 := generateRawObject(t) raw2 := generateRawObject(t)
obj1 := object.NewFromV2(raw1.ToV2())
obj2 := object.NewFromV2(raw2.ToV2())
// put two objects in metabase // put two objects in metabase
err := db.Put(obj1, nil) err := db.Put(raw1.Object(), nil)
require.NoError(t, err) require.NoError(t, err)
err = db.Put(obj2, nil) err = db.Put(raw2.Object(), nil)
require.NoError(t, err) require.NoError(t, err)
// check if toMoveIt index empty // check if toMoveIt index empty
@ -30,17 +26,17 @@ func TestDB_Movable(t *testing.T) {
require.Len(t, toMoveList, 0) require.Len(t, toMoveList, 0)
// mark to move object2 // mark to move object2
err = db.ToMoveIt(obj2.Address()) err = db.ToMoveIt(raw2.Object().Address())
require.NoError(t, err) require.NoError(t, err)
// check if toMoveIt index contains address of object 2 // check if toMoveIt index contains address of object 2
toMoveList, err = db.Movable() toMoveList, err = db.Movable()
require.NoError(t, err) require.NoError(t, err)
require.Len(t, toMoveList, 1) 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 // remove from toMoveIt index non existing address
err = db.DoNotMove(obj1.Address()) err = db.DoNotMove(raw1.Object().Address())
require.NoError(t, err) require.NoError(t, err)
// check if toMoveIt index hasn't changed // check if toMoveIt index hasn't changed
@ -49,7 +45,7 @@ func TestDB_Movable(t *testing.T) {
require.Len(t, toMoveList, 1) require.Len(t, toMoveList, 1)
// remove from toMoveIt index existing address // remove from toMoveIt index existing address
err = db.DoNotMove(obj2.Address()) err = db.DoNotMove(raw2.Object().Address())
require.NoError(t, err) require.NoError(t, err)
// check if toMoveIt index is empty now // check if toMoveIt index is empty now

View file

@ -95,14 +95,14 @@ func TestDB_SelectRootPhyParent(t *testing.T) {
rightChild := generateRawObjectWithCID(t, cid) rightChild := generateRawObjectWithCID(t, cid)
rightChild.SetParent(parent.Object().SDK()) rightChild.SetParent(parent.Object().SDK())
rightChild.SetParentID(parent.Object().Address().ObjectID()) rightChild.SetParentID(parent.ID())
err = db.Put(rightChild.Object(), nil) err = db.Put(rightChild.Object(), nil)
require.NoError(t, err) require.NoError(t, err)
link := generateRawObjectWithCID(t, cid) link := generateRawObjectWithCID(t, cid)
link.SetParent(parent.Object().SDK()) link.SetParent(parent.Object().SDK())
link.SetParentID(parent.Object().Address().ObjectID()) link.SetParentID(parent.ID())
link.SetChildren(leftChild.Object().Address().ObjectID(), rightChild.Object().Address().ObjectID()) link.SetChildren(leftChild.ID(), rightChild.ID())
err = db.Put(link.Object(), nil) err = db.Put(link.Object(), nil)
require.NoError(t, err) require.NoError(t, err)
@ -156,7 +156,7 @@ func TestDB_SelectRootPhyParent(t *testing.T) {
t.Run("objects with parent", func(t *testing.T) { t.Run("objects with parent", func(t *testing.T) {
fs := generateSearchFilter(cid) fs := generateSearchFilter(cid)
fs.AddFilter(v2object.FilterHeaderParent, fs.AddFilter(v2object.FilterHeaderParent,
parent.Object().Address().ObjectID().String(), parent.ID().String(),
objectSDK.MatchStringEqual) objectSDK.MatchStringEqual)
testSelect(t, db, fs, testSelect(t, db, fs,

View file

@ -3,7 +3,6 @@ package meta_test
import ( import (
"testing" "testing"
"github.com/nspcc-dev/neofs-node/pkg/core/object"
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobovnicza" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobovnicza"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
@ -17,29 +16,26 @@ func TestDB_IsSmall(t *testing.T) {
blobovniczaID := blobovnicza.ID{1, 2, 3, 4} blobovniczaID := blobovnicza.ID{1, 2, 3, 4}
obj1 := object.NewFromV2(raw1.ToV2())
obj2 := object.NewFromV2(raw2.ToV2())
// check IsSmall from empty database // check IsSmall from empty database
fetchedBlobovniczaID, err := db.IsSmall(obj1.Address()) fetchedBlobovniczaID, err := db.IsSmall(raw1.Object().Address())
require.NoError(t, err) require.NoError(t, err)
require.Nil(t, fetchedBlobovniczaID) require.Nil(t, fetchedBlobovniczaID)
// put one object with blobovniczaID // put one object with blobovniczaID
err = db.Put(obj1, &blobovniczaID) err = db.Put(raw1.Object(), &blobovniczaID)
require.NoError(t, err) require.NoError(t, err)
// put one object without blobovniczaID // put one object without blobovniczaID
err = db.Put(obj2, nil) err = db.Put(raw2.Object(), nil)
require.NoError(t, err) require.NoError(t, err)
// check IsSmall for object without blobovniczaID // check IsSmall for object without blobovniczaID
fetchedBlobovniczaID, err = db.IsSmall(obj2.Address()) fetchedBlobovniczaID, err = db.IsSmall(raw2.Object().Address())
require.NoError(t, err) require.NoError(t, err)
require.Nil(t, fetchedBlobovniczaID) require.Nil(t, fetchedBlobovniczaID)
// check IsSmall for object with blobovniczaID // check IsSmall for object with blobovniczaID
fetchedBlobovniczaID, err = db.IsSmall(obj1.Address()) fetchedBlobovniczaID, err = db.IsSmall(raw1.Object().Address())
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, blobovniczaID, *fetchedBlobovniczaID) require.Equal(t, &blobovniczaID, fetchedBlobovniczaID)
} }