aboutsummaryrefslogtreecommitdiffstats
path: root/swarm/fuse
diff options
context:
space:
mode:
authorAlexey Sharov <www.pismeco@gmail.com>2018-11-14 16:21:14 +0800
committerViktor TrĂ³n <viktor.tron@gmail.com>2018-11-14 16:21:14 +0800
commiteb8fa3cc89ae3a3247c649486839b1c250554d2d (patch)
treec61b8ebebc739db0e5413cd214fdd0d3da2fe61e /swarm/fuse
parentcff97119a713a6f790893aaf1c172a397a48bf33 (diff)
downloadgo-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/fuse')
-rw-r--r--swarm/fuse/swarmfs_test.go163
1 files changed, 66 insertions, 97 deletions
diff --git a/swarm/fuse/swarmfs_test.go b/swarm/fuse/swarmfs_test.go
index 87d918550..460e31c4e 100644
--- a/swarm/fuse/swarmfs_test.go
+++ b/swarm/fuse/swarmfs_test.go
@@ -20,20 +20,19 @@ package fuse
import (
"bytes"
- "crypto/rand"
"flag"
"fmt"
"io"
"io/ioutil"
+ "math/rand"
"os"
"path/filepath"
"testing"
+ "github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/swarm/api"
"github.com/ethereum/go-ethereum/swarm/storage"
-
- "github.com/ethereum/go-ethereum/log"
-
+ "github.com/ethereum/go-ethereum/swarm/testutil"
colorable "github.com/mattn/go-colorable"
)
@@ -229,12 +228,6 @@ func checkFile(t *testing.T, testMountDir, fname string, contents []byte) {
}
}
-func getRandomBytes(size int) []byte {
- contents := make([]byte, size)
- rand.Read(contents)
- return contents
-}
-
func isDirEmpty(name string) bool {
f, err := os.Open(name)
if err != nil {
@@ -328,22 +321,22 @@ func (ta *testAPI) mountListAndUnmount(t *testing.T, toEncrypt bool) {
dat.testMountDir = filepath.Join(dat.testDir, "testMountDir")
dat.files = make(map[string]fileInfo)
- dat.files["1.txt"] = fileInfo{0700, 333, 444, getRandomBytes(10)}
- dat.files["2.txt"] = fileInfo{0711, 333, 444, getRandomBytes(10)}
- dat.files["3.txt"] = fileInfo{0622, 333, 444, getRandomBytes(100)}
- dat.files["4.txt"] = fileInfo{0533, 333, 444, getRandomBytes(1024)}
- dat.files["5.txt"] = fileInfo{0544, 333, 444, getRandomBytes(10)}
- dat.files["6.txt"] = fileInfo{0555, 333, 444, getRandomBytes(10)}
- dat.files["7.txt"] = fileInfo{0666, 333, 444, getRandomBytes(10)}
- dat.files["8.txt"] = fileInfo{0777, 333, 333, getRandomBytes(10)}
- dat.files["11.txt"] = fileInfo{0777, 333, 444, getRandomBytes(10)}
- dat.files["111.txt"] = fileInfo{0777, 333, 444, getRandomBytes(10)}
- dat.files["two/2.txt"] = fileInfo{0777, 333, 444, getRandomBytes(10)}
- dat.files["two/2/2.txt"] = fileInfo{0777, 333, 444, getRandomBytes(10)}
- dat.files["two/2./2.txt"] = fileInfo{0777, 444, 444, getRandomBytes(10)}
- dat.files["twice/2.txt"] = fileInfo{0777, 444, 333, getRandomBytes(200)}
- dat.files["one/two/three/four/five/six/seven/eight/nine/10.txt"] = fileInfo{0777, 333, 444, getRandomBytes(10240)}
- dat.files["one/two/three/four/five/six/six"] = fileInfo{0777, 333, 444, getRandomBytes(10)}
+ dat.files["1.txt"] = fileInfo{0700, 333, 444, testutil.RandomBytes(1, 10)}
+ dat.files["2.txt"] = fileInfo{0711, 333, 444, testutil.RandomBytes(2, 10)}
+ dat.files["3.txt"] = fileInfo{0622, 333, 444, testutil.RandomBytes(3, 100)}
+ dat.files["4.txt"] = fileInfo{0533, 333, 444, testutil.RandomBytes(4, 1024)}
+ dat.files["5.txt"] = fileInfo{0544, 333, 444, testutil.RandomBytes(5, 10)}
+ dat.files["6.txt"] = fileInfo{0555, 333, 444, testutil.RandomBytes(6, 10)}
+ dat.files["7.txt"] = fileInfo{0666, 333, 444, testutil.RandomBytes(7, 10)}
+ dat.files["8.txt"] = fileInfo{0777, 333, 333, testutil.RandomBytes(8, 10)}
+ dat.files["11.txt"] = fileInfo{0777, 333, 444, testutil.RandomBytes(9, 10)}
+ dat.files["111.txt"] = fileInfo{0777, 333, 444, testutil.RandomBytes(10, 10)}
+ dat.files["two/2.txt"] = fileInfo{0777, 333, 444, testutil.RandomBytes(11, 10)}
+ dat.files["two/2/2.txt"] = fileInfo{0777, 333, 444, testutil.RandomBytes(12, 10)}
+ dat.files["two/2./2.txt"] = fileInfo{0777, 444, 444, testutil.RandomBytes(13, 10)}
+ dat.files["twice/2.txt"] = fileInfo{0777, 444, 333, testutil.RandomBytes(14, 200)}
+ dat.files["one/two/three/four/five/six/seven/eight/nine/10.txt"] = fileInfo{0777, 333, 444, testutil.RandomBytes(15, 10240)}
+ dat.files["one/two/three/four/five/six/six"] = fileInfo{0777, 333, 444, testutil.RandomBytes(16, 10)}
dat, err = ta.uploadAndMount(dat, t)
if err != nil {
@@ -386,7 +379,7 @@ func (ta *testAPI) runMaxMounts(t *testing.T, toEncrypt bool) {
dat.testUploadDir = filepath.Join(dat.testDir, "max-upload1")
dat.testMountDir = filepath.Join(dat.testDir, "max-mount1")
dat.files = make(map[string]fileInfo)
- dat.files["1.txt"] = fileInfo{0700, 333, 444, getRandomBytes(10)}
+ dat.files["1.txt"] = fileInfo{0700, 333, 444, testutil.RandomBytes(1, 10)}
dat, err = ta.uploadAndMount(dat, t)
if err != nil {
@@ -396,7 +389,7 @@ func (ta *testAPI) runMaxMounts(t *testing.T, toEncrypt bool) {
dat.testUploadDir = filepath.Join(dat.testDir, "max-upload2")
dat.testMountDir = filepath.Join(dat.testDir, "max-mount2")
- dat.files["2.txt"] = fileInfo{0700, 333, 444, getRandomBytes(10)}
+ dat.files["2.txt"] = fileInfo{0700, 333, 444, testutil.RandomBytes(1, 10)}
dat, err = ta.uploadAndMount(dat, t)
if err != nil {
@@ -405,7 +398,7 @@ func (ta *testAPI) runMaxMounts(t *testing.T, toEncrypt bool) {
dat.testUploadDir = filepath.Join(dat.testDir, "max-upload3")
dat.testMountDir = filepath.Join(dat.testDir, "max-mount3")
- dat.files["3.txt"] = fileInfo{0700, 333, 444, getRandomBytes(10)}
+ dat.files["3.txt"] = fileInfo{0700, 333, 444, testutil.RandomBytes(1, 10)}
dat, err = ta.uploadAndMount(dat, t)
if err != nil {
@@ -414,7 +407,7 @@ func (ta *testAPI) runMaxMounts(t *testing.T, toEncrypt bool) {
dat.testUploadDir = filepath.Join(dat.testDir, "max-upload4")
dat.testMountDir = filepath.Join(dat.testDir, "max-mount4")
- dat.files["4.txt"] = fileInfo{0700, 333, 444, getRandomBytes(10)}
+ dat.files["4.txt"] = fileInfo{0700, 333, 444, testutil.RandomBytes(1, 10)}
dat, err = ta.uploadAndMount(dat, t)
if err != nil {
@@ -423,7 +416,7 @@ func (ta *testAPI) runMaxMounts(t *testing.T, toEncrypt bool) {
dat.testUploadDir = filepath.Join(dat.testDir, "max-upload5")
dat.testMountDir = filepath.Join(dat.testDir, "max-mount5")
- dat.files["5.txt"] = fileInfo{0700, 333, 444, getRandomBytes(10)}
+ dat.files["5.txt"] = fileInfo{0700, 333, 444, testutil.RandomBytes(1, 10)}
dat, err = ta.uploadAndMount(dat, t)
if err != nil {
@@ -436,7 +429,7 @@ func (ta *testAPI) runMaxMounts(t *testing.T, toEncrypt bool) {
if err != nil {
t.Fatalf("Couldn't create upload dir 6: %v", err)
}
- dat.files["6.txt"] = fileInfo{0700, 333, 444, getRandomBytes(10)}
+ dat.files["6.txt"] = fileInfo{0700, 333, 444, testutil.RandomBytes(1, 10)}
testMountDir6 := filepath.Join(dat.testDir, "max-mount6")
err = os.MkdirAll(testMountDir6, 0777)
if err != nil {
@@ -475,7 +468,7 @@ func (ta *testAPI) remount(t *testing.T, toEncrypt bool) {
dat.testMountDir = filepath.Join(dat.testDir, "remount-mount1")
dat.files = make(map[string]fileInfo)
- dat.files["1.txt"] = fileInfo{0700, 333, 444, getRandomBytes(10)}
+ dat.files["1.txt"] = fileInfo{0700, 333, 444, testutil.RandomBytes(1, 10)}
dat, err = ta.uploadAndMount(dat, t)
if err != nil {
@@ -494,7 +487,7 @@ func (ta *testAPI) remount(t *testing.T, toEncrypt bool) {
}
// mount a different hash in already mounted point
- dat.files["2.txt"] = fileInfo{0700, 333, 444, getRandomBytes(10)}
+ dat.files["2.txt"] = fileInfo{0700, 333, 444, testutil.RandomBytes(1, 10)}
testUploadDir2, err3 := addDir(dat.testDir, "remount-upload2")
if err3 != nil {
t.Fatalf("Error creating second upload dir: %v", err3)
@@ -543,7 +536,7 @@ func (ta *testAPI) unmount(t *testing.T, toEncrypt bool) {
dat.testUploadDir = filepath.Join(dat.testDir, "ex-upload1")
dat.testMountDir = filepath.Join(dat.testDir, "ex-mount1")
dat.files = make(map[string]fileInfo)
- dat.files["1.txt"] = fileInfo{0700, 333, 444, getRandomBytes(10)}
+ dat.files["1.txt"] = fileInfo{0700, 333, 444, testutil.RandomBytes(1, 10)}
dat, err = ta.uploadAndMount(dat, t)
if err != nil {
@@ -591,7 +584,7 @@ func (ta *testAPI) unmountWhenResourceBusy(t *testing.T, toEncrypt bool) {
dat.testUploadDir = filepath.Join(dat.testDir, "ex-upload1")
dat.testMountDir = filepath.Join(dat.testDir, "ex-mount1")
dat.files = make(map[string]fileInfo)
- dat.files["1.txt"] = fileInfo{0700, 333, 444, getRandomBytes(10)}
+ dat.files["1.txt"] = fileInfo{0700, 333, 444, testutil.RandomBytes(1, 10)}
dat, err = ta.uploadAndMount(dat, t)
if err != nil {
@@ -609,7 +602,7 @@ func (ta *testAPI) unmountWhenResourceBusy(t *testing.T, toEncrypt bool) {
//we need to manually close the file before mount for this test
//but let's defer too in case of errors
defer d.Close()
- _, err = d.Write(getRandomBytes(10))
+ _, err = d.Write(testutil.RandomBytes(1, 10))
if err != nil {
t.Fatalf("Couldn't write to file: %v", err)
}
@@ -667,7 +660,7 @@ func (ta *testAPI) seekInMultiChunkFile(t *testing.T, toEncrypt bool) {
dat.testUploadDir = filepath.Join(dat.testDir, "seek-upload1")
dat.testMountDir = filepath.Join(dat.testDir, "seek-mount")
dat.files = make(map[string]fileInfo)
- dat.files["1.txt"] = fileInfo{0700, 333, 444, getRandomBytes(10240)}
+ dat.files["1.txt"] = fileInfo{0700, 333, 444, testutil.RandomBytes(1, 10240)}
dat, err = ta.uploadAndMount(dat, t)
if err != nil {
@@ -733,9 +726,9 @@ func (ta *testAPI) createNewFile(t *testing.T, toEncrypt bool) {
dat.testUploadDir = filepath.Join(dat.testDir, "create-upload1")
dat.testMountDir = filepath.Join(dat.testDir, "create-mount")
dat.files = make(map[string]fileInfo)
- dat.files["1.txt"] = fileInfo{0700, 333, 444, getRandomBytes(10)}
- dat.files["five.txt"] = fileInfo{0700, 333, 444, getRandomBytes(10)}
- dat.files["six.txt"] = fileInfo{0700, 333, 444, getRandomBytes(10)}
+ dat.files["1.txt"] = fileInfo{0700, 333, 444, testutil.RandomBytes(1, 10)}
+ dat.files["five.txt"] = fileInfo{0700, 333, 444, testutil.RandomBytes(2, 10)}
+ dat.files["six.txt"] = fileInfo{0700, 333, 444, testutil.RandomBytes(3, 10)}
dat, err = ta.uploadAndMount(dat, t)
if err != nil {
@@ -751,11 +744,7 @@ func (ta *testAPI) createNewFile(t *testing.T, toEncrypt bool) {
}
defer d.Close()
log.Debug("Opened file")
- contents := make([]byte, 11)
- _, err = rand.Read(contents)
- if err != nil {
- t.Fatalf("Could not rand read contents %v", err)
- }
+ contents := testutil.RandomBytes(1, 11)
log.Debug("content read")
_, err = d.Write(contents)
if err != nil {
@@ -815,7 +804,7 @@ func (ta *testAPI) createNewFileInsideDirectory(t *testing.T, toEncrypt bool) {
dat.testUploadDir = filepath.Join(dat.testDir, "createinsidedir-upload")
dat.testMountDir = filepath.Join(dat.testDir, "createinsidedir-mount")
dat.files = make(map[string]fileInfo)
- dat.files["one/1.txt"] = fileInfo{0700, 333, 444, getRandomBytes(10)}
+ dat.files["one/1.txt"] = fileInfo{0700, 333, 444, testutil.RandomBytes(1, 10)}
dat, err = ta.uploadAndMount(dat, t)
if err != nil {
@@ -832,11 +821,7 @@ func (ta *testAPI) createNewFileInsideDirectory(t *testing.T, toEncrypt bool) {
}
defer d.Close()
log.Debug("File opened")
- contents := make([]byte, 11)
- _, err = rand.Read(contents)
- if err != nil {
- t.Fatalf("Error filling random bytes into byte array %v", err)
- }
+ contents := testutil.RandomBytes(1, 11)
log.Debug("Content read")
_, err = d.Write(contents)
if err != nil {
@@ -896,7 +881,7 @@ func (ta *testAPI) createNewFileInsideNewDirectory(t *testing.T, toEncrypt bool)
dat.testUploadDir = filepath.Join(dat.testDir, "createinsidenewdir-upload")
dat.testMountDir = filepath.Join(dat.testDir, "createinsidenewdir-mount")
dat.files = make(map[string]fileInfo)
- dat.files["1.txt"] = fileInfo{0700, 333, 444, getRandomBytes(10)}
+ dat.files["1.txt"] = fileInfo{0700, 333, 444, testutil.RandomBytes(1, 10)}
dat, err = ta.uploadAndMount(dat, t)
if err != nil {
@@ -916,11 +901,7 @@ func (ta *testAPI) createNewFileInsideNewDirectory(t *testing.T, toEncrypt bool)
}
defer d.Close()
log.Debug("File opened")
- contents := make([]byte, 11)
- _, err = rand.Read(contents)
- if err != nil {
- t.Fatalf("Error writing random bytes to byte array: %v", err)
- }
+ contents := testutil.RandomBytes(1, 11)
log.Debug("content read")
_, err = d.Write(contents)
if err != nil {
@@ -976,9 +957,9 @@ func (ta *testAPI) removeExistingFile(t *testing.T, toEncrypt bool) {
dat.testUploadDir = filepath.Join(dat.testDir, "remove-upload")
dat.testMountDir = filepath.Join(dat.testDir, "remove-mount")
dat.files = make(map[string]fileInfo)
- dat.files["1.txt"] = fileInfo{0700, 333, 444, getRandomBytes(10)}
- dat.files["five.txt"] = fileInfo{0700, 333, 444, getRandomBytes(10)}
- dat.files["six.txt"] = fileInfo{0700, 333, 444, getRandomBytes(10)}
+ dat.files["1.txt"] = fileInfo{0700, 333, 444, testutil.RandomBytes(1, 10)}
+ dat.files["five.txt"] = fileInfo{0700, 333, 444, testutil.RandomBytes(2, 10)}
+ dat.files["six.txt"] = fileInfo{0700, 333, 444, testutil.RandomBytes(3, 10)}
dat, err = ta.uploadAndMount(dat, t)
if err != nil {
@@ -1036,9 +1017,9 @@ func (ta *testAPI) removeExistingFileInsideDir(t *testing.T, toEncrypt bool) {
dat.testUploadDir = filepath.Join(dat.testDir, "remove-upload")
dat.testMountDir = filepath.Join(dat.testDir, "remove-mount")
dat.files = make(map[string]fileInfo)
- dat.files["1.txt"] = fileInfo{0700, 333, 444, getRandomBytes(10)}
- dat.files["one/five.txt"] = fileInfo{0700, 333, 444, getRandomBytes(10)}
- dat.files["one/six.txt"] = fileInfo{0700, 333, 444, getRandomBytes(10)}
+ dat.files["1.txt"] = fileInfo{0700, 333, 444, testutil.RandomBytes(1, 10)}
+ dat.files["one/five.txt"] = fileInfo{0700, 333, 444, testutil.RandomBytes(2, 10)}
+ dat.files["one/six.txt"] = fileInfo{0700, 333, 444, testutil.RandomBytes(3, 10)}
dat, err = ta.uploadAndMount(dat, t)
if err != nil {
@@ -1104,9 +1085,9 @@ func (ta *testAPI) removeNewlyAddedFile(t *testing.T, toEncrypt bool) {
dat.testUploadDir = filepath.Join(dat.testDir, "removenew-upload")
dat.testMountDir = filepath.Join(dat.testDir, "removenew-mount")
dat.files = make(map[string]fileInfo)
- dat.files["1.txt"] = fileInfo{0700, 333, 444, getRandomBytes(10)}
- dat.files["five.txt"] = fileInfo{0700, 333, 444, getRandomBytes(10)}
- dat.files["six.txt"] = fileInfo{0700, 333, 444, getRandomBytes(10)}
+ dat.files["1.txt"] = fileInfo{0700, 333, 444, testutil.RandomBytes(1, 10)}
+ dat.files["five.txt"] = fileInfo{0700, 333, 444, testutil.RandomBytes(2, 10)}
+ dat.files["six.txt"] = fileInfo{0700, 333, 444, testutil.RandomBytes(3, 10)}
dat, err = ta.uploadAndMount(dat, t)
if err != nil {
@@ -1127,11 +1108,7 @@ func (ta *testAPI) removeNewlyAddedFile(t *testing.T, toEncrypt bool) {
}
defer d.Close()
log.Debug("file opened")
- contents := make([]byte, 11)
- _, err = rand.Read(contents)
- if err != nil {
- t.Fatalf("Error writing random bytes to byte array: %v", err)
- }
+ contents := testutil.RandomBytes(1, 11)
log.Debug("content read")
_, err = d.Write(contents)
if err != nil {
@@ -1201,9 +1178,9 @@ func (ta *testAPI) addNewFileAndModifyContents(t *testing.T, toEncrypt bool) {
dat.testUploadDir = filepath.Join(dat.testDir, "modifyfile-upload")
dat.testMountDir = filepath.Join(dat.testDir, "modifyfile-mount")
dat.files = make(map[string]fileInfo)
- dat.files["1.txt"] = fileInfo{0700, 333, 444, getRandomBytes(10)}
- dat.files["five.txt"] = fileInfo{0700, 333, 444, getRandomBytes(10)}
- dat.files["six.txt"] = fileInfo{0700, 333, 444, getRandomBytes(10)}
+ dat.files["1.txt"] = fileInfo{0700, 333, 444, testutil.RandomBytes(1, 10)}
+ dat.files["five.txt"] = fileInfo{0700, 333, 444, testutil.RandomBytes(2, 10)}
+ dat.files["six.txt"] = fileInfo{0700, 333, 444, testutil.RandomBytes(3, 10)}
dat, err = ta.uploadAndMount(dat, t)
if err != nil {
@@ -1357,9 +1334,9 @@ func (ta *testAPI) removeEmptyDir(t *testing.T, toEncrypt bool) {
dat.testUploadDir = filepath.Join(dat.testDir, "rmdir-upload")
dat.testMountDir = filepath.Join(dat.testDir, "rmdir-mount")
dat.files = make(map[string]fileInfo)
- dat.files["1.txt"] = fileInfo{0700, 333, 444, getRandomBytes(10)}
- dat.files["five.txt"] = fileInfo{0700, 333, 444, getRandomBytes(10)}
- dat.files["six.txt"] = fileInfo{0700, 333, 444, getRandomBytes(10)}
+ dat.files["1.txt"] = fileInfo{0700, 333, 444, testutil.RandomBytes(1, 10)}
+ dat.files["five.txt"] = fileInfo{0700, 333, 444, testutil.RandomBytes(2, 10)}
+ dat.files["six.txt"] = fileInfo{0700, 333, 444, testutil.RandomBytes(3, 10)}
dat, err = ta.uploadAndMount(dat, t)
if err != nil {
@@ -1406,9 +1383,9 @@ func (ta *testAPI) removeDirWhichHasFiles(t *testing.T, toEncrypt bool) {
dat.testUploadDir = filepath.Join(dat.testDir, "rmdir-upload")
dat.testMountDir = filepath.Join(dat.testDir, "rmdir-mount")
dat.files = make(map[string]fileInfo)
- dat.files["one/1.txt"] = fileInfo{0700, 333, 444, getRandomBytes(10)}
- dat.files["two/five.txt"] = fileInfo{0700, 333, 444, getRandomBytes(10)}
- dat.files["two/six.txt"] = fileInfo{0700, 333, 444, getRandomBytes(10)}
+ dat.files["one/1.txt"] = fileInfo{0700, 333, 444, testutil.RandomBytes(1, 10)}
+ dat.files["two/five.txt"] = fileInfo{0700, 333, 444, testutil.RandomBytes(2, 10)}
+ dat.files["two/six.txt"] = fileInfo{0700, 333, 444, testutil.RandomBytes(3, 10)}
dat, err = ta.uploadAndMount(dat, t)
if err != nil {
@@ -1480,12 +1457,12 @@ func (ta *testAPI) removeDirWhichHasSubDirs(t *testing.T, toEncrypt bool) {
dat.testUploadDir = filepath.Join(dat.testDir, "rmsubdir-upload")
dat.testMountDir = filepath.Join(dat.testDir, "rmsubdir-mount")
dat.files = make(map[string]fileInfo)
- dat.files["one/1.txt"] = fileInfo{0700, 333, 444, getRandomBytes(10)}
- dat.files["two/three/2.txt"] = fileInfo{0700, 333, 444, getRandomBytes(10)}
- dat.files["two/three/3.txt"] = fileInfo{0700, 333, 444, getRandomBytes(10)}
- dat.files["two/four/5.txt"] = fileInfo{0700, 333, 444, getRandomBytes(10)}
- dat.files["two/four/6.txt"] = fileInfo{0700, 333, 444, getRandomBytes(10)}
- dat.files["two/four/six/7.txt"] = fileInfo{0700, 333, 444, getRandomBytes(10)}
+ dat.files["one/1.txt"] = fileInfo{0700, 333, 444, testutil.RandomBytes(1, 10)}
+ dat.files["two/three/2.txt"] = fileInfo{0700, 333, 444, testutil.RandomBytes(2, 10)}
+ dat.files["two/three/3.txt"] = fileInfo{0700, 333, 444, testutil.RandomBytes(3, 10)}
+ dat.files["two/four/5.txt"] = fileInfo{0700, 333, 444, testutil.RandomBytes(4, 10)}
+ dat.files["two/four/6.txt"] = fileInfo{0700, 333, 444, testutil.RandomBytes(5, 10)}
+ dat.files["two/four/six/7.txt"] = fileInfo{0700, 333, 444, testutil.RandomBytes(6, 10)}
dat, err = ta.uploadAndMount(dat, t)
if err != nil {
@@ -1567,11 +1544,7 @@ func (ta *testAPI) appendFileContentsToEnd(t *testing.T, toEncrypt bool) {
dat.testMountDir = filepath.Join(dat.testDir, "appendlargefile-mount")
dat.files = make(map[string]fileInfo)
- line1 := make([]byte, 10)
- _, err = rand.Read(line1)
- if err != nil {
- t.Fatalf("Error writing random bytes to byte array: %v", err)
- }
+ line1 := testutil.RandomBytes(1, 10)
dat.files["1.txt"] = fileInfo{0700, 333, 444, line1}
@@ -1588,11 +1561,7 @@ func (ta *testAPI) appendFileContentsToEnd(t *testing.T, toEncrypt bool) {
}
defer fd.Close()
log.Debug("file opened")
- line2 := make([]byte, 5)
- _, err = rand.Read(line2)
- if err != nil {
- t.Fatalf("Error writing random bytes to byte array: %v", err)
- }
+ line2 := testutil.RandomBytes(1, 5)
log.Debug("line read")
_, err = fd.Seek(int64(len(line1)), 0)
if err != nil {