[#401] test: Randomize value for oneof
field
Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
0b8e4e4753
commit
d35e935a9d
3 changed files with 49 additions and 5 deletions
12
internal/rand.go
Normal file
12
internal/rand.go
Normal file
|
@ -0,0 +1,12 @@
|
|||
package internal
|
||||
|
||||
import (
|
||||
"math/rand"
|
||||
"time"
|
||||
)
|
||||
|
||||
// RandUint32 returns random uint32 value [0, max).
|
||||
func RandUint32(max uint32) uint32 {
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
return rand.Uint32() % max
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
package objecttest
|
||||
|
||||
import (
|
||||
"github.com/nspcc-dev/neofs-api-go/v2/internal"
|
||||
"github.com/nspcc-dev/neofs-api-go/v2/object"
|
||||
"github.com/nspcc-dev/neofs-api-go/v2/refs"
|
||||
refstest "github.com/nspcc-dev/neofs-api-go/v2/refs/test"
|
||||
|
@ -185,7 +186,14 @@ func GenerateGetResponseBody(empty bool) *object.GetResponseBody {
|
|||
m := new(object.GetResponseBody)
|
||||
|
||||
if !empty {
|
||||
m.SetObjectPart(GenerateGetObjectPartInit(false))
|
||||
switch internal.RandUint32(3) {
|
||||
case 0:
|
||||
m.SetObjectPart(GenerateGetObjectPartInit(false))
|
||||
case 1:
|
||||
m.SetObjectPart(GenerateGetObjectPartChunk(false))
|
||||
case 2:
|
||||
m.SetObjectPart(GenerateSplitInfo(false))
|
||||
}
|
||||
}
|
||||
|
||||
return m
|
||||
|
@ -232,7 +240,12 @@ func GeneratePutRequestBody(empty bool) *object.PutRequestBody {
|
|||
m := new(object.PutRequestBody)
|
||||
|
||||
if !empty {
|
||||
m.SetObjectPart(GeneratePutObjectPartInit(false))
|
||||
switch internal.RandUint32(2) {
|
||||
case 0:
|
||||
m.SetObjectPart(GeneratePutObjectPartInit(false))
|
||||
case 1:
|
||||
m.SetObjectPart(GeneratePutObjectPartChunk(false))
|
||||
}
|
||||
}
|
||||
|
||||
return m
|
||||
|
@ -349,7 +362,14 @@ func GenerateHeadResponseBody(empty bool) *object.HeadResponseBody {
|
|||
m := new(object.HeadResponseBody)
|
||||
|
||||
if !empty {
|
||||
m.SetHeaderPart(GenerateHeaderWithSignature(false))
|
||||
switch internal.RandUint32(3) {
|
||||
case 0:
|
||||
m.SetHeaderPart(GenerateHeaderWithSignature(false))
|
||||
case 1:
|
||||
m.SetHeaderPart(GenerateShortHeader(false))
|
||||
case 2:
|
||||
m.SetHeaderPart(GenerateSplitInfo(false))
|
||||
}
|
||||
}
|
||||
|
||||
return m
|
||||
|
@ -504,7 +524,12 @@ func GenerateGetRangeResponseBody(empty bool) *object.GetRangeResponseBody {
|
|||
m := new(object.GetRangeResponseBody)
|
||||
|
||||
if !empty {
|
||||
m.SetRangePart(GenerateGetRangePartChunk(false))
|
||||
switch internal.RandUint32(2) {
|
||||
case 0:
|
||||
m.SetRangePart(GenerateGetRangePartChunk(false))
|
||||
case 1:
|
||||
m.SetRangePart(GenerateSplitInfo(false))
|
||||
}
|
||||
}
|
||||
|
||||
return m
|
||||
|
|
|
@ -2,6 +2,7 @@ package sessiontest
|
|||
|
||||
import (
|
||||
acltest "github.com/nspcc-dev/neofs-api-go/v2/acl/test"
|
||||
"github.com/nspcc-dev/neofs-api-go/v2/internal"
|
||||
refstest "github.com/nspcc-dev/neofs-api-go/v2/refs/test"
|
||||
"github.com/nspcc-dev/neofs-api-go/v2/session"
|
||||
statustest "github.com/nspcc-dev/neofs-api-go/v2/status/test"
|
||||
|
@ -165,7 +166,13 @@ func GenerateSessionTokenBody(empty bool) *session.TokenBody {
|
|||
m.SetSessionKey([]byte{2})
|
||||
m.SetOwnerID(refstest.GenerateOwnerID(false))
|
||||
m.SetLifetime(GenerateTokenLifetime(false))
|
||||
m.SetContext(GenerateObjectSessionContext(false))
|
||||
|
||||
switch internal.RandUint32(2) {
|
||||
case 0:
|
||||
m.SetContext(GenerateObjectSessionContext(false))
|
||||
case 1:
|
||||
m.SetContext(GenerateContainerSessionContext(false))
|
||||
}
|
||||
}
|
||||
|
||||
return m
|
||||
|
|
Loading…
Reference in a new issue