mirror of
https://github.com/octoleo/restic.git
synced 2024-12-22 02:48:55 +00:00
Restructure TestApplyPolicy
This commit is contained in:
parent
cc627e832b
commit
060d8b57e0
@ -52,193 +52,194 @@ func TestExpireSnapshotOps(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
var testExpireSnapshots = restic.Snapshots{
|
||||
{Time: parseTimeUTC("2014-09-01 10:20:30")},
|
||||
{Time: parseTimeUTC("2014-09-02 10:20:30")},
|
||||
{Time: parseTimeUTC("2014-09-05 10:20:30")},
|
||||
{Time: parseTimeUTC("2014-09-06 10:20:30")},
|
||||
{Time: parseTimeUTC("2014-09-08 10:20:30")},
|
||||
{Time: parseTimeUTC("2014-09-09 10:20:30")},
|
||||
{Time: parseTimeUTC("2014-09-10 10:20:30")},
|
||||
{Time: parseTimeUTC("2014-09-11 10:20:30")},
|
||||
{Time: parseTimeUTC("2014-09-20 10:20:30")},
|
||||
{Time: parseTimeUTC("2014-09-22 10:20:30")},
|
||||
{Time: parseTimeUTC("2014-08-08 10:20:30")},
|
||||
{Time: parseTimeUTC("2014-08-10 10:20:30")},
|
||||
{Time: parseTimeUTC("2014-08-12 10:20:30")},
|
||||
{Time: parseTimeUTC("2014-08-13 10:20:30")},
|
||||
{Time: parseTimeUTC("2014-08-13 10:20:30.1")},
|
||||
{Time: parseTimeUTC("2014-08-15 10:20:30")},
|
||||
{Time: parseTimeUTC("2014-08-18 10:20:30")},
|
||||
{Time: parseTimeUTC("2014-08-20 10:20:30")},
|
||||
{Time: parseTimeUTC("2014-08-21 10:20:30")},
|
||||
{Time: parseTimeUTC("2014-08-22 10:20:30")},
|
||||
{Time: parseTimeUTC("2014-10-01 10:20:30"), Tags: []string{"foo"}},
|
||||
{Time: parseTimeUTC("2014-10-02 10:20:30"), Tags: []string{"foo"}},
|
||||
{Time: parseTimeUTC("2014-10-05 10:20:30"), Tags: []string{"foo"}},
|
||||
{Time: parseTimeUTC("2014-10-06 10:20:30"), Tags: []string{"foo"}},
|
||||
{Time: parseTimeUTC("2014-10-08 10:20:30"), Tags: []string{"foo"}},
|
||||
{Time: parseTimeUTC("2014-10-09 10:20:30"), Tags: []string{"foo"}},
|
||||
{Time: parseTimeUTC("2014-10-10 10:20:30"), Tags: []string{"foo"}},
|
||||
{Time: parseTimeUTC("2014-10-11 10:20:30"), Tags: []string{"foo"}},
|
||||
{Time: parseTimeUTC("2014-10-20 10:20:30"), Tags: []string{"foo"}},
|
||||
{Time: parseTimeUTC("2014-10-22 10:20:30"), Tags: []string{"foo"}},
|
||||
{Time: parseTimeUTC("2014-11-08 10:20:30"), Tags: []string{"foo"}},
|
||||
{Time: parseTimeUTC("2014-11-10 10:20:30"), Tags: []string{"foo"}},
|
||||
{Time: parseTimeUTC("2014-11-12 10:20:30"), Tags: []string{"foo"}},
|
||||
{Time: parseTimeUTC("2014-11-13 10:20:30"), Tags: []string{"foo"}},
|
||||
{Time: parseTimeUTC("2014-11-13 10:20:30.1"), Tags: []string{"bar"}},
|
||||
{Time: parseTimeUTC("2014-11-15 10:20:30"), Tags: []string{"foo", "bar"}},
|
||||
{Time: parseTimeUTC("2014-11-18 10:20:30")},
|
||||
{Time: parseTimeUTC("2014-11-20 10:20:30")},
|
||||
{Time: parseTimeUTC("2014-11-21 10:20:30")},
|
||||
{Time: parseTimeUTC("2014-11-22 10:20:30")},
|
||||
{Time: parseTimeUTC("2015-09-01 10:20:30")},
|
||||
{Time: parseTimeUTC("2015-09-02 10:20:30")},
|
||||
{Time: parseTimeUTC("2015-09-05 10:20:30")},
|
||||
{Time: parseTimeUTC("2015-09-06 10:20:30")},
|
||||
{Time: parseTimeUTC("2015-09-08 10:20:30")},
|
||||
{Time: parseTimeUTC("2015-09-09 10:20:30")},
|
||||
{Time: parseTimeUTC("2015-09-10 10:20:30")},
|
||||
{Time: parseTimeUTC("2015-09-11 10:20:30")},
|
||||
{Time: parseTimeUTC("2015-09-20 10:20:30")},
|
||||
{Time: parseTimeUTC("2015-09-22 10:20:30")},
|
||||
{Time: parseTimeUTC("2015-08-08 10:20:30")},
|
||||
{Time: parseTimeUTC("2015-08-10 10:20:30")},
|
||||
{Time: parseTimeUTC("2015-08-12 10:20:30")},
|
||||
{Time: parseTimeUTC("2015-08-13 10:20:30")},
|
||||
{Time: parseTimeUTC("2015-08-13 10:20:30.1")},
|
||||
{Time: parseTimeUTC("2015-08-15 10:20:30")},
|
||||
{Time: parseTimeUTC("2015-08-18 10:20:30")},
|
||||
{Time: parseTimeUTC("2015-08-20 10:20:30")},
|
||||
{Time: parseTimeUTC("2015-08-21 10:20:30")},
|
||||
{Time: parseTimeUTC("2015-08-22 10:20:30")},
|
||||
{Time: parseTimeUTC("2015-10-01 10:20:30")},
|
||||
{Time: parseTimeUTC("2015-10-02 10:20:30")},
|
||||
{Time: parseTimeUTC("2015-10-05 10:20:30")},
|
||||
{Time: parseTimeUTC("2015-10-06 10:20:30")},
|
||||
{Time: parseTimeUTC("2015-10-08 10:20:30")},
|
||||
{Time: parseTimeUTC("2015-10-09 10:20:30")},
|
||||
{Time: parseTimeUTC("2015-10-10 10:20:30")},
|
||||
{Time: parseTimeUTC("2015-10-11 10:20:30")},
|
||||
{Time: parseTimeUTC("2015-10-20 10:20:30")},
|
||||
{Time: parseTimeUTC("2015-10-22 10:20:30")},
|
||||
{Time: parseTimeUTC("2015-10-22 10:20:30")},
|
||||
{Time: parseTimeUTC("2015-10-22 10:20:30"), Tags: []string{"foo", "bar"}},
|
||||
{Time: parseTimeUTC("2015-10-22 10:20:30"), Tags: []string{"foo", "bar"}},
|
||||
{Time: parseTimeUTC("2015-10-22 10:20:30"), Tags: []string{"foo", "bar"}, Paths: []string{"path1", "path2"}},
|
||||
{Time: parseTimeUTC("2015-11-08 10:20:30")},
|
||||
{Time: parseTimeUTC("2015-11-10 10:20:30")},
|
||||
{Time: parseTimeUTC("2015-11-12 10:20:30")},
|
||||
{Time: parseTimeUTC("2015-11-13 10:20:30")},
|
||||
{Time: parseTimeUTC("2015-11-13 10:20:30.1")},
|
||||
{Time: parseTimeUTC("2015-11-15 10:20:30")},
|
||||
{Time: parseTimeUTC("2015-11-18 10:20:30")},
|
||||
{Time: parseTimeUTC("2015-11-20 10:20:30")},
|
||||
{Time: parseTimeUTC("2015-11-21 10:20:30")},
|
||||
{Time: parseTimeUTC("2015-11-22 10:20:30")},
|
||||
{Time: parseTimeUTC("2016-01-01 01:02:03")},
|
||||
{Time: parseTimeUTC("2016-01-01 01:03:03")},
|
||||
{Time: parseTimeUTC("2016-01-01 07:08:03")},
|
||||
{Time: parseTimeUTC("2016-01-03 07:02:03")},
|
||||
{Time: parseTimeUTC("2016-01-04 10:23:03")},
|
||||
{Time: parseTimeUTC("2016-01-04 11:23:03")},
|
||||
{Time: parseTimeUTC("2016-01-04 12:23:03")},
|
||||
{Time: parseTimeUTC("2016-01-04 12:24:03")},
|
||||
{Time: parseTimeUTC("2016-01-04 12:28:03")},
|
||||
{Time: parseTimeUTC("2016-01-04 12:30:03")},
|
||||
{Time: parseTimeUTC("2016-01-04 16:23:03")},
|
||||
{Time: parseTimeUTC("2016-01-05 09:02:03")},
|
||||
{Time: parseTimeUTC("2016-01-06 08:02:03")},
|
||||
{Time: parseTimeUTC("2016-01-07 10:02:03")},
|
||||
{Time: parseTimeUTC("2016-01-08 20:02:03")},
|
||||
{Time: parseTimeUTC("2016-01-09 21:02:03")},
|
||||
{Time: parseTimeUTC("2016-01-12 21:02:03")},
|
||||
{Time: parseTimeUTC("2016-01-12 21:08:03")},
|
||||
{Time: parseTimeUTC("2016-01-18 12:02:03")},
|
||||
}
|
||||
|
||||
var expireTests = []restic.ExpirePolicy{
|
||||
{},
|
||||
{Last: 10},
|
||||
{Last: 15},
|
||||
{Last: 99},
|
||||
{Last: 200},
|
||||
{Hourly: 20},
|
||||
{Daily: 3},
|
||||
{Daily: 10},
|
||||
{Daily: 30},
|
||||
{Last: 5, Daily: 5},
|
||||
{Last: 2, Daily: 10},
|
||||
{Weekly: 2},
|
||||
{Weekly: 4},
|
||||
{Daily: 3, Weekly: 4},
|
||||
{Monthly: 6},
|
||||
{Daily: 2, Weekly: 2, Monthly: 6},
|
||||
{Yearly: 10},
|
||||
{Daily: 7, Weekly: 2, Monthly: 3, Yearly: 10},
|
||||
{Tags: []restic.TagList{{"foo"}}},
|
||||
{Tags: []restic.TagList{{"foo", "bar"}}},
|
||||
{Tags: []restic.TagList{{"foo"}, {"bar"}}},
|
||||
{Within: parseDuration("1d")},
|
||||
{Within: parseDuration("2d")},
|
||||
{Within: parseDuration("7d")},
|
||||
{Within: parseDuration("1m")},
|
||||
}
|
||||
|
||||
func TestApplyPolicy(t *testing.T) {
|
||||
for i, p := range expireTests {
|
||||
keep, remove := restic.ApplyPolicy(testExpireSnapshots, p)
|
||||
var testExpireSnapshots = restic.Snapshots{
|
||||
{Time: parseTimeUTC("2014-09-01 10:20:30")},
|
||||
{Time: parseTimeUTC("2014-09-02 10:20:30")},
|
||||
{Time: parseTimeUTC("2014-09-05 10:20:30")},
|
||||
{Time: parseTimeUTC("2014-09-06 10:20:30")},
|
||||
{Time: parseTimeUTC("2014-09-08 10:20:30")},
|
||||
{Time: parseTimeUTC("2014-09-09 10:20:30")},
|
||||
{Time: parseTimeUTC("2014-09-10 10:20:30")},
|
||||
{Time: parseTimeUTC("2014-09-11 10:20:30")},
|
||||
{Time: parseTimeUTC("2014-09-20 10:20:30")},
|
||||
{Time: parseTimeUTC("2014-09-22 10:20:30")},
|
||||
{Time: parseTimeUTC("2014-08-08 10:20:30")},
|
||||
{Time: parseTimeUTC("2014-08-10 10:20:30")},
|
||||
{Time: parseTimeUTC("2014-08-12 10:20:30")},
|
||||
{Time: parseTimeUTC("2014-08-13 10:20:30")},
|
||||
{Time: parseTimeUTC("2014-08-13 10:20:30.1")},
|
||||
{Time: parseTimeUTC("2014-08-15 10:20:30")},
|
||||
{Time: parseTimeUTC("2014-08-18 10:20:30")},
|
||||
{Time: parseTimeUTC("2014-08-20 10:20:30")},
|
||||
{Time: parseTimeUTC("2014-08-21 10:20:30")},
|
||||
{Time: parseTimeUTC("2014-08-22 10:20:30")},
|
||||
{Time: parseTimeUTC("2014-10-01 10:20:30"), Tags: []string{"foo"}},
|
||||
{Time: parseTimeUTC("2014-10-02 10:20:30"), Tags: []string{"foo"}},
|
||||
{Time: parseTimeUTC("2014-10-05 10:20:30"), Tags: []string{"foo"}},
|
||||
{Time: parseTimeUTC("2014-10-06 10:20:30"), Tags: []string{"foo"}},
|
||||
{Time: parseTimeUTC("2014-10-08 10:20:30"), Tags: []string{"foo"}},
|
||||
{Time: parseTimeUTC("2014-10-09 10:20:30"), Tags: []string{"foo"}},
|
||||
{Time: parseTimeUTC("2014-10-10 10:20:30"), Tags: []string{"foo"}},
|
||||
{Time: parseTimeUTC("2014-10-11 10:20:30"), Tags: []string{"foo"}},
|
||||
{Time: parseTimeUTC("2014-10-20 10:20:30"), Tags: []string{"foo"}},
|
||||
{Time: parseTimeUTC("2014-10-22 10:20:30"), Tags: []string{"foo"}},
|
||||
{Time: parseTimeUTC("2014-11-08 10:20:30"), Tags: []string{"foo"}},
|
||||
{Time: parseTimeUTC("2014-11-10 10:20:30"), Tags: []string{"foo"}},
|
||||
{Time: parseTimeUTC("2014-11-12 10:20:30"), Tags: []string{"foo"}},
|
||||
{Time: parseTimeUTC("2014-11-13 10:20:30"), Tags: []string{"foo"}},
|
||||
{Time: parseTimeUTC("2014-11-13 10:20:30.1"), Tags: []string{"bar"}},
|
||||
{Time: parseTimeUTC("2014-11-15 10:20:30"), Tags: []string{"foo", "bar"}},
|
||||
{Time: parseTimeUTC("2014-11-18 10:20:30")},
|
||||
{Time: parseTimeUTC("2014-11-20 10:20:30")},
|
||||
{Time: parseTimeUTC("2014-11-21 10:20:30")},
|
||||
{Time: parseTimeUTC("2014-11-22 10:20:30")},
|
||||
{Time: parseTimeUTC("2015-09-01 10:20:30")},
|
||||
{Time: parseTimeUTC("2015-09-02 10:20:30")},
|
||||
{Time: parseTimeUTC("2015-09-05 10:20:30")},
|
||||
{Time: parseTimeUTC("2015-09-06 10:20:30")},
|
||||
{Time: parseTimeUTC("2015-09-08 10:20:30")},
|
||||
{Time: parseTimeUTC("2015-09-09 10:20:30")},
|
||||
{Time: parseTimeUTC("2015-09-10 10:20:30")},
|
||||
{Time: parseTimeUTC("2015-09-11 10:20:30")},
|
||||
{Time: parseTimeUTC("2015-09-20 10:20:30")},
|
||||
{Time: parseTimeUTC("2015-09-22 10:20:30")},
|
||||
{Time: parseTimeUTC("2015-08-08 10:20:30")},
|
||||
{Time: parseTimeUTC("2015-08-10 10:20:30")},
|
||||
{Time: parseTimeUTC("2015-08-12 10:20:30")},
|
||||
{Time: parseTimeUTC("2015-08-13 10:20:30")},
|
||||
{Time: parseTimeUTC("2015-08-13 10:20:30.1")},
|
||||
{Time: parseTimeUTC("2015-08-15 10:20:30")},
|
||||
{Time: parseTimeUTC("2015-08-18 10:20:30")},
|
||||
{Time: parseTimeUTC("2015-08-20 10:20:30")},
|
||||
{Time: parseTimeUTC("2015-08-21 10:20:30")},
|
||||
{Time: parseTimeUTC("2015-08-22 10:20:30")},
|
||||
{Time: parseTimeUTC("2015-10-01 10:20:30")},
|
||||
{Time: parseTimeUTC("2015-10-02 10:20:30")},
|
||||
{Time: parseTimeUTC("2015-10-05 10:20:30")},
|
||||
{Time: parseTimeUTC("2015-10-06 10:20:30")},
|
||||
{Time: parseTimeUTC("2015-10-08 10:20:30")},
|
||||
{Time: parseTimeUTC("2015-10-09 10:20:30")},
|
||||
{Time: parseTimeUTC("2015-10-10 10:20:30")},
|
||||
{Time: parseTimeUTC("2015-10-11 10:20:30")},
|
||||
{Time: parseTimeUTC("2015-10-20 10:20:30")},
|
||||
{Time: parseTimeUTC("2015-10-22 10:20:30")},
|
||||
{Time: parseTimeUTC("2015-10-22 10:20:30")},
|
||||
{Time: parseTimeUTC("2015-10-22 10:20:30"), Tags: []string{"foo", "bar"}},
|
||||
{Time: parseTimeUTC("2015-10-22 10:20:30"), Tags: []string{"foo", "bar"}},
|
||||
{Time: parseTimeUTC("2015-10-22 10:20:30"), Tags: []string{"foo", "bar"}, Paths: []string{"path1", "path2"}},
|
||||
{Time: parseTimeUTC("2015-11-08 10:20:30")},
|
||||
{Time: parseTimeUTC("2015-11-10 10:20:30")},
|
||||
{Time: parseTimeUTC("2015-11-12 10:20:30")},
|
||||
{Time: parseTimeUTC("2015-11-13 10:20:30")},
|
||||
{Time: parseTimeUTC("2015-11-13 10:20:30.1")},
|
||||
{Time: parseTimeUTC("2015-11-15 10:20:30")},
|
||||
{Time: parseTimeUTC("2015-11-18 10:20:30")},
|
||||
{Time: parseTimeUTC("2015-11-20 10:20:30")},
|
||||
{Time: parseTimeUTC("2015-11-21 10:20:30")},
|
||||
{Time: parseTimeUTC("2015-11-22 10:20:30")},
|
||||
{Time: parseTimeUTC("2016-01-01 01:02:03")},
|
||||
{Time: parseTimeUTC("2016-01-01 01:03:03")},
|
||||
{Time: parseTimeUTC("2016-01-01 07:08:03")},
|
||||
{Time: parseTimeUTC("2016-01-03 07:02:03")},
|
||||
{Time: parseTimeUTC("2016-01-04 10:23:03")},
|
||||
{Time: parseTimeUTC("2016-01-04 11:23:03")},
|
||||
{Time: parseTimeUTC("2016-01-04 12:23:03")},
|
||||
{Time: parseTimeUTC("2016-01-04 12:24:03")},
|
||||
{Time: parseTimeUTC("2016-01-04 12:28:03")},
|
||||
{Time: parseTimeUTC("2016-01-04 12:30:03")},
|
||||
{Time: parseTimeUTC("2016-01-04 16:23:03")},
|
||||
{Time: parseTimeUTC("2016-01-05 09:02:03")},
|
||||
{Time: parseTimeUTC("2016-01-06 08:02:03")},
|
||||
{Time: parseTimeUTC("2016-01-07 10:02:03")},
|
||||
{Time: parseTimeUTC("2016-01-08 20:02:03")},
|
||||
{Time: parseTimeUTC("2016-01-09 21:02:03")},
|
||||
{Time: parseTimeUTC("2016-01-12 21:02:03")},
|
||||
{Time: parseTimeUTC("2016-01-12 21:08:03")},
|
||||
{Time: parseTimeUTC("2016-01-18 12:02:03")},
|
||||
}
|
||||
|
||||
t.Logf("test %d: returned keep %v, remove %v (of %v) expired snapshots for policy %v",
|
||||
i, len(keep), len(remove), len(testExpireSnapshots), p)
|
||||
var tests = []restic.ExpirePolicy{
|
||||
{},
|
||||
{Last: 10},
|
||||
{Last: 15},
|
||||
{Last: 99},
|
||||
{Last: 200},
|
||||
{Hourly: 20},
|
||||
{Daily: 3},
|
||||
{Daily: 10},
|
||||
{Daily: 30},
|
||||
{Last: 5, Daily: 5},
|
||||
{Last: 2, Daily: 10},
|
||||
{Weekly: 2},
|
||||
{Weekly: 4},
|
||||
{Daily: 3, Weekly: 4},
|
||||
{Monthly: 6},
|
||||
{Daily: 2, Weekly: 2, Monthly: 6},
|
||||
{Yearly: 10},
|
||||
{Daily: 7, Weekly: 2, Monthly: 3, Yearly: 10},
|
||||
{Tags: []restic.TagList{{"foo"}}},
|
||||
{Tags: []restic.TagList{{"foo", "bar"}}},
|
||||
{Tags: []restic.TagList{{"foo"}, {"bar"}}},
|
||||
{Within: parseDuration("1d")},
|
||||
{Within: parseDuration("2d")},
|
||||
{Within: parseDuration("7d")},
|
||||
{Within: parseDuration("1m")},
|
||||
{Within: parseDuration("1m14d")},
|
||||
{Within: parseDuration("1y1d1m")},
|
||||
}
|
||||
|
||||
if len(keep)+len(remove) != len(testExpireSnapshots) {
|
||||
t.Errorf("test %d: len(keep)+len(remove) = %d != len(testExpireSnapshots) = %d",
|
||||
i, len(keep)+len(remove), len(testExpireSnapshots))
|
||||
}
|
||||
for i, p := range tests {
|
||||
t.Run("", func(t *testing.T) {
|
||||
keep, remove := restic.ApplyPolicy(testExpireSnapshots, p)
|
||||
|
||||
if p.Sum() > 0 && len(keep) > p.Sum() {
|
||||
t.Errorf("not enough snapshots removed: policy allows %v snapshots to remain, but ended up with %v",
|
||||
p.Sum(), len(keep))
|
||||
}
|
||||
t.Logf("returned keep %v, remove %v (of %v) expired snapshots for policy %v",
|
||||
len(keep), len(remove), len(testExpireSnapshots), p)
|
||||
|
||||
for _, sn := range keep {
|
||||
t.Logf("test %d: keep snapshot at %v %s\n", i, sn.Time, sn.Tags)
|
||||
}
|
||||
for _, sn := range remove {
|
||||
t.Logf("test %d: forget snapshot at %v %s\n", i, sn.Time, sn.Tags)
|
||||
}
|
||||
if len(keep)+len(remove) != len(testExpireSnapshots) {
|
||||
t.Errorf("len(keep)+len(remove) = %d != len(testExpireSnapshots) = %d",
|
||||
len(keep)+len(remove), len(testExpireSnapshots))
|
||||
}
|
||||
|
||||
goldenFilename := filepath.Join("testdata", fmt.Sprintf("policy_keep_snapshots_%d", i))
|
||||
if p.Sum() > 0 && len(keep) > p.Sum() {
|
||||
t.Errorf("not enough snapshots removed: policy allows %v snapshots to remain, but ended up with %v",
|
||||
p.Sum(), len(keep))
|
||||
}
|
||||
|
||||
if *updateGoldenFiles {
|
||||
buf, err := json.MarshalIndent(keep, "", " ")
|
||||
for _, sn := range keep {
|
||||
t.Logf(" keep snapshot at %v %s", sn.Time, sn.Tags)
|
||||
}
|
||||
for _, sn := range remove {
|
||||
t.Logf(" forget snapshot at %v %s", sn.Time, sn.Tags)
|
||||
}
|
||||
|
||||
goldenFilename := filepath.Join("testdata", fmt.Sprintf("policy_keep_snapshots_%d", i))
|
||||
|
||||
if *updateGoldenFiles {
|
||||
buf, err := json.MarshalIndent(keep, "", " ")
|
||||
if err != nil {
|
||||
t.Fatalf("error marshaling result: %v", err)
|
||||
}
|
||||
|
||||
if err = ioutil.WriteFile(goldenFilename, buf, 0644); err != nil {
|
||||
t.Fatalf("unable to update golden file: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
buf, err := ioutil.ReadFile(goldenFilename)
|
||||
if err != nil {
|
||||
t.Fatalf("error marshaling result: %v", err)
|
||||
t.Fatalf("error loading golden file %v: %v", goldenFilename, err)
|
||||
}
|
||||
|
||||
if err = ioutil.WriteFile(goldenFilename, buf, 0644); err != nil {
|
||||
t.Fatalf("unable to update golden file: %v", err)
|
||||
var want restic.Snapshots
|
||||
err = json.Unmarshal(buf, &want)
|
||||
if err != nil {
|
||||
t.Fatalf("error unmarshalling golden file %v: %v", goldenFilename, err)
|
||||
}
|
||||
}
|
||||
|
||||
buf, err := ioutil.ReadFile(goldenFilename)
|
||||
if err != nil {
|
||||
t.Errorf("error loading golden file %v: %v", goldenFilename, err)
|
||||
continue
|
||||
}
|
||||
|
||||
var want restic.Snapshots
|
||||
err = json.Unmarshal(buf, &want)
|
||||
if err != nil {
|
||||
t.Errorf("error unmarshalling golden file %v: %v", goldenFilename, err)
|
||||
continue
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(keep, want) {
|
||||
t.Errorf("test %v: wrong result, want:\n %v\ngot:\n %v", i, want, keep)
|
||||
continue
|
||||
}
|
||||
if !reflect.DeepEqual(keep, want) {
|
||||
t.Fatalf("wrong result, want:\n %v\ngot:\n %v", want, keep)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
97
internal/restic/testdata/policy_keep_snapshots_25
vendored
Normal file
97
internal/restic/testdata/policy_keep_snapshots_25
vendored
Normal file
@ -0,0 +1,97 @@
|
||||
[
|
||||
{
|
||||
"time": "2016-01-18T12:02:03Z",
|
||||
"tree": null,
|
||||
"paths": null
|
||||
},
|
||||
{
|
||||
"time": "2016-01-12T21:08:03Z",
|
||||
"tree": null,
|
||||
"paths": null
|
||||
},
|
||||
{
|
||||
"time": "2016-01-12T21:02:03Z",
|
||||
"tree": null,
|
||||
"paths": null
|
||||
},
|
||||
{
|
||||
"time": "2016-01-09T21:02:03Z",
|
||||
"tree": null,
|
||||
"paths": null
|
||||
},
|
||||
{
|
||||
"time": "2016-01-08T20:02:03Z",
|
||||
"tree": null,
|
||||
"paths": null
|
||||
},
|
||||
{
|
||||
"time": "2016-01-07T10:02:03Z",
|
||||
"tree": null,
|
||||
"paths": null
|
||||
},
|
||||
{
|
||||
"time": "2016-01-06T08:02:03Z",
|
||||
"tree": null,
|
||||
"paths": null
|
||||
},
|
||||
{
|
||||
"time": "2016-01-05T09:02:03Z",
|
||||
"tree": null,
|
||||
"paths": null
|
||||
},
|
||||
{
|
||||
"time": "2016-01-04T16:23:03Z",
|
||||
"tree": null,
|
||||
"paths": null
|
||||
},
|
||||
{
|
||||
"time": "2016-01-04T12:30:03Z",
|
||||
"tree": null,
|
||||
"paths": null
|
||||
},
|
||||
{
|
||||
"time": "2016-01-04T12:28:03Z",
|
||||
"tree": null,
|
||||
"paths": null
|
||||
},
|
||||
{
|
||||
"time": "2016-01-04T12:24:03Z",
|
||||
"tree": null,
|
||||
"paths": null
|
||||
},
|
||||
{
|
||||
"time": "2016-01-04T12:23:03Z",
|
||||
"tree": null,
|
||||
"paths": null
|
||||
},
|
||||
{
|
||||
"time": "2016-01-04T11:23:03Z",
|
||||
"tree": null,
|
||||
"paths": null
|
||||
},
|
||||
{
|
||||
"time": "2016-01-04T10:23:03Z",
|
||||
"tree": null,
|
||||
"paths": null
|
||||
},
|
||||
{
|
||||
"time": "2016-01-03T07:02:03Z",
|
||||
"tree": null,
|
||||
"paths": null
|
||||
},
|
||||
{
|
||||
"time": "2016-01-01T07:08:03Z",
|
||||
"tree": null,
|
||||
"paths": null
|
||||
},
|
||||
{
|
||||
"time": "2016-01-01T01:03:03Z",
|
||||
"tree": null,
|
||||
"paths": null
|
||||
},
|
||||
{
|
||||
"time": "2016-01-01T01:02:03Z",
|
||||
"tree": null,
|
||||
"paths": null
|
||||
}
|
||||
]
|
332
internal/restic/testdata/policy_keep_snapshots_26
vendored
Normal file
332
internal/restic/testdata/policy_keep_snapshots_26
vendored
Normal file
@ -0,0 +1,332 @@
|
||||
[
|
||||
{
|
||||
"time": "2016-01-18T12:02:03Z",
|
||||
"tree": null,
|
||||
"paths": null
|
||||
},
|
||||
{
|
||||
"time": "2016-01-12T21:08:03Z",
|
||||
"tree": null,
|
||||
"paths": null
|
||||
},
|
||||
{
|
||||
"time": "2016-01-12T21:02:03Z",
|
||||
"tree": null,
|
||||
"paths": null
|
||||
},
|
||||
{
|
||||
"time": "2016-01-09T21:02:03Z",
|
||||
"tree": null,
|
||||
"paths": null
|
||||
},
|
||||
{
|
||||
"time": "2016-01-08T20:02:03Z",
|
||||
"tree": null,
|
||||
"paths": null
|
||||
},
|
||||
{
|
||||
"time": "2016-01-07T10:02:03Z",
|
||||
"tree": null,
|
||||
"paths": null
|
||||
},
|
||||
{
|
||||
"time": "2016-01-06T08:02:03Z",
|
||||
"tree": null,
|
||||
"paths": null
|
||||
},
|
||||
{
|
||||
"time": "2016-01-05T09:02:03Z",
|
||||
"tree": null,
|
||||
"paths": null
|
||||
},
|
||||
{
|
||||
"time": "2016-01-04T16:23:03Z",
|
||||
"tree": null,
|
||||
"paths": null
|
||||
},
|
||||
{
|
||||
"time": "2016-01-04T12:30:03Z",
|
||||
"tree": null,
|
||||
"paths": null
|
||||
},
|
||||
{
|
||||
"time": "2016-01-04T12:28:03Z",
|
||||
"tree": null,
|
||||
"paths": null
|
||||
},
|
||||
{
|
||||
"time": "2016-01-04T12:24:03Z",
|
||||
"tree": null,
|
||||
"paths": null
|
||||
},
|
||||
{
|
||||
"time": "2016-01-04T12:23:03Z",
|
||||
"tree": null,
|
||||
"paths": null
|
||||
},
|
||||
{
|
||||
"time": "2016-01-04T11:23:03Z",
|
||||
"tree": null,
|
||||
"paths": null
|
||||
},
|
||||
{
|
||||
"time": "2016-01-04T10:23:03Z",
|
||||
"tree": null,
|
||||
"paths": null
|
||||
},
|
||||
{
|
||||
"time": "2016-01-03T07:02:03Z",
|
||||
"tree": null,
|
||||
"paths": null
|
||||
},
|
||||
{
|
||||
"time": "2016-01-01T07:08:03Z",
|
||||
"tree": null,
|
||||
"paths": null
|
||||
},
|
||||
{
|
||||
"time": "2016-01-01T01:03:03Z",
|
||||
"tree": null,
|
||||
"paths": null
|
||||
},
|
||||
{
|
||||
"time": "2016-01-01T01:02:03Z",
|
||||
"tree": null,
|
||||
"paths": null
|
||||
},
|
||||
{
|
||||
"time": "2015-11-22T10:20:30Z",
|
||||
"tree": null,
|
||||
"paths": null
|
||||
},
|
||||
{
|
||||
"time": "2015-11-21T10:20:30Z",
|
||||
"tree": null,
|
||||
"paths": null
|
||||
},
|
||||
{
|
||||
"time": "2015-11-20T10:20:30Z",
|
||||
"tree": null,
|
||||
"paths": null
|
||||
},
|
||||
{
|
||||
"time": "2015-11-18T10:20:30Z",
|
||||
"tree": null,
|
||||
"paths": null
|
||||
},
|
||||
{
|
||||
"time": "2015-11-15T10:20:30Z",
|
||||
"tree": null,
|
||||
"paths": null
|
||||
},
|
||||
{
|
||||
"time": "2015-11-13T10:20:30.1Z",
|
||||
"tree": null,
|
||||
"paths": null
|
||||
},
|
||||
{
|
||||
"time": "2015-11-13T10:20:30Z",
|
||||
"tree": null,
|
||||
"paths": null
|
||||
},
|
||||
{
|
||||
"time": "2015-11-12T10:20:30Z",
|
||||
"tree": null,
|
||||
"paths": null
|
||||
},
|
||||
{
|
||||
"time": "2015-11-10T10:20:30Z",
|
||||
"tree": null,
|
||||
"paths": null
|
||||
},
|
||||
{
|
||||
"time": "2015-11-08T10:20:30Z",
|
||||
"tree": null,
|
||||
"paths": null
|
||||
},
|
||||
{
|
||||
"time": "2015-10-22T10:20:30Z",
|
||||
"tree": null,
|
||||
"paths": null
|
||||
},
|
||||
{
|
||||
"time": "2015-10-22T10:20:30Z",
|
||||
"tree": null,
|
||||
"paths": [
|
||||
"path1",
|
||||
"path2"
|
||||
],
|
||||
"tags": [
|
||||
"foo",
|
||||
"bar"
|
||||
]
|
||||
},
|
||||
{
|
||||
"time": "2015-10-22T10:20:30Z",
|
||||
"tree": null,
|
||||
"paths": null,
|
||||
"tags": [
|
||||
"foo",
|
||||
"bar"
|
||||
]
|
||||
},
|
||||
{
|
||||
"time": "2015-10-22T10:20:30Z",
|
||||
"tree": null,
|
||||
"paths": null
|
||||
},
|
||||
{
|
||||
"time": "2015-10-22T10:20:30Z",
|
||||
"tree": null,
|
||||
"paths": null,
|
||||
"tags": [
|
||||
"foo",
|
||||
"bar"
|
||||
]
|
||||
},
|
||||
{
|
||||
"time": "2015-10-20T10:20:30Z",
|
||||
"tree": null,
|
||||
"paths": null
|
||||
},
|
||||
{
|
||||
"time": "2015-10-11T10:20:30Z",
|
||||
"tree": null,
|
||||
"paths": null
|
||||
},
|
||||
{
|
||||
"time": "2015-10-10T10:20:30Z",
|
||||
"tree": null,
|
||||
"paths": null
|
||||
},
|
||||
{
|
||||
"time": "2015-10-09T10:20:30Z",
|
||||
"tree": null,
|
||||
"paths": null
|
||||
},
|
||||
{
|
||||
"time": "2015-10-08T10:20:30Z",
|
||||
"tree": null,
|
||||
"paths": null
|
||||
},
|
||||
{
|
||||
"time": "2015-10-06T10:20:30Z",
|
||||
"tree": null,
|
||||
"paths": null
|
||||
},
|
||||
{
|
||||
"time": "2015-10-05T10:20:30Z",
|
||||
"tree": null,
|
||||
"paths": null
|
||||
},
|
||||
{
|
||||
"time": "2015-10-02T10:20:30Z",
|
||||
"tree": null,
|
||||
"paths": null
|
||||
},
|
||||
{
|
||||
"time": "2015-10-01T10:20:30Z",
|
||||
"tree": null,
|
||||
"paths": null
|
||||
},
|
||||
{
|
||||
"time": "2015-09-22T10:20:30Z",
|
||||
"tree": null,
|
||||
"paths": null
|
||||
},
|
||||
{
|
||||
"time": "2015-09-20T10:20:30Z",
|
||||
"tree": null,
|
||||
"paths": null
|
||||
},
|
||||
{
|
||||
"time": "2015-09-11T10:20:30Z",
|
||||
"tree": null,
|
||||
"paths": null
|
||||
},
|
||||
{
|
||||
"time": "2015-09-10T10:20:30Z",
|
||||
"tree": null,
|
||||
"paths": null
|
||||
},
|
||||
{
|
||||
"time": "2015-09-09T10:20:30Z",
|
||||
"tree": null,
|
||||
"paths": null
|
||||
},
|
||||
{
|
||||
"time": "2015-09-08T10:20:30Z",
|
||||
"tree": null,
|
||||
"paths": null
|
||||
},
|
||||
{
|
||||
"time": "2015-09-06T10:20:30Z",
|
||||
"tree": null,
|
||||
"paths": null
|
||||
},
|
||||
{
|
||||
"time": "2015-09-05T10:20:30Z",
|
||||
"tree": null,
|
||||
"paths": null
|
||||
},
|
||||
{
|
||||
"time": "2015-09-02T10:20:30Z",
|
||||
"tree": null,
|
||||
"paths": null
|
||||
},
|
||||
{
|
||||
"time": "2015-09-01T10:20:30Z",
|
||||
"tree": null,
|
||||
"paths": null
|
||||
},
|
||||
{
|
||||
"time": "2015-08-22T10:20:30Z",
|
||||
"tree": null,
|
||||
"paths": null
|
||||
},
|
||||
{
|
||||
"time": "2015-08-21T10:20:30Z",
|
||||
"tree": null,
|
||||
"paths": null
|
||||
},
|
||||
{
|
||||
"time": "2015-08-20T10:20:30Z",
|
||||
"tree": null,
|
||||
"paths": null
|
||||
},
|
||||
{
|
||||
"time": "2015-08-18T10:20:30Z",
|
||||
"tree": null,
|
||||
"paths": null
|
||||
},
|
||||
{
|
||||
"time": "2015-08-15T10:20:30Z",
|
||||
"tree": null,
|
||||
"paths": null
|
||||
},
|
||||
{
|
||||
"time": "2015-08-13T10:20:30.1Z",
|
||||
"tree": null,
|
||||
"paths": null
|
||||
},
|
||||
{
|
||||
"time": "2015-08-13T10:20:30Z",
|
||||
"tree": null,
|
||||
"paths": null
|
||||
},
|
||||
{
|
||||
"time": "2015-08-12T10:20:30Z",
|
||||
"tree": null,
|
||||
"paths": null
|
||||
},
|
||||
{
|
||||
"time": "2015-08-10T10:20:30Z",
|
||||
"tree": null,
|
||||
"paths": null
|
||||
},
|
||||
{
|
||||
"time": "2015-08-08T10:20:30Z",
|
||||
"tree": null,
|
||||
"paths": null
|
||||
}
|
||||
]
|
Loading…
Reference in New Issue
Block a user