Evgenii Stratonikov
d641cba2fc
Some checks failed
Build / Build Components (1.20) (pull_request) Failing after 3s
Build / Build Components (1.21) (pull_request) Failing after 3s
Tests and linters / Lint (pull_request) Failing after 3s
Tests and linters / Tests (1.20) (pull_request) Failing after 3s
Tests and linters / Tests (1.21) (pull_request) Failing after 3s
Tests and linters / Tests with -race (pull_request) Failing after 5s
Tests and linters / Staticcheck (pull_request) Failing after 8s
Vulncheck / Vulncheck (pull_request) Failing after 2s
Fix staticcheck warnings after go1.20 update. Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
67 lines
1.6 KiB
Go
67 lines
1.6 KiB
Go
package util_test
|
|
|
|
import (
|
|
"crypto/rand"
|
|
"testing"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/util"
|
|
objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
|
|
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
|
|
"github.com/google/uuid"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestMergeSplitInfo(t *testing.T) {
|
|
uid, err := uuid.NewUUID()
|
|
require.NoError(t, err)
|
|
|
|
splitID := objectSDK.NewSplitID()
|
|
splitID.SetUUID(uid)
|
|
|
|
var rawLinkID, rawLastID [32]byte
|
|
var linkID oid.ID
|
|
var lastID oid.ID
|
|
|
|
_, err = rand.Read(rawLinkID[:])
|
|
require.NoError(t, err)
|
|
linkID.SetSHA256(rawLinkID)
|
|
|
|
_, err = rand.Read(rawLastID[:])
|
|
require.NoError(t, err)
|
|
lastID.SetSHA256(rawLastID)
|
|
|
|
target := objectSDK.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 := objectSDK.NewSplitInfo()
|
|
|
|
result := util.MergeSplitInfo(target, to)
|
|
require.Equal(t, result, target)
|
|
})
|
|
|
|
t.Run("merge link", func(t *testing.T) {
|
|
from := objectSDK.NewSplitInfo()
|
|
from.SetSplitID(splitID)
|
|
from.SetLastPart(lastID)
|
|
|
|
to := objectSDK.NewSplitInfo()
|
|
to.SetLink(linkID)
|
|
|
|
result := util.MergeSplitInfo(from, to)
|
|
require.Equal(t, result, target)
|
|
})
|
|
t.Run("merge last", func(t *testing.T) {
|
|
from := objectSDK.NewSplitInfo()
|
|
from.SetSplitID(splitID)
|
|
from.SetLink(linkID)
|
|
|
|
to := objectSDK.NewSplitInfo()
|
|
to.SetLastPart(lastID)
|
|
|
|
result := util.MergeSplitInfo(from, to)
|
|
require.Equal(t, result, target)
|
|
})
|
|
}
|