2022-01-04 06:03:53 +00:00
|
|
|
package restic_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/restic/restic/internal/repository"
|
|
|
|
"github.com/restic/restic/internal/restic"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestFindLatestSnapshot(t *testing.T) {
|
|
|
|
repo, cleanup := repository.TestRepository(t)
|
|
|
|
defer cleanup()
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
2021-11-06 00:14:24 +00:00
|
|
|
id, err := restic.FindLatestSnapshot(context.TODO(), repo.Backend(), repo, []string{}, []restic.TagList{}, []string{"foo"}, nil)
|
2022-01-04 06:03:53 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("FindLatestSnapshot returned error: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if id != *latestSnapshot.ID() {
|
|
|
|
t.Errorf("FindLatestSnapshot returned wrong snapshot ID: %v", id)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestFindLatestSnapshotWithMaxTimestamp(t *testing.T) {
|
|
|
|
repo, cleanup := repository.TestRepository(t)
|
|
|
|
defer cleanup()
|
|
|
|
|
|
|
|
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")
|
|
|
|
|
2021-11-06 00:14:24 +00:00
|
|
|
id, err := restic.FindLatestSnapshot(context.TODO(), repo.Backend(), repo, []string{}, []restic.TagList{}, []string{"foo"}, &maxTimestamp)
|
2022-01-04 06:03:53 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("FindLatestSnapshot returned error: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if id != *desiredSnapshot.ID() {
|
|
|
|
t.Errorf("FindLatestSnapshot returned wrong snapshot ID: %v", id)
|
|
|
|
}
|
|
|
|
}
|