restic/internal/restic/testing_test.go

60 lines
1.3 KiB
Go
Raw Normal View History

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/checker"
"github.com/restic/restic/internal/repository"
2017-07-24 15:42:25 +00:00
"github.com/restic/restic/internal/restic"
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 := repository.TestRepository(t)
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), testDepth)
2016-04-10 15:25:32 +00:00
}
2016-04-10 14:52:15 +00:00
2023-12-24 14:04:05 +00:00
snapshots, err := restic.TestLoadAllSnapshots(context.TODO(), repo, restic.NewIDSet())
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")
}
checker.TestCheckRepo(t, repo)
2016-04-10 14:52:15 +00:00
}
func BenchmarkTestCreateSnapshot(t *testing.B) {
repo := repository.TestRepository(t)
t.ResetTimer()
for i := 0; i < t.N; i++ {
restic.TestCreateSnapshot(t, repo, testSnapshotTime.Add(time.Duration(i)*time.Second), testDepth)
}
}