aboutsummaryrefslogtreecommitdiffstats
path: root/swarm/testutil/file.go
diff options
context:
space:
mode:
Diffstat (limited to 'swarm/testutil/file.go')
-rw-r--r--swarm/testutil/file.go21
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))
+}