[#293] pkg/object: Implement and use generator of ID

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2021-06-08 11:38:29 +03:00 committed by Alex Vanin
parent 72adf5f972
commit dd0a883637
2 changed files with 8 additions and 27 deletions

View file

@ -1,29 +1,16 @@
package audit_test
import (
"crypto/rand"
"crypto/sha256"
"testing"
"github.com/nspcc-dev/neofs-api-go/pkg"
"github.com/nspcc-dev/neofs-api-go/pkg/audit"
cidtest "github.com/nspcc-dev/neofs-api-go/pkg/container/id/test"
"github.com/nspcc-dev/neofs-api-go/pkg/object"
objecttest "github.com/nspcc-dev/neofs-api-go/pkg/object/test"
"github.com/stretchr/testify/require"
)
func testSHA256() (cs [sha256.Size]byte) {
_, _ = rand.Read(cs[:])
return
}
func testOID() *object.ID {
id := object.NewID()
id.SetSHA256(testSHA256())
return id
}
func TestResult(t *testing.T) {
r := audit.NewResult()
require.Equal(t, pkg.SDKVersion(), r.Version())
@ -51,11 +38,11 @@ func TestResult(t *testing.T) {
r.SetRetries(retries)
require.Equal(t, retries, r.Retries())
passSG := []*object.ID{testOID(), testOID()}
passSG := []*object.ID{objecttest.GenerateID(), objecttest.GenerateID()}
r.SetPassSG(passSG)
require.Equal(t, passSG, r.PassSG())
failSG := []*object.ID{testOID(), testOID()}
failSG := []*object.ID{objecttest.GenerateID(), objecttest.GenerateID()}
r.SetFailSG(failSG)
require.Equal(t, failSG, r.FailSG())
@ -85,8 +72,8 @@ func TestStorageGroupEncoding(t *testing.T) {
r.SetAuditEpoch(13)
r.SetContainerID(cidtest.Generate())
r.SetPublicKey([]byte{1, 2, 3})
r.SetPassSG([]*object.ID{testOID(), testOID()})
r.SetFailSG([]*object.ID{testOID(), testOID()})
r.SetPassSG([]*object.ID{objecttest.GenerateID(), objecttest.GenerateID()})
r.SetFailSG([]*object.ID{objecttest.GenerateID(), objecttest.GenerateID()})
r.SetRequests(3)
r.SetRetries(2)
r.SetHit(1)

View file

@ -7,6 +7,7 @@ import (
"github.com/nspcc-dev/neofs-api-go/pkg"
"github.com/nspcc-dev/neofs-api-go/pkg/object"
objecttest "github.com/nspcc-dev/neofs-api-go/pkg/object/test"
"github.com/nspcc-dev/neofs-api-go/pkg/storagegroup"
"github.com/stretchr/testify/require"
)
@ -23,13 +24,6 @@ func testChecksum() *pkg.Checksum {
return h
}
func testOID() *object.ID {
id := object.NewID()
id.SetSHA256(testSHA256())
return id
}
func TestStorageGroup(t *testing.T) {
sg := storagegroup.New()
@ -45,7 +39,7 @@ func TestStorageGroup(t *testing.T) {
sg.SetExpirationEpoch(exp)
require.Equal(t, exp, sg.ExpirationEpoch())
members := []*object.ID{testOID(), testOID()}
members := []*object.ID{objecttest.GenerateID(), objecttest.GenerateID()}
sg.SetMembers(members)
require.Equal(t, members, sg.Members())
}
@ -55,7 +49,7 @@ func TestStorageGroupEncoding(t *testing.T) {
sg.SetValidationDataSize(13)
sg.SetValidationDataHash(testChecksum())
sg.SetExpirationEpoch(33)
sg.SetMembers([]*object.ID{testOID(), testOID()})
sg.SetMembers([]*object.ID{objecttest.GenerateID(), objecttest.GenerateID()})
t.Run("binary", func(t *testing.T) {
data, err := sg.Marshal()