forked from TrueCloudLab/restic
backend/test: Randomize test suite
This commit is contained in:
parent
7ec0543af3
commit
79477fdfe4
1 changed files with 12 additions and 0 deletions
|
@ -13,12 +13,19 @@ import (
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
"restic/test"
|
"restic/test"
|
||||||
|
|
||||||
"restic/backend"
|
"restic/backend"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func seedRand(t testing.TB) {
|
||||||
|
seed := time.Now().UnixNano()
|
||||||
|
rand.Seed(seed)
|
||||||
|
t.Logf("rand initialized with seed %d", seed)
|
||||||
|
}
|
||||||
|
|
||||||
// TestCreateWithConfig tests that creating a backend in a location which already
|
// TestCreateWithConfig tests that creating a backend in a location which already
|
||||||
// has a config file fails.
|
// has a config file fails.
|
||||||
func (s *Suite) TestCreateWithConfig(t *testing.T) {
|
func (s *Suite) TestCreateWithConfig(t *testing.T) {
|
||||||
|
@ -101,6 +108,8 @@ func (s *Suite) TestConfig(t *testing.T) {
|
||||||
|
|
||||||
// TestLoad tests the backend's Load function.
|
// TestLoad tests the backend's Load function.
|
||||||
func (s *Suite) TestLoad(t *testing.T) {
|
func (s *Suite) TestLoad(t *testing.T) {
|
||||||
|
seedRand(t)
|
||||||
|
|
||||||
b := s.open(t)
|
b := s.open(t)
|
||||||
defer s.close(t, b)
|
defer s.close(t, b)
|
||||||
|
|
||||||
|
@ -160,6 +169,7 @@ func (s *Suite) TestLoad(t *testing.T) {
|
||||||
d = d[:l]
|
d = d[:l]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
t.Logf("Load, l %v, o %v, len(d) %v, getlen %v", l, o, len(d), getlen)
|
||||||
rd, err := b.Load(handle, getlen, int64(o))
|
rd, err := b.Load(handle, getlen, int64(o))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Load(%d, %d) returned unexpected error: %+v", l, o, err)
|
t.Errorf("Load(%d, %d) returned unexpected error: %+v", l, o, err)
|
||||||
|
@ -234,6 +244,8 @@ func (ec errorCloser) Size() int64 {
|
||||||
|
|
||||||
// TestSave tests saving data in the backend.
|
// TestSave tests saving data in the backend.
|
||||||
func (s *Suite) TestSave(t *testing.T) {
|
func (s *Suite) TestSave(t *testing.T) {
|
||||||
|
seedRand(t)
|
||||||
|
|
||||||
b := s.open(t)
|
b := s.open(t)
|
||||||
defer s.close(t, b)
|
defer s.close(t, b)
|
||||||
var id restic.ID
|
var id restic.ID
|
||||||
|
|
Loading…
Reference in a new issue