forked from TrueCloudLab/frostfs-node
26f03c6301
Signed-off-by: Alex Vanin <alexey@nspcc.ru>
127 lines
3.1 KiB
Go
127 lines
3.1 KiB
Go
package meta_test
|
|
|
|
import (
|
|
"errors"
|
|
"testing"
|
|
|
|
objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestDB_Exists(t *testing.T) {
|
|
db := newDB(t)
|
|
defer releaseDB(db)
|
|
|
|
t.Run("no object", func(t *testing.T) {
|
|
nonExist := generateRawObject(t)
|
|
exists, err := db.Exists(nonExist.Object().Address())
|
|
require.NoError(t, err)
|
|
require.False(t, exists)
|
|
})
|
|
|
|
t.Run("regular object", func(t *testing.T) {
|
|
regular := generateRawObject(t)
|
|
err := db.Put(regular.Object(), nil)
|
|
require.NoError(t, err)
|
|
|
|
exists, err := db.Exists(regular.Object().Address())
|
|
require.NoError(t, err)
|
|
require.True(t, exists)
|
|
})
|
|
|
|
t.Run("tombstone object", func(t *testing.T) {
|
|
ts := generateRawObject(t)
|
|
ts.SetType(objectSDK.TypeTombstone)
|
|
|
|
err := db.Put(ts.Object(), nil)
|
|
require.NoError(t, err)
|
|
|
|
exists, err := db.Exists(ts.Object().Address())
|
|
require.NoError(t, err)
|
|
require.True(t, exists)
|
|
})
|
|
|
|
t.Run("storage group object", func(t *testing.T) {
|
|
sg := generateRawObject(t)
|
|
sg.SetType(objectSDK.TypeStorageGroup)
|
|
|
|
err := db.Put(sg.Object(), nil)
|
|
require.NoError(t, err)
|
|
|
|
exists, err := db.Exists(sg.Object().Address())
|
|
require.NoError(t, err)
|
|
require.True(t, exists)
|
|
})
|
|
|
|
t.Run("virtual object", func(t *testing.T) {
|
|
cid := testCID()
|
|
parent := generateRawObjectWithCID(t, cid)
|
|
|
|
child := generateRawObjectWithCID(t, cid)
|
|
child.SetParent(parent.Object().SDK())
|
|
child.SetParentID(parent.ID())
|
|
|
|
err := db.Put(child.Object(), nil)
|
|
require.NoError(t, err)
|
|
|
|
_, err = db.Exists(parent.Object().Address())
|
|
|
|
var expectedErr *objectSDK.SplitInfoError
|
|
require.True(t, errors.As(err, &expectedErr))
|
|
})
|
|
|
|
t.Run("merge split info", func(t *testing.T) {
|
|
cid := testCID()
|
|
splitID := objectSDK.NewSplitID()
|
|
|
|
parent := generateRawObjectWithCID(t, cid)
|
|
addAttribute(parent, "foo", "bar")
|
|
|
|
child := generateRawObjectWithCID(t, cid)
|
|
child.SetParent(parent.Object().SDK())
|
|
child.SetParentID(parent.ID())
|
|
child.SetSplitID(splitID)
|
|
|
|
link := generateRawObjectWithCID(t, cid)
|
|
link.SetParent(parent.Object().SDK())
|
|
link.SetParentID(parent.ID())
|
|
link.SetChildren(child.ID())
|
|
link.SetSplitID(splitID)
|
|
|
|
t.Run("direct order", func(t *testing.T) {
|
|
err := db.Put(child.Object(), nil)
|
|
require.NoError(t, err)
|
|
|
|
err = db.Put(link.Object(), nil)
|
|
require.NoError(t, err)
|
|
|
|
_, err = db.Exists(parent.Object().Address())
|
|
require.Error(t, err)
|
|
|
|
si, ok := err.(*objectSDK.SplitInfoError)
|
|
require.True(t, ok)
|
|
|
|
require.Equal(t, splitID, si.SplitInfo().SplitID())
|
|
require.Equal(t, child.ID(), si.SplitInfo().LastPart())
|
|
require.Equal(t, link.ID(), si.SplitInfo().Link())
|
|
})
|
|
|
|
t.Run("reverse order", func(t *testing.T) {
|
|
err := db.Put(link.Object(), nil)
|
|
require.NoError(t, err)
|
|
|
|
err = db.Put(child.Object(), nil)
|
|
require.NoError(t, err)
|
|
|
|
_, err = db.Exists(parent.Object().Address())
|
|
require.Error(t, err)
|
|
|
|
si, ok := err.(*objectSDK.SplitInfoError)
|
|
require.True(t, ok)
|
|
|
|
require.Equal(t, splitID, si.SplitInfo().SplitID())
|
|
require.Equal(t, child.ID(), si.SplitInfo().LastPart())
|
|
require.Equal(t, link.ID(), si.SplitInfo().Link())
|
|
})
|
|
})
|
|
}
|