2021-04-15 07:23:52 +00:00
|
|
|
package util_test
|
|
|
|
|
|
|
|
import (
|
2023-08-09 13:01:44 +00:00
|
|
|
"crypto/rand"
|
2021-04-15 07:23:52 +00:00
|
|
|
"testing"
|
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/util"
|
2023-07-06 12:36:41 +00:00
|
|
|
objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
|
2023-03-07 13:38:26 +00:00
|
|
|
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
|
2021-04-15 07:23:52 +00:00
|
|
|
"github.com/google/uuid"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestMergeSplitInfo(t *testing.T) {
|
|
|
|
uid, err := uuid.NewUUID()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2023-07-06 12:36:41 +00:00
|
|
|
splitID := objectSDK.NewSplitID()
|
2021-04-15 07:23:52 +00:00
|
|
|
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)
|
|
|
|
|
2023-07-06 12:36:41 +00:00
|
|
|
target := objectSDK.NewSplitInfo() // target is SplitInfo struct with all fields set
|
2021-04-15 07:23:52 +00:00
|
|
|
target.SetSplitID(splitID)
|
|
|
|
target.SetLastPart(lastID)
|
|
|
|
target.SetLink(linkID)
|
|
|
|
|
|
|
|
t.Run("merge empty", func(t *testing.T) {
|
2023-07-06 12:36:41 +00:00
|
|
|
to := objectSDK.NewSplitInfo()
|
2021-04-15 07:23:52 +00:00
|
|
|
|
|
|
|
result := util.MergeSplitInfo(target, to)
|
|
|
|
require.Equal(t, result, target)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("merge link", func(t *testing.T) {
|
2023-07-06 12:36:41 +00:00
|
|
|
from := objectSDK.NewSplitInfo()
|
2021-04-15 07:23:52 +00:00
|
|
|
from.SetSplitID(splitID)
|
|
|
|
from.SetLastPart(lastID)
|
|
|
|
|
2023-07-06 12:36:41 +00:00
|
|
|
to := objectSDK.NewSplitInfo()
|
2021-04-15 07:23:52 +00:00
|
|
|
to.SetLink(linkID)
|
|
|
|
|
|
|
|
result := util.MergeSplitInfo(from, to)
|
|
|
|
require.Equal(t, result, target)
|
|
|
|
})
|
|
|
|
t.Run("merge last", func(t *testing.T) {
|
2023-07-06 12:36:41 +00:00
|
|
|
from := objectSDK.NewSplitInfo()
|
2021-04-15 07:23:52 +00:00
|
|
|
from.SetSplitID(splitID)
|
|
|
|
from.SetLink(linkID)
|
|
|
|
|
2023-07-06 12:36:41 +00:00
|
|
|
to := objectSDK.NewSplitInfo()
|
2021-04-15 07:23:52 +00:00
|
|
|
to.SetLastPart(lastID)
|
|
|
|
|
|
|
|
result := util.MergeSplitInfo(from, to)
|
|
|
|
require.Equal(t, result, target)
|
|
|
|
})
|
|
|
|
}
|