[#64] object/test: reuse checksum and signature generators

These were missing from #53.

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
Evgenii Stratonikov 2021-11-08 13:04:45 +03:00 committed by Alex Vanin
parent 39d3317ef6
commit d6b72453fc
3 changed files with 41 additions and 6 deletions

21
checksum/test/generate.go Normal file
View file

@ -0,0 +1,21 @@
package test
import (
"crypto/sha256"
"math/rand"
"github.com/nspcc-dev/neofs-sdk-go/checksum"
)
// Checksum returns random checksum.Checksum.
func Checksum() *checksum.Checksum {
var cs [sha256.Size]byte
rand.Read(cs[:])
x := checksum.New()
x.SetSHA256(cs)
return x
}

View file

@ -5,12 +5,12 @@ import (
"math/rand" "math/rand"
"github.com/google/uuid" "github.com/google/uuid"
"github.com/nspcc-dev/neofs-sdk-go/checksum" checksumtest "github.com/nspcc-dev/neofs-sdk-go/checksum/test"
cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test" cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test"
"github.com/nspcc-dev/neofs-sdk-go/object" "github.com/nspcc-dev/neofs-sdk-go/object"
ownertest "github.com/nspcc-dev/neofs-sdk-go/owner/test" ownertest "github.com/nspcc-dev/neofs-sdk-go/owner/test"
sessiontest "github.com/nspcc-dev/neofs-sdk-go/session/test" sessiontest "github.com/nspcc-dev/neofs-sdk-go/session/test"
"github.com/nspcc-dev/neofs-sdk-go/signature" sigtest "github.com/nspcc-dev/neofs-sdk-go/signature/test"
"github.com/nspcc-dev/neofs-sdk-go/version" "github.com/nspcc-dev/neofs-sdk-go/version"
) )
@ -88,10 +88,9 @@ func generateRaw(withParent bool) *object.RawObject {
x.SetChildren(ID(), ID()) x.SetChildren(ID(), ID())
x.SetAttributes(Attribute(), Attribute()) x.SetAttributes(Attribute(), Attribute())
x.SetSplitID(SplitID()) x.SetSplitID(SplitID())
// TODO reuse generators x.SetPayloadChecksum(checksumtest.Checksum())
x.SetPayloadChecksum(checksum.New()) x.SetPayloadHomomorphicHash(checksumtest.Checksum())
x.SetPayloadHomomorphicHash(checksum.New()) x.SetSignature(sigtest.Signature())
x.SetSignature(signature.New())
if withParent { if withParent {
x.SetParent(generateRaw(false).Object()) x.SetParent(generateRaw(false).Object())

View file

@ -0,0 +1,15 @@
package test
import (
"github.com/nspcc-dev/neofs-sdk-go/signature"
)
// Signature returns random pkg.Signature.
func Signature() *signature.Signature {
x := signature.New()
x.SetKey([]byte("key"))
x.SetSign([]byte("sign"))
return x
}