2016-04-10 14:52:15 +00:00
|
|
|
package restic_test
|
|
|
|
|
|
|
|
import (
|
2017-06-05 21:56:59 +00:00
|
|
|
"context"
|
2016-04-10 14:52:15 +00:00
|
|
|
"testing"
|
|
|
|
"time"
|
2017-07-23 12:21:03 +00:00
|
|
|
|
|
|
|
"github.com/restic/restic/internal"
|
|
|
|
"github.com/restic/restic/internal/checker"
|
|
|
|
"github.com/restic/restic/internal/repository"
|
2016-04-10 14:52:15 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var testSnapshotTime = time.Unix(1460289341, 207401672)
|
|
|
|
|
2016-07-31 08:58:09 +00:00
|
|
|
const (
|
|
|
|
testCreateSnapshots = 3
|
|
|
|
testDepth = 2
|
|
|
|
)
|
2016-04-10 15:25:32 +00:00
|
|
|
|
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++ {
|
2016-08-07 19:56:06 +00:00
|
|
|
restic.TestCreateSnapshot(t, repo, testSnapshotTime.Add(time.Duration(i)*time.Second), testDepth, 0)
|
2016-04-10 15:25:32 +00:00
|
|
|
}
|
2016-04-10 14:52:15 +00:00
|
|
|
|
2017-06-05 21:56:59 +00:00
|
|
|
snapshots, err := restic.LoadAllSnapshots(context.TODO(), repo)
|
2016-04-10 14:52:15 +00:00
|
|
|
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)) {
|
2016-05-08 11:09:36 +00:00
|
|
|
t.Fatalf("timestamp %v is outside of the allowed time range", sn.Time)
|
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")
|
|
|
|
}
|
|
|
|
|
2016-07-31 10:09:44 +00:00
|
|
|
checker.TestCheckRepo(t, repo)
|
2016-04-10 14:52:15 +00:00
|
|
|
}
|
2017-01-17 11:56:20 +00:00
|
|
|
|
|
|
|
func BenchmarkTestCreateSnapshot(t *testing.B) {
|
|
|
|
repo, cleanup := repository.TestRepository(t)
|
|
|
|
defer cleanup()
|
|
|
|
|
|
|
|
t.ResetTimer()
|
|
|
|
|
|
|
|
for i := 0; i < t.N; i++ {
|
|
|
|
restic.TestCreateSnapshot(t, repo, testSnapshotTime.Add(time.Duration(i)*time.Second), testDepth, 0)
|
|
|
|
}
|
|
|
|
}
|