2
2
mirror of https://github.com/octoleo/restic.git synced 2024-12-23 03:18:55 +00:00

Do not use singleton counter.

Revert change for running the numbered tests as subtests.
This commit is contained in:
Pauline Middelink 2017-05-15 08:53:59 +02:00
parent 103a491ac0
commit 7fffd408af
15 changed files with 71 additions and 74 deletions

View File

@ -789,7 +789,7 @@ hours/days/weeks/months/years which have a snapshot, so those without a
snapshot are ignored.
All snapshots are evaluated counted against all matching keep-* counts. A
single snapshot on 30-09-2017 (Sun) will count as a daily, weekly and monthly.
single snapshot on 2017-09-30 (Sun) will count as a daily, weekly and monthly.
Let's explain this with an example: Suppose you have only made a backup
on each Sunday for 12 weeks. Then ``forget --keep-daily 4`` will keep
@ -803,8 +803,8 @@ Another example: Suppose you make daily backups for 100 years. Then
``forget --keep-daily 7 --keep-weekly 5 --keep-monthly 12 --keep-yearly 75``
will keep the most recent 7 daily snapshots, then 4 (remember, 7 dailies
already include a week!) last-day-of-the-weeks and 11 or 12
last-day-of-the-months. (11 or 12 depends if the 5 weeklies cross a month).
And ofcourse 75 last-day-of-the-year snapshots. All other snapshots are
last-day-of-the-months (11 or 12 depends if the 5 weeklies cross a month).
And finally 75 last-day-of-the-year snapshots. All other snapshots are
removed.
Autocompletion

View File

@ -77,12 +77,9 @@ func y(d time.Time) int {
return d.Year()
}
var a int
// always retuns a unique number for d.
// always returns a unique number for d.
func always(d time.Time) int {
a++
return a
return int(d.UnixNano())
}
// ApplyPolicy returns the snapshots from list that are to be kept and removed

View File

@ -57,7 +57,7 @@ var testExpireSnapshots = restic.Snapshots{
{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")},
{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")},
@ -77,7 +77,7 @@ var testExpireSnapshots = restic.Snapshots{
{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"), Tags: []string{"bar"}},
{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")},
@ -97,7 +97,7 @@ var testExpireSnapshots = restic.Snapshots{
{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")},
{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")},
@ -117,7 +117,7 @@ var testExpireSnapshots = restic.Snapshots{
{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")},
{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")},
@ -169,53 +169,53 @@ var expireTests = []restic.ExpirePolicy{
func TestApplyPolicy(t *testing.T) {
for i, p := range expireTests {
t.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
keep, remove := restic.ApplyPolicy(testExpireSnapshots, p)
keep, remove := restic.ApplyPolicy(testExpireSnapshots, p)
t.Logf("test %d: returned keep %v, remove %v (of %v) expired snapshots for policy %v",
i, len(keep), len(remove), len(testExpireSnapshots), p)
t.Logf("test %d: returned keep %v, remove %v (of %v) expired snapshots for policy %v",
i, len(keep), len(remove), len(testExpireSnapshots), p)
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))
}
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))
}
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 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))
}
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)
}
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)
}
goldenFilename := filepath.Join("testdata", fmt.Sprintf("policy_keep_snapshots_%d", i))
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 *updateGoldenFiles {
buf, err := json.MarshalIndent(keep, "", " ")
if err != nil {
t.Fatalf("error loading golden file %v: %v", goldenFilename, err)
t.Fatalf("error marshaling result: %v", err)
}
var want restic.Snapshots
err = json.Unmarshal(buf, &want)
if !reflect.DeepEqual(keep, want) {
t.Fatalf("test %v: wrong result, want:\n %v\ngot:\n %v", i, want, keep)
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.Errorf("error loading golden file %v: %v", goldenFilename, err)
continue
}
var want restic.Snapshots
err = json.Unmarshal(buf, &want)
if !reflect.DeepEqual(keep, want) {
t.Errorf("test %v: wrong result, want:\n %v\ngot:\n %v", i, want, keep)
continue
}
}
}

View File

@ -120,7 +120,7 @@
"paths": null
},
{
"time": "2015-11-13T10:20:30Z",
"time": "2015-11-13T10:20:30.1Z",
"tree": null,
"paths": null
},
@ -270,7 +270,7 @@
"paths": null
},
{
"time": "2015-08-13T10:20:30Z",
"time": "2015-08-13T10:20:30.1Z",
"tree": null,
"paths": null
},
@ -324,7 +324,7 @@
]
},
{
"time": "2014-11-13T10:20:30Z",
"time": "2014-11-13T10:20:30.1Z",
"tree": null,
"paths": null,
"tags": [
@ -519,7 +519,7 @@
"paths": null
},
{
"time": "2014-08-13T10:20:30Z",
"time": "2014-08-13T10:20:30.1Z",
"tree": null,
"paths": null
},
@ -543,4 +543,4 @@
"tree": null,
"paths": null
}
]
]

View File

@ -49,4 +49,4 @@
"tree": null,
"paths": null
}
]
]

View File

@ -19,4 +19,4 @@
"tree": null,
"paths": null
}
]
]

View File

@ -34,4 +34,4 @@
"tree": null,
"paths": null
}
]
]

View File

@ -49,4 +49,4 @@
"tree": null,
"paths": null
}
]
]

View File

@ -120,4 +120,4 @@
"foo"
]
}
]
]

View File

@ -8,4 +8,4 @@
"bar"
]
}
]
]

View File

@ -120,7 +120,7 @@
"paths": null
},
{
"time": "2015-11-13T10:20:30Z",
"time": "2015-11-13T10:20:30.1Z",
"tree": null,
"paths": null
},
@ -270,7 +270,7 @@
"paths": null
},
{
"time": "2015-08-13T10:20:30Z",
"time": "2015-08-13T10:20:30.1Z",
"tree": null,
"paths": null
},
@ -324,7 +324,7 @@
]
},
{
"time": "2014-11-13T10:20:30Z",
"time": "2014-11-13T10:20:30.1Z",
"tree": null,
"paths": null,
"tags": [
@ -519,7 +519,7 @@
"paths": null
},
{
"time": "2014-08-13T10:20:30Z",
"time": "2014-08-13T10:20:30.1Z",
"tree": null,
"paths": null
},
@ -543,4 +543,4 @@
"tree": null,
"paths": null
}
]
]

View File

@ -120,7 +120,7 @@
"paths": null
},
{
"time": "2015-11-13T10:20:30Z",
"time": "2015-11-13T10:20:30.1Z",
"tree": null,
"paths": null
},
@ -270,7 +270,7 @@
"paths": null
},
{
"time": "2015-08-13T10:20:30Z",
"time": "2015-08-13T10:20:30.1Z",
"tree": null,
"paths": null
},
@ -324,7 +324,7 @@
]
},
{
"time": "2014-11-13T10:20:30Z",
"time": "2014-11-13T10:20:30.1Z",
"tree": null,
"paths": null,
"tags": [
@ -519,7 +519,7 @@
"paths": null
},
{
"time": "2014-08-13T10:20:30Z",
"time": "2014-08-13T10:20:30.1Z",
"tree": null,
"paths": null
},
@ -543,4 +543,4 @@
"tree": null,
"paths": null
}
]
]

View File

@ -95,7 +95,7 @@
"paths": null
},
{
"time": "2015-11-13T10:20:30Z",
"time": "2015-11-13T10:20:30.1Z",
"tree": null,
"paths": null
}

View File

@ -75,7 +75,7 @@
"paths": null
},
{
"time": "2015-11-13T10:20:30Z",
"time": "2015-11-13T10:20:30.1Z",
"tree": null,
"paths": null
},

View File

@ -29,4 +29,4 @@
"tree": null,
"paths": null
}
]
]