mirror of
https://github.com/octoleo/restic.git
synced 2024-11-30 00:33:57 +00:00
Add more tests
This commit is contained in:
parent
6655511ab8
commit
514a43f74b
@ -116,6 +116,9 @@ func saveFile(t testing.TB, repo *repository.Repository, rd io.Reader) (blobs ba
|
|||||||
return blobs
|
return blobs
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const maxFileSize = 1500000
|
||||||
|
const maxSeed = 100
|
||||||
|
|
||||||
// saveTree saves a tree of fake files in the repo and returns the ID.
|
// 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 {
|
func saveTree(t testing.TB, repo *repository.Repository, seed int64) backend.ID {
|
||||||
rnd := rand.NewSource(seed)
|
rnd := rand.NewSource(seed)
|
||||||
@ -124,10 +127,17 @@ func saveTree(t testing.TB, repo *repository.Repository, seed int64) backend.ID
|
|||||||
|
|
||||||
var tree Tree
|
var tree Tree
|
||||||
for i := 0; i < numNodes; i++ {
|
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)
|
tree.Nodes = append(tree.Nodes, node)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,24 +10,28 @@ import (
|
|||||||
|
|
||||||
var testSnapshotTime = time.Unix(1460289341, 207401672)
|
var testSnapshotTime = time.Unix(1460289341, 207401672)
|
||||||
|
|
||||||
|
const testCreateSnapshots = 3
|
||||||
|
|
||||||
func TestCreateSnapshot(t *testing.T) {
|
func TestCreateSnapshot(t *testing.T) {
|
||||||
repo, cleanup := repository.TestRepository(t)
|
repo, cleanup := repository.TestRepository(t)
|
||||||
defer cleanup()
|
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)
|
snapshots, err := restic.LoadAllSnapshots(repo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(snapshots) != 1 {
|
if len(snapshots) != testCreateSnapshots {
|
||||||
t.Fatalf("got %d snapshots, expected %d", len(snapshots), 1)
|
t.Fatalf("got %d snapshots, expected %d", len(snapshots), 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
sn := snapshots[0]
|
sn := snapshots[0]
|
||||||
if sn.Time != testSnapshotTime {
|
if sn.Time.Before(testSnapshotTime) || sn.Time.After(testSnapshotTime.Add(testCreateSnapshots*time.Second)) {
|
||||||
t.Fatalf("got timestamp %v, expected %v", sn.Time, testSnapshotTime)
|
t.Fatalf("timestamp %v is outside of the allowed time range", sn.Time, testSnapshotTime)
|
||||||
}
|
}
|
||||||
|
|
||||||
if sn.Tree == nil {
|
if sn.Tree == nil {
|
||||||
@ -57,4 +61,11 @@ func TestCreateSnapshot(t *testing.T) {
|
|||||||
for err := range errChan {
|
for err := range errChan {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
errChan = make(chan error)
|
||||||
|
go chkr.ReadData(nil, errChan, done)
|
||||||
|
|
||||||
|
for err := range errChan {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user