forked from TrueCloudLab/frostfs-sdk-go
[#54] tests: unify test generator names
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
parent
fa7c01bd0b
commit
3d0df0d068
35 changed files with 113 additions and 113 deletions
|
@ -4,7 +4,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neofs-sdk-go/accounting"
|
"github.com/nspcc-dev/neofs-sdk-go/accounting"
|
||||||
test "github.com/nspcc-dev/neofs-sdk-go/accounting/test"
|
accountingtest "github.com/nspcc-dev/neofs-sdk-go/accounting/test"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ func TestDecimal(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDecimalEncoding(t *testing.T) {
|
func TestDecimalEncoding(t *testing.T) {
|
||||||
d := test.GenerateDecimal()
|
d := accountingtest.Decimal()
|
||||||
|
|
||||||
t.Run("binary", func(t *testing.T) {
|
t.Run("binary", func(t *testing.T) {
|
||||||
data, err := d.Marshal()
|
data, err := d.Marshal()
|
||||||
|
|
|
@ -6,8 +6,8 @@ import (
|
||||||
"github.com/nspcc-dev/neofs-sdk-go/accounting"
|
"github.com/nspcc-dev/neofs-sdk-go/accounting"
|
||||||
)
|
)
|
||||||
|
|
||||||
// GenerateDecimal returns random accounting.Decimal.
|
// Decimal returns random accounting.Decimal.
|
||||||
func GenerateDecimal() *accounting.Decimal {
|
func Decimal() *accounting.Decimal {
|
||||||
d := accounting.NewDecimal()
|
d := accounting.NewDecimal()
|
||||||
d.SetValue(rand.Int63())
|
d.SetValue(rand.Int63())
|
||||||
d.SetPrecision(rand.Uint32())
|
d.SetPrecision(rand.Uint32())
|
||||||
|
|
|
@ -21,7 +21,7 @@ func TestResult(t *testing.T) {
|
||||||
r.SetAuditEpoch(epoch)
|
r.SetAuditEpoch(epoch)
|
||||||
require.Equal(t, epoch, r.AuditEpoch())
|
require.Equal(t, epoch, r.AuditEpoch())
|
||||||
|
|
||||||
cid := cidtest.GenerateID()
|
cid := cidtest.ID()
|
||||||
r.SetContainerID(cid)
|
r.SetContainerID(cid)
|
||||||
require.Equal(t, cid, r.ContainerID())
|
require.Equal(t, cid, r.ContainerID())
|
||||||
|
|
||||||
|
@ -70,7 +70,7 @@ func TestResult(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestStorageGroupEncoding(t *testing.T) {
|
func TestStorageGroupEncoding(t *testing.T) {
|
||||||
r := audittest.Generate()
|
r := audittest.Result()
|
||||||
|
|
||||||
t.Run("binary", func(t *testing.T) {
|
t.Run("binary", func(t *testing.T) {
|
||||||
data, err := r.Marshal()
|
data, err := r.Marshal()
|
||||||
|
|
|
@ -8,12 +8,12 @@ import (
|
||||||
versiontest "github.com/nspcc-dev/neofs-sdk-go/version/test"
|
versiontest "github.com/nspcc-dev/neofs-sdk-go/version/test"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Generate returns random audit.Result.
|
// Result returns random audit.Result.
|
||||||
func Generate() *audit.Result {
|
func Result() *audit.Result {
|
||||||
x := audit.NewResult()
|
x := audit.NewResult()
|
||||||
|
|
||||||
x.SetVersion(versiontest.Version())
|
x.SetVersion(versiontest.Version())
|
||||||
x.SetContainerID(cidtest.GenerateID())
|
x.SetContainerID(cidtest.ID())
|
||||||
x.SetPublicKey([]byte("key"))
|
x.SetPublicKey([]byte("key"))
|
||||||
x.SetComplete(true)
|
x.SetComplete(true)
|
||||||
x.SetAuditEpoch(44)
|
x.SetAuditEpoch(44)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package test
|
package checksumtest
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
|
|
|
@ -17,7 +17,7 @@ func TestAnnouncement(t *testing.T) {
|
||||||
const epoch, usedSpace uint64 = 10, 100
|
const epoch, usedSpace uint64 = 10, 100
|
||||||
|
|
||||||
cidValue := [sha256.Size]byte{1, 2, 3}
|
cidValue := [sha256.Size]byte{1, 2, 3}
|
||||||
id := cidtest.GenerateIDWithChecksum(cidValue)
|
id := cidtest.IDWithChecksum(cidValue)
|
||||||
|
|
||||||
a := container.NewAnnouncement()
|
a := container.NewAnnouncement()
|
||||||
a.SetEpoch(epoch)
|
a.SetEpoch(epoch)
|
||||||
|
|
|
@ -20,7 +20,7 @@ func TestNewContainer(t *testing.T) {
|
||||||
|
|
||||||
nonce := uuid.New()
|
nonce := uuid.New()
|
||||||
|
|
||||||
ownerID := ownertest.GenerateID()
|
ownerID := ownertest.ID()
|
||||||
policy := netmaptest.PlacementPolicy()
|
policy := netmaptest.PlacementPolicy()
|
||||||
|
|
||||||
c.SetBasicACL(acl.PublicBasicRule)
|
c.SetBasicACL(acl.PublicBasicRule)
|
||||||
|
@ -75,7 +75,7 @@ func TestContainerEncoding(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestContainer_SessionToken(t *testing.T) {
|
func TestContainer_SessionToken(t *testing.T) {
|
||||||
tok := sessiontest.Generate()
|
tok := sessiontest.Token()
|
||||||
|
|
||||||
cnr := container.New()
|
cnr := container.New()
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ func TestID_ToV2(t *testing.T) {
|
||||||
t.Run("non-nil", func(t *testing.T) {
|
t.Run("non-nil", func(t *testing.T) {
|
||||||
checksum := randSHA256Checksum()
|
checksum := randSHA256Checksum()
|
||||||
|
|
||||||
id := cidtest.GenerateIDWithChecksum(checksum)
|
id := cidtest.IDWithChecksum(checksum)
|
||||||
|
|
||||||
idV2 := id.ToV2()
|
idV2 := id.ToV2()
|
||||||
|
|
||||||
|
@ -46,19 +46,19 @@ func TestID_ToV2(t *testing.T) {
|
||||||
func TestID_Equal(t *testing.T) {
|
func TestID_Equal(t *testing.T) {
|
||||||
cs := randSHA256Checksum()
|
cs := randSHA256Checksum()
|
||||||
|
|
||||||
id1 := cidtest.GenerateIDWithChecksum(cs)
|
id1 := cidtest.IDWithChecksum(cs)
|
||||||
id2 := cidtest.GenerateIDWithChecksum(cs)
|
id2 := cidtest.IDWithChecksum(cs)
|
||||||
|
|
||||||
require.True(t, id1.Equal(id2))
|
require.True(t, id1.Equal(id2))
|
||||||
|
|
||||||
id3 := cidtest.GenerateID()
|
id3 := cidtest.ID()
|
||||||
|
|
||||||
require.False(t, id1.Equal(id3))
|
require.False(t, id1.Equal(id3))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestID_String(t *testing.T) {
|
func TestID_String(t *testing.T) {
|
||||||
t.Run("Parse/String", func(t *testing.T) {
|
t.Run("Parse/String", func(t *testing.T) {
|
||||||
id := cidtest.GenerateID()
|
id := cidtest.ID()
|
||||||
id2 := cid.New()
|
id2 := cid.New()
|
||||||
|
|
||||||
require.NoError(t, id2.Parse(id.String()))
|
require.NoError(t, id2.Parse(id.String()))
|
||||||
|
@ -73,7 +73,7 @@ func TestID_String(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestContainerIDEncoding(t *testing.T) {
|
func TestContainerIDEncoding(t *testing.T) {
|
||||||
id := cidtest.GenerateID()
|
id := cidtest.ID()
|
||||||
|
|
||||||
t.Run("binary", func(t *testing.T) {
|
t.Run("binary", func(t *testing.T) {
|
||||||
data, err := id.Marshal()
|
data, err := id.Marshal()
|
||||||
|
|
|
@ -7,18 +7,18 @@ import (
|
||||||
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
|
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
|
||||||
)
|
)
|
||||||
|
|
||||||
// GenerateID returns random cid.ID.
|
// ID returns random cid.ID.
|
||||||
func GenerateID() *cid.ID {
|
func ID() *cid.ID {
|
||||||
checksum := [sha256.Size]byte{}
|
checksum := [sha256.Size]byte{}
|
||||||
|
|
||||||
rand.Read(checksum[:])
|
rand.Read(checksum[:])
|
||||||
|
|
||||||
return GenerateIDWithChecksum(checksum)
|
return IDWithChecksum(checksum)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GenerateIDWithChecksum returns cid.ID initialized
|
// IDWithChecksum returns cid.ID initialized
|
||||||
// with specified checksum.
|
// with specified checksum.
|
||||||
func GenerateIDWithChecksum(cs [sha256.Size]byte) *cid.ID {
|
func IDWithChecksum(cs [sha256.Size]byte) *cid.ID {
|
||||||
id := cid.New()
|
id := cid.New()
|
||||||
id.SetSHA256(cs)
|
id.SetSHA256(cs)
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@ func Container() *container.Container {
|
||||||
|
|
||||||
x.SetVersion(versiontest.Version())
|
x.SetVersion(versiontest.Version())
|
||||||
x.SetAttributes(Attributes())
|
x.SetAttributes(Attributes())
|
||||||
x.SetOwnerID(ownertest.GenerateID())
|
x.SetOwnerID(ownertest.ID())
|
||||||
x.SetBasicACL(123)
|
x.SetBasicACL(123)
|
||||||
x.SetPlacementPolicy(netmaptest.PlacementPolicy())
|
x.SetPlacementPolicy(netmaptest.PlacementPolicy())
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ func Container() *container.Container {
|
||||||
func UsedSpaceAnnouncement() *container.UsedSpaceAnnouncement {
|
func UsedSpaceAnnouncement() *container.UsedSpaceAnnouncement {
|
||||||
x := container.NewAnnouncement()
|
x := container.NewAnnouncement()
|
||||||
|
|
||||||
x.SetContainerID(cidtest.GenerateID())
|
x.SetContainerID(cidtest.ID())
|
||||||
x.SetEpoch(55)
|
x.SetEpoch(55)
|
||||||
x.SetUsedSpace(999)
|
x.SetUsedSpace(999)
|
||||||
|
|
||||||
|
|
|
@ -158,8 +158,8 @@ func TestReservedRecords(t *testing.T) {
|
||||||
var (
|
var (
|
||||||
v = versiontest.Version()
|
v = versiontest.Version()
|
||||||
oid = objecttest.ID()
|
oid = objecttest.ID()
|
||||||
cid = cidtest.GenerateID()
|
cid = cidtest.ID()
|
||||||
ownerid = ownertest.GenerateID()
|
ownerid = ownertest.ID()
|
||||||
h = checksumtest.Checksum()
|
h = checksumtest.Checksum()
|
||||||
typ = new(object.Type)
|
typ = new(object.Type)
|
||||||
)
|
)
|
||||||
|
|
|
@ -17,7 +17,7 @@ func TestTable(t *testing.T) {
|
||||||
var v version.Version
|
var v version.Version
|
||||||
|
|
||||||
sha := sha256.Sum256([]byte("container id"))
|
sha := sha256.Sum256([]byte("container id"))
|
||||||
id := cidtest.GenerateIDWithChecksum(sha)
|
id := cidtest.IDWithChecksum(sha)
|
||||||
|
|
||||||
v.SetMajor(3)
|
v.SetMajor(3)
|
||||||
v.SetMinor(2)
|
v.SetMinor(2)
|
||||||
|
@ -42,7 +42,7 @@ func TestTable(t *testing.T) {
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("create table", func(t *testing.T) {
|
t.Run("create table", func(t *testing.T) {
|
||||||
id := cidtest.GenerateID()
|
id := cidtest.ID()
|
||||||
|
|
||||||
table := eacl.CreateTable(*id)
|
table := eacl.CreateTable(*id)
|
||||||
require.Equal(t, id, table.CID())
|
require.Equal(t, id, table.CID())
|
||||||
|
@ -91,7 +91,7 @@ func TestTableEncoding(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTable_SessionToken(t *testing.T) {
|
func TestTable_SessionToken(t *testing.T) {
|
||||||
tok := sessiontest.Generate()
|
tok := sessiontest.Token()
|
||||||
|
|
||||||
table := eacl.NewTable()
|
table := eacl.NewTable()
|
||||||
table.SetSessionToken(tok)
|
table.SetSessionToken(tok)
|
||||||
|
|
|
@ -27,8 +27,8 @@ func Record() *eacl.Record {
|
||||||
x.SetAction(eacl.ActionAllow)
|
x.SetAction(eacl.ActionAllow)
|
||||||
x.SetOperation(eacl.OperationRangeHash)
|
x.SetOperation(eacl.OperationRangeHash)
|
||||||
x.SetTargets(Target(), Target())
|
x.SetTargets(Target(), Target())
|
||||||
x.AddObjectContainerIDFilter(eacl.MatchStringEqual, cidtest.GenerateID())
|
x.AddObjectContainerIDFilter(eacl.MatchStringEqual, cidtest.ID())
|
||||||
x.AddObjectOwnerIDFilter(eacl.MatchStringNotEqual, ownertest.GenerateID())
|
x.AddObjectOwnerIDFilter(eacl.MatchStringNotEqual, ownertest.ID())
|
||||||
|
|
||||||
return x
|
return x
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ func Record() *eacl.Record {
|
||||||
func Table() *eacl.Table {
|
func Table() *eacl.Table {
|
||||||
x := eacl.NewTable()
|
x := eacl.NewTable()
|
||||||
|
|
||||||
x.SetCID(cidtest.GenerateID())
|
x.SetCID(cidtest.ID())
|
||||||
x.AddRecord(Record())
|
x.AddRecord(Record())
|
||||||
x.AddRecord(Record())
|
x.AddRecord(Record())
|
||||||
x.SetVersion(*versiontest.Version())
|
x.SetVersion(*versiontest.Version())
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package test
|
package netmaptest
|
||||||
|
|
||||||
import "github.com/nspcc-dev/neofs-sdk-go/netmap"
|
import "github.com/nspcc-dev/neofs-sdk-go/netmap"
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@ import (
|
||||||
func TestAddress_SetContainerID(t *testing.T) {
|
func TestAddress_SetContainerID(t *testing.T) {
|
||||||
a := NewAddress()
|
a := NewAddress()
|
||||||
|
|
||||||
id := cidtest.GenerateID()
|
id := cidtest.ID()
|
||||||
|
|
||||||
a.SetContainerID(id)
|
a.SetContainerID(id)
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ func TestAddress_SetObjectID(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAddress_Parse(t *testing.T) {
|
func TestAddress_Parse(t *testing.T) {
|
||||||
cid := cidtest.GenerateID()
|
cid := cidtest.ID()
|
||||||
|
|
||||||
oid := NewID()
|
oid := NewID()
|
||||||
oid.SetSHA256(randSHA256Checksum(t))
|
oid.SetSHA256(randSHA256Checksum(t))
|
||||||
|
@ -63,7 +63,7 @@ func TestAddress_Parse(t *testing.T) {
|
||||||
func TestAddressEncoding(t *testing.T) {
|
func TestAddressEncoding(t *testing.T) {
|
||||||
a := NewAddress()
|
a := NewAddress()
|
||||||
a.SetObjectID(randID(t))
|
a.SetObjectID(randID(t))
|
||||||
a.SetContainerID(cidtest.GenerateID())
|
a.SetContainerID(cidtest.ID())
|
||||||
|
|
||||||
t.Run("binary", func(t *testing.T) {
|
t.Run("binary", func(t *testing.T) {
|
||||||
data, err := a.Marshal()
|
data, err := a.Marshal()
|
||||||
|
|
|
@ -93,7 +93,7 @@ func TestRawObject_SetPayloadSize(t *testing.T) {
|
||||||
func TestRawObject_SetContainerID(t *testing.T) {
|
func TestRawObject_SetContainerID(t *testing.T) {
|
||||||
obj := NewRaw()
|
obj := NewRaw()
|
||||||
|
|
||||||
cid := cidtest.GenerateID()
|
cid := cidtest.ID()
|
||||||
|
|
||||||
obj.SetContainerID(cid)
|
obj.SetContainerID(cid)
|
||||||
|
|
||||||
|
@ -103,7 +103,7 @@ func TestRawObject_SetContainerID(t *testing.T) {
|
||||||
func TestRawObject_SetOwnerID(t *testing.T) {
|
func TestRawObject_SetOwnerID(t *testing.T) {
|
||||||
obj := NewRaw()
|
obj := NewRaw()
|
||||||
|
|
||||||
ownerID := ownertest.GenerateID()
|
ownerID := ownertest.ID()
|
||||||
|
|
||||||
obj.SetOwnerID(ownerID)
|
obj.SetOwnerID(ownerID)
|
||||||
|
|
||||||
|
@ -196,7 +196,7 @@ func TestRawObject_SetParent(t *testing.T) {
|
||||||
|
|
||||||
par := NewRaw()
|
par := NewRaw()
|
||||||
par.SetID(randID(t))
|
par.SetID(randID(t))
|
||||||
par.SetContainerID(cidtest.GenerateID())
|
par.SetContainerID(cidtest.ID())
|
||||||
par.SetSignature(signature.New())
|
par.SetSignature(signature.New())
|
||||||
|
|
||||||
parObj := par.Object()
|
parObj := par.Object()
|
||||||
|
@ -218,7 +218,7 @@ func TestRawObject_ToV2(t *testing.T) {
|
||||||
func TestRawObject_SetSessionToken(t *testing.T) {
|
func TestRawObject_SetSessionToken(t *testing.T) {
|
||||||
obj := NewRaw()
|
obj := NewRaw()
|
||||||
|
|
||||||
tok := sessiontest.Generate()
|
tok := sessiontest.Token()
|
||||||
|
|
||||||
obj.SetSessionToken(tok)
|
obj.SetSessionToken(tok)
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,7 @@ func IDWithChecksum(cs [sha256.Size]byte) *object.ID {
|
||||||
func Address() *object.Address {
|
func Address() *object.Address {
|
||||||
x := object.NewAddress()
|
x := object.NewAddress()
|
||||||
|
|
||||||
x.SetContainerID(cidtest.GenerateID())
|
x.SetContainerID(cidtest.ID())
|
||||||
x.SetObjectID(ID())
|
x.SetObjectID(ID())
|
||||||
|
|
||||||
return x
|
return x
|
||||||
|
@ -75,10 +75,10 @@ func generateRaw(withParent bool) *object.RawObject {
|
||||||
x := object.NewRaw()
|
x := object.NewRaw()
|
||||||
|
|
||||||
x.SetID(ID())
|
x.SetID(ID())
|
||||||
x.SetSessionToken(sessiontest.Generate())
|
x.SetSessionToken(sessiontest.Token())
|
||||||
x.SetPayload([]byte{1, 2, 3})
|
x.SetPayload([]byte{1, 2, 3})
|
||||||
x.SetOwnerID(ownertest.GenerateID())
|
x.SetOwnerID(ownertest.ID())
|
||||||
x.SetContainerID(cidtest.GenerateID())
|
x.SetContainerID(cidtest.ID())
|
||||||
x.SetType(object.TypeTombstone)
|
x.SetType(object.TypeTombstone)
|
||||||
x.SetVersion(version.Current())
|
x.SetVersion(version.Current())
|
||||||
x.SetPayloadSize(111)
|
x.SetPayloadSize(111)
|
||||||
|
@ -136,7 +136,7 @@ func SearchFilters() object.SearchFilters {
|
||||||
x := object.NewSearchFilters()
|
x := object.NewSearchFilters()
|
||||||
|
|
||||||
x.AddObjectIDFilter(object.MatchStringEqual, ID())
|
x.AddObjectIDFilter(object.MatchStringEqual, ID())
|
||||||
x.AddObjectContainerIDFilter(object.MatchStringNotEqual, cidtest.GenerateID())
|
x.AddObjectContainerIDFilter(object.MatchStringNotEqual, cidtest.ID())
|
||||||
|
|
||||||
return x
|
return x
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestIDV2(t *testing.T) {
|
func TestIDV2(t *testing.T) {
|
||||||
id := ownertest.GenerateID()
|
id := ownertest.ID()
|
||||||
|
|
||||||
idV2 := id.ToV2()
|
idV2 := id.ToV2()
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ func TestIDV2(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestID_Valid(t *testing.T) {
|
func TestID_Valid(t *testing.T) {
|
||||||
id := ownertest.GenerateID()
|
id := ownertest.ID()
|
||||||
require.True(t, id.Valid())
|
require.True(t, id.Valid())
|
||||||
|
|
||||||
val := id.ToV2().GetValue()
|
val := id.ToV2().GetValue()
|
||||||
|
@ -32,13 +32,13 @@ func TestID_Valid(t *testing.T) {
|
||||||
copy(v, val)
|
copy(v, val)
|
||||||
v[0] ^= 0xFF
|
v[0] ^= 0xFF
|
||||||
|
|
||||||
id := ownertest.GenerateIDFromBytes(v)
|
id := ownertest.IDFromBytes(v)
|
||||||
require.False(t, id.Valid())
|
require.False(t, id.Valid())
|
||||||
})
|
})
|
||||||
t.Run("invalid size", func(t *testing.T) {
|
t.Run("invalid size", func(t *testing.T) {
|
||||||
val := val[:NEO3WalletSize-1]
|
val := val[:NEO3WalletSize-1]
|
||||||
|
|
||||||
id := ownertest.GenerateIDFromBytes(val)
|
id := ownertest.IDFromBytes(val)
|
||||||
require.False(t, id.Valid())
|
require.False(t, id.Valid())
|
||||||
})
|
})
|
||||||
t.Run("invalid checksum", func(t *testing.T) {
|
t.Run("invalid checksum", func(t *testing.T) {
|
||||||
|
@ -46,7 +46,7 @@ func TestID_Valid(t *testing.T) {
|
||||||
copy(v, val)
|
copy(v, val)
|
||||||
v[NEO3WalletSize-1] ^= 0xFF
|
v[NEO3WalletSize-1] ^= 0xFF
|
||||||
|
|
||||||
id := ownertest.GenerateIDFromBytes(v)
|
id := ownertest.IDFromBytes(v)
|
||||||
require.False(t, id.Valid())
|
require.False(t, id.Valid())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -87,7 +87,7 @@ func TestID_Parse(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestIDEncoding(t *testing.T) {
|
func TestIDEncoding(t *testing.T) {
|
||||||
id := ownertest.GenerateID()
|
id := ownertest.ID()
|
||||||
|
|
||||||
t.Run("binary", func(t *testing.T) {
|
t.Run("binary", func(t *testing.T) {
|
||||||
data, err := id.Marshal()
|
data, err := id.Marshal()
|
||||||
|
@ -117,14 +117,14 @@ func TestID_Equal(t *testing.T) {
|
||||||
data3 = append(data1, 255)
|
data3 = append(data1, 255)
|
||||||
)
|
)
|
||||||
|
|
||||||
id1 := ownertest.GenerateIDFromBytes(data1)
|
id1 := ownertest.IDFromBytes(data1)
|
||||||
|
|
||||||
require.True(t, id1.Equal(
|
require.True(t, id1.Equal(
|
||||||
ownertest.GenerateIDFromBytes(data2),
|
ownertest.IDFromBytes(data2),
|
||||||
))
|
))
|
||||||
|
|
||||||
require.False(t, id1.Equal(
|
require.False(t, id1.Equal(
|
||||||
ownertest.GenerateIDFromBytes(data3),
|
ownertest.IDFromBytes(data3),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,21 +8,21 @@ import (
|
||||||
"github.com/nspcc-dev/neofs-sdk-go/owner"
|
"github.com/nspcc-dev/neofs-sdk-go/owner"
|
||||||
)
|
)
|
||||||
|
|
||||||
// GenerateID returns owner.ID calculated
|
// ID returns owner.ID calculated
|
||||||
// from a random owner.NEO3Wallet.
|
// from a random owner.NEO3Wallet.
|
||||||
func GenerateID() *owner.ID {
|
func ID() *owner.ID {
|
||||||
u := make([]byte, owner.NEO3WalletSize)
|
u := make([]byte, owner.NEO3WalletSize)
|
||||||
u[0] = 0x35
|
u[0] = 0x35
|
||||||
rand.Read(u[1:21])
|
rand.Read(u[1:21])
|
||||||
h1 := sha256.Sum256(u[:21])
|
h1 := sha256.Sum256(u[:21])
|
||||||
h2 := sha256.Sum256(h1[:])
|
h2 := sha256.Sum256(h1[:])
|
||||||
copy(u[21:], h2[:4])
|
copy(u[21:], h2[:4])
|
||||||
return GenerateIDFromBytes(u)
|
return IDFromBytes(u)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GenerateIDFromBytes returns owner.ID generated
|
// IDFromBytes returns owner.ID generated
|
||||||
// from a passed byte slice.
|
// from a passed byte slice.
|
||||||
func GenerateIDFromBytes(val []byte) *owner.ID {
|
func IDFromBytes(val []byte) *owner.ID {
|
||||||
idV2 := new(refs.OwnerID)
|
idV2 := new(refs.OwnerID)
|
||||||
idV2.SetValue(val)
|
idV2.SetValue(val)
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ func TestPeerID_ToV2(t *testing.T) {
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("nil", func(t *testing.T) {
|
t.Run("nil", func(t *testing.T) {
|
||||||
peerID := reputationtest.GeneratePeerID()
|
peerID := reputationtest.PeerID()
|
||||||
|
|
||||||
require.Equal(t, peerID, reputation.PeerIDFromV2(peerID.ToV2()))
|
require.Equal(t, peerID, reputation.PeerIDFromV2(peerID.ToV2()))
|
||||||
})
|
})
|
||||||
|
@ -25,7 +25,7 @@ func TestPeerID_ToV2(t *testing.T) {
|
||||||
|
|
||||||
func TestPeerID_String(t *testing.T) {
|
func TestPeerID_String(t *testing.T) {
|
||||||
t.Run("Parse/String", func(t *testing.T) {
|
t.Run("Parse/String", func(t *testing.T) {
|
||||||
id := reputationtest.GeneratePeerID()
|
id := reputationtest.PeerID()
|
||||||
|
|
||||||
strID := id.String()
|
strID := id.String()
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@ func TestPeerID_String(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPeerIDEncoding(t *testing.T) {
|
func TestPeerIDEncoding(t *testing.T) {
|
||||||
id := reputationtest.GeneratePeerID()
|
id := reputationtest.PeerID()
|
||||||
|
|
||||||
t.Run("binary", func(t *testing.T) {
|
t.Run("binary", func(t *testing.T) {
|
||||||
data, err := id.Marshal()
|
data, err := id.Marshal()
|
||||||
|
|
|
@ -11,7 +11,7 @@ import (
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GeneratePeerID() *reputation.PeerID {
|
func PeerID() *reputation.PeerID {
|
||||||
v := reputation.NewPeerID()
|
v := reputation.NewPeerID()
|
||||||
|
|
||||||
p, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
|
p, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
|
||||||
|
@ -26,32 +26,32 @@ func GeneratePeerID() *reputation.PeerID {
|
||||||
return v
|
return v
|
||||||
}
|
}
|
||||||
|
|
||||||
func GenerateTrust() *reputation.Trust {
|
func Trust() *reputation.Trust {
|
||||||
v := reputation.NewTrust()
|
v := reputation.NewTrust()
|
||||||
v.SetPeer(GeneratePeerID())
|
v.SetPeer(PeerID())
|
||||||
v.SetValue(1.5)
|
v.SetValue(1.5)
|
||||||
|
|
||||||
return v
|
return v
|
||||||
}
|
}
|
||||||
|
|
||||||
func GeneratePeerToPeerTrust() *reputation.PeerToPeerTrust {
|
func PeerToPeerTrust() *reputation.PeerToPeerTrust {
|
||||||
v := reputation.NewPeerToPeerTrust()
|
v := reputation.NewPeerToPeerTrust()
|
||||||
v.SetTrustingPeer(GeneratePeerID())
|
v.SetTrustingPeer(PeerID())
|
||||||
v.SetTrust(GenerateTrust())
|
v.SetTrust(Trust())
|
||||||
|
|
||||||
return v
|
return v
|
||||||
}
|
}
|
||||||
|
|
||||||
func GenerateGlobalTrust() *reputation.GlobalTrust {
|
func GlobalTrust() *reputation.GlobalTrust {
|
||||||
v := reputation.NewGlobalTrust()
|
v := reputation.NewGlobalTrust()
|
||||||
v.SetManager(GeneratePeerID())
|
v.SetManager(PeerID())
|
||||||
v.SetTrust(GenerateTrust())
|
v.SetTrust(Trust())
|
||||||
|
|
||||||
return v
|
return v
|
||||||
}
|
}
|
||||||
|
|
||||||
func GenerateSignedGlobalTrust(t testing.TB) *reputation.GlobalTrust {
|
func SignedGlobalTrust(t testing.TB) *reputation.GlobalTrust {
|
||||||
gt := GenerateGlobalTrust()
|
gt := GlobalTrust()
|
||||||
|
|
||||||
p, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
|
p, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
|
@ -14,7 +14,7 @@ import (
|
||||||
func TestTrust(t *testing.T) {
|
func TestTrust(t *testing.T) {
|
||||||
trust := reputation.NewTrust()
|
trust := reputation.NewTrust()
|
||||||
|
|
||||||
id := reputationtest.GeneratePeerID()
|
id := reputationtest.PeerID()
|
||||||
trust.SetPeer(id)
|
trust.SetPeer(id)
|
||||||
require.Equal(t, id, trust.Peer())
|
require.Equal(t, id, trust.Peer())
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ func TestTrust(t *testing.T) {
|
||||||
require.Equal(t, val, trust.Value())
|
require.Equal(t, val, trust.Value())
|
||||||
|
|
||||||
t.Run("binary encoding", func(t *testing.T) {
|
t.Run("binary encoding", func(t *testing.T) {
|
||||||
trust := reputationtest.GenerateTrust()
|
trust := reputationtest.Trust()
|
||||||
data, err := trust.Marshal()
|
data, err := trust.Marshal()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ func TestTrust(t *testing.T) {
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("JSON encoding", func(t *testing.T) {
|
t.Run("JSON encoding", func(t *testing.T) {
|
||||||
trust := reputationtest.GenerateTrust()
|
trust := reputationtest.Trust()
|
||||||
data, err := trust.MarshalJSON()
|
data, err := trust.MarshalJSON()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
@ -58,17 +58,17 @@ func TestPeerToPeerTrust(t *testing.T) {
|
||||||
require.Nil(t, p2pt.TrustingPeer())
|
require.Nil(t, p2pt.TrustingPeer())
|
||||||
require.Nil(t, p2pt.Trust())
|
require.Nil(t, p2pt.Trust())
|
||||||
|
|
||||||
trusting := reputationtest.GeneratePeerID()
|
trusting := reputationtest.PeerID()
|
||||||
p2pt.SetTrustingPeer(trusting)
|
p2pt.SetTrustingPeer(trusting)
|
||||||
require.Equal(t, trusting, p2pt.TrustingPeer())
|
require.Equal(t, trusting, p2pt.TrustingPeer())
|
||||||
|
|
||||||
trust := reputationtest.GenerateTrust()
|
trust := reputationtest.Trust()
|
||||||
p2pt.SetTrust(trust)
|
p2pt.SetTrust(trust)
|
||||||
require.Equal(t, trust, p2pt.Trust())
|
require.Equal(t, trust, p2pt.Trust())
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("encoding", func(t *testing.T) {
|
t.Run("encoding", func(t *testing.T) {
|
||||||
p2pt := reputationtest.GeneratePeerToPeerTrust()
|
p2pt := reputationtest.PeerToPeerTrust()
|
||||||
|
|
||||||
t.Run("binary", func(t *testing.T) {
|
t.Run("binary", func(t *testing.T) {
|
||||||
data, err := p2pt.Marshal()
|
data, err := p2pt.Marshal()
|
||||||
|
@ -112,17 +112,17 @@ func TestGlobalTrust(t *testing.T) {
|
||||||
gt.SetVersion(version)
|
gt.SetVersion(version)
|
||||||
require.Equal(t, version, gt.Version())
|
require.Equal(t, version, gt.Version())
|
||||||
|
|
||||||
mngr := reputationtest.GeneratePeerID()
|
mngr := reputationtest.PeerID()
|
||||||
gt.SetManager(mngr)
|
gt.SetManager(mngr)
|
||||||
require.Equal(t, mngr, gt.Manager())
|
require.Equal(t, mngr, gt.Manager())
|
||||||
|
|
||||||
trust := reputationtest.GenerateTrust()
|
trust := reputationtest.Trust()
|
||||||
gt.SetTrust(trust)
|
gt.SetTrust(trust)
|
||||||
require.Equal(t, trust, gt.Trust())
|
require.Equal(t, trust, gt.Trust())
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("sign+verify", func(t *testing.T) {
|
t.Run("sign+verify", func(t *testing.T) {
|
||||||
gt := reputationtest.GenerateSignedGlobalTrust(t)
|
gt := reputationtest.SignedGlobalTrust(t)
|
||||||
|
|
||||||
err := gt.VerifySignature()
|
err := gt.VerifySignature()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
@ -130,7 +130,7 @@ func TestGlobalTrust(t *testing.T) {
|
||||||
|
|
||||||
t.Run("encoding", func(t *testing.T) {
|
t.Run("encoding", func(t *testing.T) {
|
||||||
t.Run("binary", func(t *testing.T) {
|
t.Run("binary", func(t *testing.T) {
|
||||||
gt := reputationtest.GenerateSignedGlobalTrust(t)
|
gt := reputationtest.SignedGlobalTrust(t)
|
||||||
|
|
||||||
data, err := gt.Marshal()
|
data, err := gt.Marshal()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
@ -141,7 +141,7 @@ func TestGlobalTrust(t *testing.T) {
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("JSON", func(t *testing.T) {
|
t.Run("JSON", func(t *testing.T) {
|
||||||
gt := reputationtest.GenerateSignedGlobalTrust(t)
|
gt := reputationtest.SignedGlobalTrust(t)
|
||||||
data, err := gt.MarshalJSON()
|
data, err := gt.MarshalJSON()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,7 @@ func TestContainerContextVerbs(t *testing.T) {
|
||||||
|
|
||||||
func TestContainerContext_ApplyTo(t *testing.T) {
|
func TestContainerContext_ApplyTo(t *testing.T) {
|
||||||
c := session.NewContainerContext()
|
c := session.NewContainerContext()
|
||||||
id := cidtest.GenerateID()
|
id := cidtest.ID()
|
||||||
|
|
||||||
t.Run("method", func(t *testing.T) {
|
t.Run("method", func(t *testing.T) {
|
||||||
c.ApplyTo(id)
|
c.ApplyTo(id)
|
||||||
|
|
|
@ -22,7 +22,7 @@ func TestSessionToken_SetID(t *testing.T) {
|
||||||
func TestSessionToken_SetOwnerID(t *testing.T) {
|
func TestSessionToken_SetOwnerID(t *testing.T) {
|
||||||
token := session.NewToken()
|
token := session.NewToken()
|
||||||
|
|
||||||
ownerID := ownertest.GenerateID()
|
ownerID := ownertest.ID()
|
||||||
|
|
||||||
token.SetOwnerID(ownerID)
|
token.SetOwnerID(ownerID)
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ func TestSessionToken_SetSessionKey(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSessionTokenEncoding(t *testing.T) {
|
func TestSessionTokenEncoding(t *testing.T) {
|
||||||
tok := sessiontest.Generate()
|
tok := sessiontest.Token()
|
||||||
|
|
||||||
t.Run("binary", func(t *testing.T) {
|
t.Run("binary", func(t *testing.T) {
|
||||||
data, err := tok.Marshal()
|
data, err := tok.Marshal()
|
||||||
|
@ -70,13 +70,13 @@ func TestToken_VerifySignature(t *testing.T) {
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("unsigned", func(t *testing.T) {
|
t.Run("unsigned", func(t *testing.T) {
|
||||||
tok := sessiontest.Generate()
|
tok := sessiontest.Token()
|
||||||
|
|
||||||
require.False(t, tok.VerifySignature())
|
require.False(t, tok.VerifySignature())
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("signed", func(t *testing.T) {
|
t.Run("signed", func(t *testing.T) {
|
||||||
tok := sessiontest.GenerateSigned()
|
tok := sessiontest.SignedToken()
|
||||||
|
|
||||||
require.True(t, tok.VerifySignature())
|
require.True(t, tok.VerifySignature())
|
||||||
})
|
})
|
||||||
|
|
|
@ -20,7 +20,7 @@ func ContainerContext() *session.ContainerContext {
|
||||||
|
|
||||||
setters[rand.Uint32()%uint32(len(setters))]()
|
setters[rand.Uint32()%uint32(len(setters))]()
|
||||||
|
|
||||||
c.ApplyTo(cidtest.GenerateID())
|
c.ApplyTo(cidtest.ID())
|
||||||
|
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,10 +22,10 @@ func init() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate returns random session.Token.
|
// Token returns random session.Token.
|
||||||
//
|
//
|
||||||
// Resulting token is unsigned.
|
// Resulting token is unsigned.
|
||||||
func Generate() *session.Token {
|
func Token() *session.Token {
|
||||||
tok := session.NewToken()
|
tok := session.NewToken()
|
||||||
|
|
||||||
uid, err := uuid.New().MarshalBinary()
|
uid, err := uuid.New().MarshalBinary()
|
||||||
|
@ -51,11 +51,11 @@ func Generate() *session.Token {
|
||||||
return tok
|
return tok
|
||||||
}
|
}
|
||||||
|
|
||||||
// GenerateSigned returns signed random session.Token.
|
// SignedToken returns signed random session.Token.
|
||||||
//
|
//
|
||||||
// Panics if token could not be signed (actually unexpected).
|
// Panics if token could not be signed (actually unexpected).
|
||||||
func GenerateSigned() *session.Token {
|
func SignedToken() *session.Token {
|
||||||
tok := Generate()
|
tok := Token()
|
||||||
|
|
||||||
err := tok.Sign(p)
|
err := tok.Sign(p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package test
|
package sigtest
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/nspcc-dev/neofs-sdk-go/signature"
|
"github.com/nspcc-dev/neofs-sdk-go/signature"
|
||||||
|
|
|
@ -33,7 +33,7 @@ func TestStorageGroup(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestStorageGroupEncoding(t *testing.T) {
|
func TestStorageGroupEncoding(t *testing.T) {
|
||||||
sg := storagegrouptest.Generate()
|
sg := storagegrouptest.StorageGroup()
|
||||||
|
|
||||||
t.Run("binary", func(t *testing.T) {
|
t.Run("binary", func(t *testing.T) {
|
||||||
data, err := sg.Marshal()
|
data, err := sg.Marshal()
|
||||||
|
|
|
@ -7,8 +7,8 @@ import (
|
||||||
"github.com/nspcc-dev/neofs-sdk-go/storagegroup"
|
"github.com/nspcc-dev/neofs-sdk-go/storagegroup"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Generate returns random storagegroup.StorageGroup.
|
// StorageGroup returns random storagegroup.StorageGroup.
|
||||||
func Generate() *storagegroup.StorageGroup {
|
func StorageGroup() *storagegroup.StorageGroup {
|
||||||
x := storagegroup.New()
|
x := storagegroup.New()
|
||||||
|
|
||||||
x.SetExpirationEpoch(66)
|
x.SetExpirationEpoch(66)
|
||||||
|
|
|
@ -70,7 +70,7 @@ func TestID_Equals(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSubnetIDEncoding(t *testing.T) {
|
func TestSubnetIDEncoding(t *testing.T) {
|
||||||
id := subnetidtest.GenerateID()
|
id := subnetidtest.ID()
|
||||||
|
|
||||||
t.Run("binary", func(t *testing.T) {
|
t.Run("binary", func(t *testing.T) {
|
||||||
data, err := id.Marshal()
|
data, err := id.Marshal()
|
||||||
|
|
|
@ -6,8 +6,8 @@ import (
|
||||||
subnetid "github.com/nspcc-dev/neofs-sdk-go/subnet/id"
|
subnetid "github.com/nspcc-dev/neofs-sdk-go/subnet/id"
|
||||||
)
|
)
|
||||||
|
|
||||||
// GenerateID generates and returns random subnetid.ID using math/rand.Uint32.
|
// ID generates and returns random subnetid.ID using math/rand.Uint32.
|
||||||
func GenerateID() *subnetid.ID {
|
func ID() *subnetid.ID {
|
||||||
var id subnetid.ID
|
var id subnetid.ID
|
||||||
|
|
||||||
id.SetNumber(rand.Uint32())
|
id.SetNumber(rand.Uint32())
|
||||||
|
|
|
@ -40,7 +40,7 @@ func TestInfo_SetOwner(t *testing.T) {
|
||||||
info Info
|
info Info
|
||||||
)
|
)
|
||||||
|
|
||||||
id = *ownertest.GenerateID()
|
id = *ownertest.ID()
|
||||||
|
|
||||||
require.False(t, IsOwner(info, id))
|
require.False(t, IsOwner(info, id))
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,7 @@ func TestBearerToken_Issuer(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFilterEncoding(t *testing.T) {
|
func TestFilterEncoding(t *testing.T) {
|
||||||
f := tokentest.Generate()
|
f := tokentest.BearerToken()
|
||||||
|
|
||||||
t.Run("binary", func(t *testing.T) {
|
t.Run("binary", func(t *testing.T) {
|
||||||
data, err := f.Marshal()
|
data, err := f.Marshal()
|
||||||
|
|
|
@ -10,24 +10,24 @@ import (
|
||||||
"github.com/nspcc-dev/neofs-sdk-go/token"
|
"github.com/nspcc-dev/neofs-sdk-go/token"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Generate returns random token.BearerToken.
|
// BearerToken returns random token.BearerToken.
|
||||||
//
|
//
|
||||||
// Resulting token is unsigned.
|
// Resulting token is unsigned.
|
||||||
func Generate() *token.BearerToken {
|
func BearerToken() *token.BearerToken {
|
||||||
x := token.NewBearerToken()
|
x := token.NewBearerToken()
|
||||||
|
|
||||||
x.SetLifetime(3, 2, 1)
|
x.SetLifetime(3, 2, 1)
|
||||||
x.SetOwner(ownertest.GenerateID())
|
x.SetOwner(ownertest.ID())
|
||||||
x.SetEACLTable(eacltest.Table())
|
x.SetEACLTable(eacltest.Table())
|
||||||
|
|
||||||
return x
|
return x
|
||||||
}
|
}
|
||||||
|
|
||||||
// GenerateSigned returns signed random token.BearerToken.
|
// SignedBearerToken returns signed random token.BearerToken.
|
||||||
//
|
//
|
||||||
// Panics if token could not be signed (actually unexpected).
|
// Panics if token could not be signed (actually unexpected).
|
||||||
func GenerateSigned() *token.BearerToken {
|
func SignedBearerToken() *token.BearerToken {
|
||||||
tok := Generate()
|
tok := BearerToken()
|
||||||
|
|
||||||
p, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
|
p, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package test
|
package versiontest
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"math/rand"
|
"math/rand"
|
||||||
|
|
Loading…
Reference in a new issue