[#106] test: Generate correct data for tests
All checks were successful
DCO action / DCO (pull_request) Successful in 1m1s
Tests and linters / Tests (1.22) (pull_request) Successful in 59s
Tests and linters / Tests (1.23) (pull_request) Successful in 58s
Tests and linters / Tests with -race (pull_request) Successful in 1m14s
Tests and linters / Lint (pull_request) Successful in 1m21s

Signed-off-by: Aleksey Savchuk <a.savchuk@yadro.com>
This commit is contained in:
Aleksey Savchuk 2024-08-26 14:13:20 +03:00
parent 33653962b7
commit 7fd808b317
No known key found for this signature in database
5 changed files with 68 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

@ -4,6 +4,8 @@ import (
"math/rand"
"time"
crand "crypto/rand"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/object"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs"
refstest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs/test"
@ -59,7 +61,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 +96,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 +158,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 +638,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

@ -4,6 +4,8 @@ import (
"math/rand"
"time"
crand "crypto/rand"
acltest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/acl/test"
refstest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs/test"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/session"
@ -38,7 +40,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 +169,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))
}