test: improvements

This commit is contained in:
Alexander Neumann 2015-11-22 22:08:23 +01:00
parent b841eb4c54
commit 141d400b4a
1 changed files with 12 additions and 2 deletions

View File

@ -4,10 +4,10 @@ import (
"bytes"
"compress/bzip2"
"compress/gzip"
"crypto/rand"
"fmt"
"io"
"io/ioutil"
"math/rand"
"os"
"os/exec"
"path/filepath"
@ -15,6 +15,8 @@ import (
"runtime"
"testing"
mrand "math/rand"
"github.com/restic/restic/backend"
"github.com/restic/restic/backend/local"
"github.com/restic/restic/repository"
@ -76,7 +78,7 @@ func ParseID(s string) backend.ID {
func Random(seed, count int) []byte {
buf := make([]byte, count)
rnd := rand.New(rand.NewSource(int64(seed)))
rnd := mrand.New(mrand.NewSource(int64(seed)))
for i := 0; i < count; i++ {
buf[i] = byte(rnd.Uint32())
}
@ -90,6 +92,14 @@ func RandomReader(seed, size int) *bytes.Reader {
return bytes.NewReader(Random(seed, size))
}
// GenRandom returns a []byte filled with up to 1000 random bytes.
func GenRandom(t testing.TB) []byte {
buf := make([]byte, mrand.Intn(1000))
_, err := io.ReadFull(rand.Reader, buf)
OK(t, err)
return buf
}
// SetupTarTestFixture extracts the tarFile to outputDir.
func SetupTarTestFixture(t testing.TB, outputDir, tarFile string) {
input, err := os.Open(tarFile)