2016-04-10 14:52:15 +00:00
|
|
|
package restic_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"restic"
|
|
|
|
"restic/checker"
|
|
|
|
"restic/repository"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
var testSnapshotTime = time.Unix(1460289341, 207401672)
|
|
|
|
|
2016-04-10 15:25:32 +00:00
|
|
|
const testCreateSnapshots = 3
|
|
|
|
|
2016-04-10 14:52:15 +00:00
|
|
|
func TestCreateSnapshot(t *testing.T) {
|
|
|
|
repo, cleanup := repository.TestRepository(t)
|
|
|
|
defer cleanup()
|
|
|
|
|
2016-04-10 15:25:32 +00:00
|
|
|
for i := 0; i < testCreateSnapshots; i++ {
|
|
|
|
restic.TestCreateSnapshot(t, repo, testSnapshotTime.Add(time.Duration(i)*time.Second))
|
|
|
|
}
|
2016-04-10 14:52:15 +00:00
|
|
|
|
|
|
|
snapshots, err := restic.LoadAllSnapshots(repo)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2016-04-10 15:25:32 +00:00
|
|
|
if len(snapshots) != testCreateSnapshots {
|
2016-04-10 14:52:15 +00:00
|
|
|
t.Fatalf("got %d snapshots, expected %d", len(snapshots), 1)
|
|
|
|
}
|
|
|
|
|
|
|
|
sn := snapshots[0]
|
2016-04-10 15:25:32 +00:00
|
|
|
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)
|
2016-04-10 14:52:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if sn.Tree == nil {
|
|
|
|
t.Fatalf("tree id is nil")
|
|
|
|
}
|
|
|
|
|
|
|
|
if sn.Tree.IsNull() {
|
|
|
|
t.Fatalf("snapshot has zero tree ID")
|
|
|
|
}
|
|
|
|
|
|
|
|
chkr := checker.New(repo)
|
|
|
|
|
|
|
|
hints, errs := chkr.LoadIndex()
|
|
|
|
if len(errs) != 0 {
|
|
|
|
t.Fatalf("errors loading index: %v", errs)
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(hints) != 0 {
|
|
|
|
t.Fatalf("errors loading index: %v", hints)
|
|
|
|
}
|
|
|
|
|
|
|
|
done := make(chan struct{})
|
|
|
|
defer close(done)
|
|
|
|
errChan := make(chan error)
|
|
|
|
go chkr.Structure(errChan, done)
|
|
|
|
|
|
|
|
for err := range errChan {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
2016-04-10 15:25:32 +00:00
|
|
|
|
|
|
|
errChan = make(chan error)
|
|
|
|
go chkr.ReadData(nil, errChan, done)
|
|
|
|
|
|
|
|
for err := range errChan {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
2016-04-10 14:52:15 +00:00
|
|
|
}
|