68 lines
1.7 KiB
Go
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"
|
|
"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() *object.Object {
|
|
return GenerateObjectWithCID(cidtest.ID())
|
|
}
|
|
|
|
func GenerateObjectWithCID(cnr cid.ID) *object.Object {
|
|
data := make([]byte, defaultDataSize)
|
|
_, _ = rand.Read(data)
|
|
return GenerateObjectWithCIDWithPayload(cnr, data)
|
|
}
|
|
|
|
func GenerateObjectWithCIDWithPayload(cnr cid.ID, data []byte) *object.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 := object.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 *object.Object, key, val string) {
|
|
var attr object.Attribute
|
|
attr.SetKey(key)
|
|
attr.SetValue(val)
|
|
|
|
attrs := obj.Attributes()
|
|
attrs = append(attrs, attr)
|
|
obj.SetAttributes(attrs...)
|
|
}
|
|
|
|
func AddPayload(obj *object.Object, size int) {
|
|
buf := make([]byte, size)
|
|
_, _ = rand.Read(buf)
|
|
|
|
obj.SetPayload(buf)
|
|
obj.SetPayloadSize(uint64(size))
|
|
}
|