aboutsummaryrefslogtreecommitdiffstats
path: root/cmd/swarm/export_test.go
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 /cmd/swarm/export_test.go
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 'cmd/swarm/export_test.go')
-rw-r--r--cmd/swarm/export_test.go36
1 files changed, 6 insertions, 30 deletions
diff --git a/cmd/swarm/export_test.go b/cmd/swarm/export_test.go
index c533511af..f1bc2f265 100644
--- a/cmd/swarm/export_test.go
+++ b/cmd/swarm/export_test.go
@@ -19,9 +19,7 @@ package main
import (
"bytes"
"crypto/md5"
- "crypto/rand"
"io"
- "io/ioutil"
"net/http"
"os"
"runtime"
@@ -29,6 +27,7 @@ import (
"testing"
"github.com/ethereum/go-ethereum/swarm"
+ "github.com/ethereum/go-ethereum/swarm/testutil"
)
// TestCLISwarmExportImport perform the following test:
@@ -45,11 +44,12 @@ func TestCLISwarmExportImport(t *testing.T) {
cluster := newTestCluster(t, 1)
// generate random 10mb file
- f, cleanup := generateRandomFile(t, 10000000)
- defer cleanup()
+ content := testutil.RandomBytes(1, 10000000)
+ fileName := testutil.TempFileWithContent(t, string(content))
+ defer os.Remove(fileName)
// upload the file with 'swarm up' and expect a hash
- up := runSwarm(t, "--bzzapi", cluster.Nodes[0].URL, "up", f.Name())
+ up := runSwarm(t, "--bzzapi", cluster.Nodes[0].URL, "up", fileName)
_, matches := up.ExpectRegexp(`[a-f\d]{64}`)
up.ExpectExit()
hash := matches[0]
@@ -96,7 +96,7 @@ func TestCLISwarmExportImport(t *testing.T) {
}
// compare downloaded file with the generated random file
- mustEqualFiles(t, f, res.Body)
+ mustEqualFiles(t, bytes.NewReader(content), res.Body)
}
func mustEqualFiles(t *testing.T, up io.Reader, down io.Reader) {
@@ -117,27 +117,3 @@ func mustEqualFiles(t *testing.T, up io.Reader, down io.Reader) {
t.Fatalf("downloaded imported file md5=%x (length %v) is not the same as the generated one mp5=%x (length %v)", downHash, downLen, upHash, upLen)
}
}
-
-func generateRandomFile(t *testing.T, size int) (f *os.File, teardown func()) {
- // create a tmp file
- tmp, err := ioutil.TempFile("", "swarm-test")
- if err != nil {
- t.Fatal(err)
- }
-
- // callback for tmp file cleanup
- teardown = func() {
- tmp.Close()
- os.Remove(tmp.Name())
- }
-
- // write 10mb random data to file
- buf := make([]byte, 10000000)
- _, err = rand.Read(buf)
- if err != nil {
- t.Fatal(err)
- }
- ioutil.WriteFile(tmp.Name(), buf, 0755)
-
- return tmp, teardown
-}