mirror of
https://github.com/restic/restic.git
synced 2025-12-11 18:47:50 +00:00
data: split node and snapshot code from restic package
This commit is contained in:
60
internal/data/testing_test.go
Normal file
60
internal/data/testing_test.go
Normal file
@@ -0,0 +1,60 @@
|
||||
package data_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/restic/restic/internal/checker"
|
||||
"github.com/restic/restic/internal/data"
|
||||
"github.com/restic/restic/internal/repository"
|
||||
"github.com/restic/restic/internal/restic"
|
||||
)
|
||||
|
||||
var testSnapshotTime = time.Unix(1460289341, 207401672)
|
||||
|
||||
const (
|
||||
testCreateSnapshots = 3
|
||||
testDepth = 2
|
||||
)
|
||||
|
||||
func TestCreateSnapshot(t *testing.T) {
|
||||
repo := repository.TestRepository(t)
|
||||
for i := 0; i < testCreateSnapshots; i++ {
|
||||
data.TestCreateSnapshot(t, repo, testSnapshotTime.Add(time.Duration(i)*time.Second), testDepth)
|
||||
}
|
||||
|
||||
snapshots, err := data.TestLoadAllSnapshots(context.TODO(), repo, restic.NewIDSet())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if len(snapshots) != testCreateSnapshots {
|
||||
t.Fatalf("got %d snapshots, expected %d", len(snapshots), 1)
|
||||
}
|
||||
|
||||
sn := snapshots[0]
|
||||
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)
|
||||
}
|
||||
|
||||
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, false)
|
||||
}
|
||||
|
||||
func BenchmarkTestCreateSnapshot(t *testing.B) {
|
||||
repo := repository.TestRepository(t)
|
||||
|
||||
t.ResetTimer()
|
||||
|
||||
for i := 0; i < t.N; i++ {
|
||||
data.TestCreateSnapshot(t, repo, testSnapshotTime.Add(time.Duration(i)*time.Second), testDepth)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user