From d6b72453fce9b91a95be6bf25d6b93531d4e3b6e Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Mon, 8 Nov 2021 13:04:45 +0300 Subject: [PATCH] [#64] object/test: reuse checksum and signature generators These were missing from #53. Signed-off-by: Evgenii Stratonikov --- checksum/test/generate.go | 21 +++++++++++++++++++++ object/test/generate.go | 11 +++++------ signature/test/generate.go | 15 +++++++++++++++ 3 files changed, 41 insertions(+), 6 deletions(-) create mode 100644 checksum/test/generate.go create mode 100644 signature/test/generate.go diff --git a/checksum/test/generate.go b/checksum/test/generate.go new file mode 100644 index 0000000..0df988d --- /dev/null +++ b/checksum/test/generate.go @@ -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 +} diff --git a/object/test/generate.go b/object/test/generate.go index 4e5e5bd..23eef70 100644 --- a/object/test/generate.go +++ b/object/test/generate.go @@ -5,12 +5,12 @@ import ( "math/rand" "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" "github.com/nspcc-dev/neofs-sdk-go/object" ownertest "github.com/nspcc-dev/neofs-sdk-go/owner/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" ) @@ -88,10 +88,9 @@ func generateRaw(withParent bool) *object.RawObject { x.SetChildren(ID(), ID()) x.SetAttributes(Attribute(), Attribute()) x.SetSplitID(SplitID()) - // TODO reuse generators - x.SetPayloadChecksum(checksum.New()) - x.SetPayloadHomomorphicHash(checksum.New()) - x.SetSignature(signature.New()) + x.SetPayloadChecksum(checksumtest.Checksum()) + x.SetPayloadHomomorphicHash(checksumtest.Checksum()) + x.SetSignature(sigtest.Signature()) if withParent { x.SetParent(generateRaw(false).Object()) diff --git a/signature/test/generate.go b/signature/test/generate.go new file mode 100644 index 0000000..90e56cb --- /dev/null +++ b/signature/test/generate.go @@ -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 +}