forked from TrueCloudLab/restic
Add more tests
This commit is contained in:
parent
6655511ab8
commit
514a43f74b
2 changed files with 27 additions and 6 deletions
|
@ -116,6 +116,9 @@ func saveFile(t testing.TB, repo *repository.Repository, rd io.Reader) (blobs ba
|
|||
return blobs
|
||||
}
|
||||
|
||||
const maxFileSize = 1500000
|
||||
const maxSeed = 100
|
||||
|
||||
// saveTree saves a tree of fake files in the repo and returns the ID.
|
||||
func saveTree(t testing.TB, repo *repository.Repository, seed int64) backend.ID {
|
||||
rnd := rand.NewSource(seed)
|
||||
|
@ -124,10 +127,17 @@ func saveTree(t testing.TB, repo *repository.Repository, seed int64) backend.ID
|
|||
|
||||
var tree Tree
|
||||
for i := 0; i < numNodes; i++ {
|
||||
t.Logf("create node %v", i)
|
||||
seed := rnd.Int63() % maxSeed
|
||||
size := rnd.Int63() % maxFileSize
|
||||
|
||||
node := &Node{}
|
||||
node := &Node{
|
||||
Name: fmt.Sprintf("file-%v", seed),
|
||||
Type: "file",
|
||||
Mode: 0644,
|
||||
Size: uint64(size),
|
||||
}
|
||||
|
||||
node.Content = saveFile(t, repo, fakeFile(t, seed, size))
|
||||
tree.Nodes = append(tree.Nodes, node)
|
||||
}
|
||||
|
||||
|
|
|
@ -10,24 +10,28 @@ import (
|
|||
|
||||
var testSnapshotTime = time.Unix(1460289341, 207401672)
|
||||
|
||||
const testCreateSnapshots = 3
|
||||
|
||||
func TestCreateSnapshot(t *testing.T) {
|
||||
repo, cleanup := repository.TestRepository(t)
|
||||
defer cleanup()
|
||||
|
||||
restic.TestCreateSnapshot(t, repo, testSnapshotTime)
|
||||
for i := 0; i < testCreateSnapshots; i++ {
|
||||
restic.TestCreateSnapshot(t, repo, testSnapshotTime.Add(time.Duration(i)*time.Second))
|
||||
}
|
||||
|
||||
snapshots, err := restic.LoadAllSnapshots(repo)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if len(snapshots) != 1 {
|
||||
if len(snapshots) != testCreateSnapshots {
|
||||
t.Fatalf("got %d snapshots, expected %d", len(snapshots), 1)
|
||||
}
|
||||
|
||||
sn := snapshots[0]
|
||||
if sn.Time != testSnapshotTime {
|
||||
t.Fatalf("got timestamp %v, expected %v", sn.Time, testSnapshotTime)
|
||||
if sn.Time.Before(testSnapshotTime) || sn.Time.After(testSnapshotTime.Add(testCreateSnapshots*time.Second)) {
|
||||
t.Fatalf("timestamp %v is outside of the allowed time range", sn.Time, testSnapshotTime)
|
||||
}
|
||||
|
||||
if sn.Tree == nil {
|
||||
|
@ -57,4 +61,11 @@ func TestCreateSnapshot(t *testing.T) {
|
|||
for err := range errChan {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
errChan = make(chan error)
|
||||
go chkr.ReadData(nil, errChan, done)
|
||||
|
||||
for err := range errChan {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue