test: Generate correct IDs for tests #106

Merged
fyrchik merged 1 commit from a-savchuk/frostfs-api-go:test/generate-ids into master 2024-08-30 10:55:06 +00:00
5 changed files with 66 additions and 17 deletions

View file

@ -1,6 +1,8 @@
package containertest
import (
"crypto/rand"
acltest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/acl/test"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/container"
netmaptest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/netmap/test"
@ -36,8 +38,11 @@ func GenerateContainer(empty bool) *container.Container {
m := new(container.Container)
if !empty {
nonce := make([]byte, 16)
_, _ = rand.Read(nonce)
m.SetBasicACL(12)
m.SetNonce([]byte{1, 2, 3})
m.SetNonce(nonce)
m.SetOwnerID(refstest.GenerateOwnerID(false))
m.SetAttributes(GenerateAttributes(false))
m.SetPlacementPolicy(netmaptest.GeneratePlacementPolicy(false))

View file

@ -1,6 +1,7 @@
package objecttest
import (
crand "crypto/rand"
"math/rand"
"time"
@ -59,7 +60,10 @@ func generateSplitHeader(empty, withPar bool) *object.SplitHeader {
m := new(object.SplitHeader)
if !empty {
m.SetSplitID([]byte{1, 3, 5})
id := make([]byte, 16)
_, _ = crand.Read(id)
m.SetSplitID(id)
m.SetParent(refstest.GenerateObjectID(false))
m.SetPrevious(refstest.GenerateObjectID(false))
m.SetChildren(refstest.GenerateObjectIDs(false))
@ -91,7 +95,10 @@ func GenerateECHeader(empty bool) *object.ECHeader {
if !empty {
ech.Parent = refstest.GenerateObjectID(empty)
ech.ParentSplitID = []byte{1, 2, 3}
ech.ParentSplitID = make([]byte, 16)
_, _ = crand.Read(ech.ParentSplitID)
ech.ParentSplitParentID = refstest.GenerateObjectID(empty)
ech.ParentAttributes = GenerateAttributes(empty)
ech.Index = 0
@ -150,7 +157,10 @@ func GenerateSplitInfo(empty bool) *object.SplitInfo {
m := new(object.SplitInfo)
if !empty {
m.SetSplitID([]byte("splitID"))
id := make([]byte, 16)
_, _ = crand.Read(id)
m.SetSplitID(id)
m.SetLastPart(refstest.GenerateObjectID(false))
m.SetLink(refstest.GenerateObjectID(false))
}
@ -627,7 +637,10 @@ func GenerateGetRangeHashResponseBody(empty bool) *object.GetRangeHashResponseBo
if !empty {
m.SetType(678)
m.SetHashList([][]byte{{1}, {2}})
m.SetHashList([][]byte{
refstest.GenerateChecksum(false).GetSum(),
refstest.GenerateChecksum(false).GetSum(),
})
}
return m

View file

@ -1,7 +1,8 @@
package refstest
import (
"math/rand"
crand "crypto/rand"
"crypto/sha256"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs"
)
@ -21,7 +22,10 @@ func GenerateOwnerID(empty bool) *refs.OwnerID {
m := new(refs.OwnerID)
if !empty {
m.SetValue([]byte{1, 2, 3})
id := make([]byte, 25)
_, _ = crand.Read(id)
m.SetValue(id)
}
return m
@ -42,7 +46,10 @@ func GenerateObjectID(empty bool) *refs.ObjectID {
m := new(refs.ObjectID)
if !empty {
m.SetValue([]byte{1, 2, 3})
id := make([]byte, sha256.Size)
_, _ = crand.Read(id)
m.SetValue(id)
}
return m
@ -65,7 +72,10 @@ func GenerateContainerID(empty bool) *refs.ContainerID {
m := new(refs.ContainerID)
if !empty {
m.SetValue([]byte{1, 2, 3})
id := make([]byte, sha256.Size)
_, _ = crand.Read(id)
m.SetValue(id)
}
return m
@ -88,9 +98,15 @@ func GenerateSignature(empty bool) *refs.Signature {
m := new(refs.Signature)
if !empty {
m.SetKey([]byte{1})
m.SetSign([]byte{2})
m.SetScheme(refs.SignatureScheme(rand.Int31() % 3))
key := make([]byte, 33)
_, _ = crand.Read(key)
sign := make([]byte, 65)
_, _ = crand.Read(sign)
m.SetScheme(refs.ECDSA_SHA512)
m.SetKey(key)
m.SetSign(sign)
}
return m
@ -100,8 +116,11 @@ func GenerateChecksum(empty bool) *refs.Checksum {
m := new(refs.Checksum)
if !empty {
m.SetType(1)
m.SetSum([]byte{1, 2, 3})
cs := make([]byte, sha256.Size)
_, _ = crand.Read(cs)
m.SetType(refs.SHA256)
m.SetSum(cs)
}
return m

View file

@ -1,6 +1,7 @@
package sessiontest
import (
crand "crypto/rand"
"math/rand"
"time"
@ -38,7 +39,10 @@ func GenerateCreateResponseBody(empty bool) *session.CreateResponseBody {
m := new(session.CreateResponseBody)
if !empty {
m.SetID([]byte{1, 2, 3})
id := make([]byte, 16)
_, _ = crand.Read(id)
m.SetID(id)
m.SetSessionKey([]byte{4, 5, 6})
}
@ -164,7 +168,10 @@ func GenerateSessionTokenBody(empty bool) *session.TokenBody {
m := new(session.TokenBody)
if !empty {
m.SetID([]byte{1})
id := make([]byte, 16)
_, _ = crand.Read(id)
m.SetID(id)
m.SetSessionKey([]byte{2})
m.SetOwnerID(refstest.GenerateOwnerID(false))
m.SetLifetime(GenerateTokenLifetime(false))

View file

@ -1,6 +1,8 @@
package tombstonetest
import (
"crypto/rand"
refstest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs/test"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/tombstone"
)
@ -9,8 +11,11 @@ func GenerateTombstone(empty bool) *tombstone.Tombstone {
m := new(tombstone.Tombstone)
if !empty {
id := make([]byte, 16)
_, _ = rand.Read(id)
m.SetExpirationEpoch(89)
m.SetSplitID([]byte{3, 2, 1})
m.SetSplitID(id)
m.SetMembers(refstest.GenerateObjectIDs(false))
}