2021-04-15 07:23:52 +00:00
|
|
|
package util_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"math/rand"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/google/uuid"
|
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/util"
|
2021-11-10 07:08:33 +00:00
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/object"
|
2022-05-31 17:00:41 +00:00
|
|
|
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
2021-04-15 07:23:52 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestMergeSplitInfo(t *testing.T) {
|
|
|
|
uid, err := uuid.NewUUID()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
splitID := object.NewSplitID()
|
|
|
|
splitID.SetUUID(uid)
|
|
|
|
|
|
|
|
var rawLinkID, rawLastID [32]byte
|
2022-05-31 17:00:41 +00:00
|
|
|
var linkID oid.ID
|
|
|
|
var lastID oid.ID
|
2021-04-15 07:23:52 +00:00
|
|
|
|
|
|
|
_, err = rand.Read(rawLinkID[:])
|
|
|
|
require.NoError(t, err)
|
|
|
|
linkID.SetSHA256(rawLinkID)
|
|
|
|
|
|
|
|
_, err = rand.Read(rawLastID[:])
|
|
|
|
require.NoError(t, err)
|
|
|
|
lastID.SetSHA256(rawLastID)
|
|
|
|
|
|
|
|
target := object.NewSplitInfo() // target is SplitInfo struct with all fields set
|
|
|
|
target.SetSplitID(splitID)
|
|
|
|
target.SetLastPart(lastID)
|
|
|
|
target.SetLink(linkID)
|
|
|
|
|
|
|
|
t.Run("merge empty", func(t *testing.T) {
|
|
|
|
to := object.NewSplitInfo()
|
|
|
|
|
|
|
|
result := util.MergeSplitInfo(target, to)
|
|
|
|
require.Equal(t, result, target)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("merge link", func(t *testing.T) {
|
|
|
|
from := object.NewSplitInfo()
|
|
|
|
from.SetSplitID(splitID)
|
|
|
|
from.SetLastPart(lastID)
|
|
|
|
|
|
|
|
to := object.NewSplitInfo()
|
|
|
|
to.SetLink(linkID)
|
|
|
|
|
|
|
|
result := util.MergeSplitInfo(from, to)
|
|
|
|
require.Equal(t, result, target)
|
|
|
|
})
|
|
|
|
t.Run("merge last", func(t *testing.T) {
|
|
|
|
from := object.NewSplitInfo()
|
|
|
|
from.SetSplitID(splitID)
|
|
|
|
from.SetLink(linkID)
|
|
|
|
|
|
|
|
to := object.NewSplitInfo()
|
|
|
|
to.SetLastPart(lastID)
|
|
|
|
|
|
|
|
result := util.MergeSplitInfo(from, to)
|
|
|
|
require.Equal(t, result, target)
|
|
|
|
})
|
|
|
|
}
|