From 075003c4f1d9198e4a89921dede1ece811a6c64b Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Tue, 8 Jun 2021 14:34:44 +0300 Subject: [PATCH] [#293] pkg: Implement and use generators of the messages Signed-off-by: Leonard Lyubich --- pkg/acl/eacl/test/generate.go | 3 +++ pkg/test/generate.go | 51 +++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 pkg/test/generate.go diff --git a/pkg/acl/eacl/test/generate.go b/pkg/acl/eacl/test/generate.go index 456871a..ce8c4dd 100644 --- a/pkg/acl/eacl/test/generate.go +++ b/pkg/acl/eacl/test/generate.go @@ -5,6 +5,7 @@ import ( cidtest "github.com/nspcc-dev/neofs-api-go/pkg/container/id/test" ownertest "github.com/nspcc-dev/neofs-api-go/pkg/owner/test" sessiontest "github.com/nspcc-dev/neofs-api-go/pkg/session/test" + refstest "github.com/nspcc-dev/neofs-api-go/pkg/test" ) // Target returns random eacl.Target. @@ -40,6 +41,8 @@ func Table() *eacl.Table { x.SetSessionToken(sessiontest.Generate()) x.AddRecord(Record()) x.AddRecord(Record()) + x.SetVersion(*refstest.Version()) + x.SetSignature(refstest.Signature()) return x } diff --git a/pkg/test/generate.go b/pkg/test/generate.go new file mode 100644 index 0000000..5bd0933 --- /dev/null +++ b/pkg/test/generate.go @@ -0,0 +1,51 @@ +package refstest + +import ( + "crypto/sha256" + "math/rand" + + "github.com/nspcc-dev/neofs-api-go/pkg" +) + +// Checksum returns random pkg.Checksum. +func Checksum() *pkg.Checksum { + var cs [sha256.Size]byte + + rand.Read(cs[:]) + + x := pkg.NewChecksum() + + x.SetSHA256(cs) + + return x +} + +// Signature returns random pkg.Signature. +func Signature() *pkg.Signature { + x := pkg.NewSignature() + + x.SetKey([]byte("key")) + x.SetSign([]byte("sign")) + + return x +} + +// Version returns random pkg.Version. +func Version() *pkg.Version { + x := pkg.NewVersion() + + x.SetMajor(2) + x.SetMinor(1) + + return x +} + +// XHeader returns random pkg.XHeader. +func XHeader() *pkg.XHeader { + x := pkg.NewXHeader() + + x.SetKey("key") + x.SetValue("value") + + return x +}