mirror of
https://github.com/restic/restic.git
synced 2025-04-27 14:30:47 +00:00

TestRepository and its variants always returned no-op cleanup functions. If they ever do need to do cleanup, using testing.T.Cleanup is easier than passing these functions around.
44 lines
1.5 KiB
Go
44 lines
1.5 KiB
Go
package restic_test
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/restic/restic/internal/repository"
|
|
"github.com/restic/restic/internal/restic"
|
|
)
|
|
|
|
func TestFindLatestSnapshot(t *testing.T) {
|
|
repo := repository.TestRepository(t)
|
|
restic.TestCreateSnapshot(t, repo, parseTimeUTC("2015-05-05 05:05:05"), 1, 0)
|
|
restic.TestCreateSnapshot(t, repo, parseTimeUTC("2017-07-07 07:07:07"), 1, 0)
|
|
latestSnapshot := restic.TestCreateSnapshot(t, repo, parseTimeUTC("2019-09-09 09:09:09"), 1, 0)
|
|
|
|
sn, err := restic.FindFilteredSnapshot(context.TODO(), repo.Backend(), repo, []string{"foo"}, []restic.TagList{}, []string{}, nil, "latest")
|
|
if err != nil {
|
|
t.Fatalf("FindLatestSnapshot returned error: %v", err)
|
|
}
|
|
|
|
if *sn.ID() != *latestSnapshot.ID() {
|
|
t.Errorf("FindLatestSnapshot returned wrong snapshot ID: %v", *sn.ID())
|
|
}
|
|
}
|
|
|
|
func TestFindLatestSnapshotWithMaxTimestamp(t *testing.T) {
|
|
repo := repository.TestRepository(t)
|
|
restic.TestCreateSnapshot(t, repo, parseTimeUTC("2015-05-05 05:05:05"), 1, 0)
|
|
desiredSnapshot := restic.TestCreateSnapshot(t, repo, parseTimeUTC("2017-07-07 07:07:07"), 1, 0)
|
|
restic.TestCreateSnapshot(t, repo, parseTimeUTC("2019-09-09 09:09:09"), 1, 0)
|
|
|
|
maxTimestamp := parseTimeUTC("2018-08-08 08:08:08")
|
|
|
|
sn, err := restic.FindFilteredSnapshot(context.TODO(), repo.Backend(), repo, []string{"foo"}, []restic.TagList{}, []string{}, &maxTimestamp, "latest")
|
|
if err != nil {
|
|
t.Fatalf("FindLatestSnapshot returned error: %v", err)
|
|
}
|
|
|
|
if *sn.ID() != *desiredSnapshot.ID() {
|
|
t.Errorf("FindLatestSnapshot returned wrong snapshot ID: %v", *sn.ID())
|
|
}
|
|
}
|