mirror of
https://github.com/octoleo/restic.git
synced 2024-12-22 02:48:55 +00:00
rewrite: cleanup tests
This commit is contained in:
parent
c31f5f986c
commit
649a6409ee
@ -65,8 +65,7 @@ func TestRewriteReplace(t *testing.T) {
|
||||
|
||||
// exclude some data
|
||||
testRunRewriteExclude(t, env.gopts, []string{"3"}, true, snapshotMetadataArgs{Hostname: "", Time: ""})
|
||||
newSnapshotIDs := testRunList(t, "snapshots", env.gopts)
|
||||
rtest.Assert(t, len(newSnapshotIDs) == 1, "expected one snapshot, got %v", newSnapshotIDs)
|
||||
newSnapshotIDs := testListSnapshots(t, env.gopts, 1)
|
||||
rtest.Assert(t, snapshotID != newSnapshotIDs[0], "snapshot id should have changed")
|
||||
// check forbids unused blobs, thus remove them first
|
||||
testRunPrune(t, env.gopts, PruneOptions{MaxUnused: "0"})
|
||||
@ -75,16 +74,15 @@ func TestRewriteReplace(t *testing.T) {
|
||||
|
||||
func testRewriteMetadata(t *testing.T, metadata snapshotMetadataArgs) {
|
||||
env, cleanup := withTestEnvironment(t)
|
||||
env.gopts.backendTestHook = nil
|
||||
defer cleanup()
|
||||
createBasicRewriteRepo(t, env)
|
||||
repo, _ := OpenRepository(context.TODO(), env.gopts)
|
||||
|
||||
testRunRewriteExclude(t, env.gopts, []string{}, true, metadata)
|
||||
|
||||
snapshots := FindFilteredSnapshots(context.TODO(), repo, repo, &restic.SnapshotFilter{}, []string{})
|
||||
|
||||
newSnapshot := <-snapshots
|
||||
repo, _ := OpenRepository(context.TODO(), env.gopts)
|
||||
snapshots, err := restic.TestLoadAllSnapshots(context.TODO(), repo, nil)
|
||||
rtest.OK(t, err)
|
||||
rtest.Assert(t, len(snapshots) == 1, "expected one snapshot, got %v", len(snapshots))
|
||||
newSnapshot := snapshots[0]
|
||||
|
||||
if metadata.Time != "" {
|
||||
rtest.Assert(t, newSnapshot.Time.Format(TimeFormat) == metadata.Time, "New snapshot should have time %s", metadata.Time)
|
||||
|
@ -187,3 +187,22 @@ func ParseDurationOrPanic(s string) Duration {
|
||||
|
||||
return d
|
||||
}
|
||||
|
||||
// TestLoadAllSnapshots returns a list of all snapshots in the repo.
|
||||
// If a snapshot ID is in excludeIDs, it will not be included in the result.
|
||||
func TestLoadAllSnapshots(ctx context.Context, repo Repository, excludeIDs IDSet) (snapshots Snapshots, err error) {
|
||||
err = ForAllSnapshots(ctx, repo, repo, excludeIDs, func(id ID, sn *Snapshot, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
snapshots = append(snapshots, sn)
|
||||
return nil
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return snapshots, nil
|
||||
}
|
||||
|
@ -17,32 +17,13 @@ const (
|
||||
testDepth = 2
|
||||
)
|
||||
|
||||
// LoadAllSnapshots returns a list of all snapshots in the repo.
|
||||
// If a snapshot ID is in excludeIDs, it will not be included in the result.
|
||||
func loadAllSnapshots(ctx context.Context, repo restic.Repository, excludeIDs restic.IDSet) (snapshots restic.Snapshots, err error) {
|
||||
err = restic.ForAllSnapshots(ctx, repo, repo, excludeIDs, func(id restic.ID, sn *restic.Snapshot, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
snapshots = append(snapshots, sn)
|
||||
return nil
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return snapshots, nil
|
||||
}
|
||||
|
||||
func TestCreateSnapshot(t *testing.T) {
|
||||
repo := repository.TestRepository(t)
|
||||
for i := 0; i < testCreateSnapshots; i++ {
|
||||
restic.TestCreateSnapshot(t, repo, testSnapshotTime.Add(time.Duration(i)*time.Second), testDepth)
|
||||
}
|
||||
|
||||
snapshots, err := loadAllSnapshots(context.TODO(), repo, restic.NewIDSet())
|
||||
snapshots, err := restic.TestLoadAllSnapshots(context.TODO(), repo, restic.NewIDSet())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user