forked from TrueCloudLab/frostfs-api-go
[#401] internal: Place randomization code in random package
Also replace seeding into `init` function. Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
02e962f727
commit
c82dcf7e16
4 changed files with 22 additions and 19 deletions
|
@ -1,12 +0,0 @@
|
||||||
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
|
|
||||||
}
|
|
15
internal/random/rand.go
Normal file
15
internal/random/rand.go
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
package random
|
||||||
|
|
||||||
|
import (
|
||||||
|
"math/rand"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
rand.Seed(time.Now().UnixNano())
|
||||||
|
}
|
||||||
|
|
||||||
|
// Uint32 returns random uint32 value [0, max).
|
||||||
|
func Uint32(max uint32) uint32 {
|
||||||
|
return rand.Uint32() % max
|
||||||
|
}
|
|
@ -1,7 +1,7 @@
|
||||||
package objecttest
|
package objecttest
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/nspcc-dev/neofs-api-go/v2/internal"
|
"github.com/nspcc-dev/neofs-api-go/v2/internal/random"
|
||||||
"github.com/nspcc-dev/neofs-api-go/v2/object"
|
"github.com/nspcc-dev/neofs-api-go/v2/object"
|
||||||
"github.com/nspcc-dev/neofs-api-go/v2/refs"
|
"github.com/nspcc-dev/neofs-api-go/v2/refs"
|
||||||
refstest "github.com/nspcc-dev/neofs-api-go/v2/refs/test"
|
refstest "github.com/nspcc-dev/neofs-api-go/v2/refs/test"
|
||||||
|
@ -186,7 +186,7 @@ func GenerateGetResponseBody(empty bool) *object.GetResponseBody {
|
||||||
m := new(object.GetResponseBody)
|
m := new(object.GetResponseBody)
|
||||||
|
|
||||||
if !empty {
|
if !empty {
|
||||||
switch internal.RandUint32(3) {
|
switch random.Uint32(3) {
|
||||||
case 0:
|
case 0:
|
||||||
m.SetObjectPart(GenerateGetObjectPartInit(false))
|
m.SetObjectPart(GenerateGetObjectPartInit(false))
|
||||||
case 1:
|
case 1:
|
||||||
|
@ -240,7 +240,7 @@ func GeneratePutRequestBody(empty bool) *object.PutRequestBody {
|
||||||
m := new(object.PutRequestBody)
|
m := new(object.PutRequestBody)
|
||||||
|
|
||||||
if !empty {
|
if !empty {
|
||||||
switch internal.RandUint32(2) {
|
switch random.Uint32(2) {
|
||||||
case 0:
|
case 0:
|
||||||
m.SetObjectPart(GeneratePutObjectPartInit(false))
|
m.SetObjectPart(GeneratePutObjectPartInit(false))
|
||||||
case 1:
|
case 1:
|
||||||
|
@ -362,7 +362,7 @@ func GenerateHeadResponseBody(empty bool) *object.HeadResponseBody {
|
||||||
m := new(object.HeadResponseBody)
|
m := new(object.HeadResponseBody)
|
||||||
|
|
||||||
if !empty {
|
if !empty {
|
||||||
switch internal.RandUint32(3) {
|
switch random.Uint32(3) {
|
||||||
case 0:
|
case 0:
|
||||||
m.SetHeaderPart(GenerateHeaderWithSignature(false))
|
m.SetHeaderPart(GenerateHeaderWithSignature(false))
|
||||||
case 1:
|
case 1:
|
||||||
|
@ -524,7 +524,7 @@ func GenerateGetRangeResponseBody(empty bool) *object.GetRangeResponseBody {
|
||||||
m := new(object.GetRangeResponseBody)
|
m := new(object.GetRangeResponseBody)
|
||||||
|
|
||||||
if !empty {
|
if !empty {
|
||||||
switch internal.RandUint32(2) {
|
switch random.Uint32(2) {
|
||||||
case 0:
|
case 0:
|
||||||
m.SetRangePart(GenerateGetRangePartChunk(false))
|
m.SetRangePart(GenerateGetRangePartChunk(false))
|
||||||
case 1:
|
case 1:
|
||||||
|
|
|
@ -2,7 +2,7 @@ package sessiontest
|
||||||
|
|
||||||
import (
|
import (
|
||||||
acltest "github.com/nspcc-dev/neofs-api-go/v2/acl/test"
|
acltest "github.com/nspcc-dev/neofs-api-go/v2/acl/test"
|
||||||
"github.com/nspcc-dev/neofs-api-go/v2/internal"
|
"github.com/nspcc-dev/neofs-api-go/v2/internal/random"
|
||||||
refstest "github.com/nspcc-dev/neofs-api-go/v2/refs/test"
|
refstest "github.com/nspcc-dev/neofs-api-go/v2/refs/test"
|
||||||
"github.com/nspcc-dev/neofs-api-go/v2/session"
|
"github.com/nspcc-dev/neofs-api-go/v2/session"
|
||||||
statustest "github.com/nspcc-dev/neofs-api-go/v2/status/test"
|
statustest "github.com/nspcc-dev/neofs-api-go/v2/status/test"
|
||||||
|
@ -167,7 +167,7 @@ func GenerateSessionTokenBody(empty bool) *session.TokenBody {
|
||||||
m.SetOwnerID(refstest.GenerateOwnerID(false))
|
m.SetOwnerID(refstest.GenerateOwnerID(false))
|
||||||
m.SetLifetime(GenerateTokenLifetime(false))
|
m.SetLifetime(GenerateTokenLifetime(false))
|
||||||
|
|
||||||
switch internal.RandUint32(2) {
|
switch random.Uint32(2) {
|
||||||
case 0:
|
case 0:
|
||||||
m.SetContext(GenerateObjectSessionContext(false))
|
m.SetContext(GenerateObjectSessionContext(false))
|
||||||
case 1:
|
case 1:
|
||||||
|
|
Loading…
Reference in a new issue