frostfs-node/pkg/local_object_storage/internal/testutil/object.go
Alexander Chuprov 033eaf77e1 [] node: Fix linter importas
Standardize the alias of the
import frostfs-sdk-go/object as objectSDK.

Signed-off-by: Alexander Chuprov <a.chuprov@yadro.com>
2023-07-06 15:36:41 +03:00

68 lines
1.7 KiB
Go

package testutil
import (
"crypto/sha256"
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/checksum"
cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id"
cidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id/test"
objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
oidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id/test"
usertest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/user/test"
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/version"
"git.frostfs.info/TrueCloudLab/tzhash/tz"
"golang.org/x/exp/rand"
)
const defaultDataSize = 32
func GenerateObject() *objectSDK.Object {
return GenerateObjectWithCID(cidtest.ID())
}
func GenerateObjectWithCID(cnr cid.ID) *objectSDK.Object {
data := make([]byte, defaultDataSize)
_, _ = rand.Read(data)
return GenerateObjectWithCIDWithPayload(cnr, data)
}
func GenerateObjectWithCIDWithPayload(cnr cid.ID, data []byte) *objectSDK.Object {
var ver version.Version
ver.SetMajor(2)
ver.SetMinor(1)
var csum checksum.Checksum
csum.SetSHA256(sha256.Sum256(data))
var csumTZ checksum.Checksum
csumTZ.SetTillichZemor(tz.Sum(csum.Value()))
obj := objectSDK.New()
obj.SetID(oidtest.ID())
obj.SetOwnerID(usertest.ID())
obj.SetContainerID(cnr)
obj.SetVersion(&ver)
obj.SetPayload(data)
obj.SetPayloadChecksum(csum)
obj.SetPayloadHomomorphicHash(csumTZ)
return obj
}
func AddAttribute(obj *objectSDK.Object, key, val string) {
var attr objectSDK.Attribute
attr.SetKey(key)
attr.SetValue(val)
attrs := obj.Attributes()
attrs = append(attrs, attr)
obj.SetAttributes(attrs...)
}
func AddPayload(obj *objectSDK.Object, size int) {
buf := make([]byte, size)
_, _ = rand.Read(buf)
obj.SetPayload(buf)
obj.SetPayloadSize(uint64(size))
}