diff options
author | Alexey Sharov <www.pismeco@gmail.com> | 2018-11-14 16:21:14 +0800 |
---|---|---|
committer | Viktor TrĂ³n <viktor.tron@gmail.com> | 2018-11-14 16:21:14 +0800 |
commit | eb8fa3cc89ae3a3247c649486839b1c250554d2d (patch) | |
tree | c61b8ebebc739db0e5413cd214fdd0d3da2fe61e /swarm/testutil/file.go | |
parent | cff97119a713a6f790893aaf1c172a397a48bf33 (diff) | |
download | go-tangerine-eb8fa3cc89ae3a3247c649486839b1c250554d2d.tar go-tangerine-eb8fa3cc89ae3a3247c649486839b1c250554d2d.tar.gz go-tangerine-eb8fa3cc89ae3a3247c649486839b1c250554d2d.tar.bz2 go-tangerine-eb8fa3cc89ae3a3247c649486839b1c250554d2d.tar.lz go-tangerine-eb8fa3cc89ae3a3247c649486839b1c250554d2d.tar.xz go-tangerine-eb8fa3cc89ae3a3247c649486839b1c250554d2d.tar.zst go-tangerine-eb8fa3cc89ae3a3247c649486839b1c250554d2d.zip |
cmd/swarm, swarm/api/http, swarm/bmt, swarm/fuse, swarm/network/stream, swarm/storage, swarm/storage/encryption, swarm/testutil: use pseudo-random instead of crypto-random for test files content generation (#18083)
- Replace "crypto/rand" to "math/rand" for files content generation
- Remove swarm/network_test.go.Shuffle and swarm/btm/btm_test.go.Shuffle - because go1.9 support dropped (see https://github.com/ethereum/go-ethereum/pull/17807 and comments to swarm/network_test.go.Shuffle)
Diffstat (limited to 'swarm/testutil/file.go')
-rw-r--r-- | swarm/testutil/file.go | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/swarm/testutil/file.go b/swarm/testutil/file.go index ecb0d971e..70732aa92 100644 --- a/swarm/testutil/file.go +++ b/swarm/testutil/file.go @@ -17,8 +17,10 @@ package testutil import ( + "bytes" "io" "io/ioutil" + "math/rand" "os" "strings" "testing" @@ -42,3 +44,22 @@ func TempFileWithContent(t *testing.T, content string) string { } return tempFile.Name() } + +// RandomBytes returns pseudo-random deterministic result +// because test fails must be reproducible +func RandomBytes(seed, length int) []byte { + b := make([]byte, length) + reader := rand.New(rand.NewSource(int64(seed))) + for n := 0; n < length; { + read, err := reader.Read(b[n:]) + if err != nil { + panic(err) + } + n += read + } + return b +} + +func RandomReader(seed, length int) *bytes.Reader { + return bytes.NewReader(RandomBytes(seed, length)) +} |