2
2
mirror of https://github.com/octoleo/restic.git synced 2024-05-31 08:00:48 +00:00
restic/src/restic/testing_test.go

50 lines
1.0 KiB
Go
Raw Normal View History

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-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++ {
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
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)) {
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
}