cmd/swarm: Smoke test for MRU

This commit is contained in:
lash 2018-09-14 11:45:24 +02:00
parent 6a6affdfc7
commit 3d2842b291
2 changed files with 21 additions and 2 deletions

View file

@ -89,6 +89,12 @@ func main() {
Usage: "upload and sync",
Action: cliUploadAndSync,
},
{
Name: "resource_sync",
Aliases: []string{"r"},
Usage: "resource update generate, upload and sync",
Action: cliResourceUploadAndSync,
},
}
sort.Sort(cli.FlagsByName(app.Flags))

View file

@ -19,7 +19,8 @@ package main
import (
"bytes"
"crypto/md5"
"crypto/rand"
crand "crypto/rand"
"errors"
"fmt"
"io"
"io/ioutil"
@ -166,6 +167,18 @@ func digest(r io.Reader) ([]byte, error) {
return h.Sum(nil), nil
}
// generates random data in heap buffer
func generateRandomData(datasize int) ([]byte, error) {
b := make([]byte, datasize)
c, err := crand.Read(b)
if err != nil {
return nil, err
} else if c != datasize {
return nil, errors.New("short read")
}
return b, nil
}
// generateRandomFile is creating a temporary file with the requested byte size
func generateRandomFile(size int) (f *os.File, teardown func()) {
// create a tmp file
@ -181,7 +194,7 @@ func generateRandomFile(size int) (f *os.File, teardown func()) {
}
buf := make([]byte, size)
_, err = rand.Read(buf)
_, err = crand.Read(buf)
if err != nil {
panic(err)
}