Skip to content

Commit

Permalink
bug that delete the newest backups has been fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexAkulov committed May 21, 2019
1 parent 28e48bc commit 1a10c79
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func copyFile(srcFile string, dstFile string) error {
func GetBackupsToDelete(backups []Backup, keep int) []Backup {
if len(backups) > keep {
sort.SliceStable(backups, func(i, j int) bool {
return backups[i].Date.Before(backups[j].Date)
return backups[i].Date.After(backups[j].Date)
})
return backups[keep:]
}
Expand Down
6 changes: 3 additions & 3 deletions utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ func timeParse(s string) time.Time {
func TestGetBackupsToDelete(t *testing.T) {
testData := []Backup{
Backup{Name: "three", Date: timeParse("2019-03-28T19-50-12")},
Backup{Name: "one", Date: timeParse("2019-01-28T19-50-12")},
Backup{Name: "five", Date: timeParse("2019-05-28T19-50-12")},
Backup{Name: "two", Date: timeParse("2019-02-28T19-50-12")},
Backup{Name: "one", Date: timeParse("2019-01-28T19-50-12")},
Backup{Name: "four", Date: timeParse("2019-04-28T19-50-12")},
}
expectedData := []Backup{
Backup{Name: "four", Date: timeParse("2019-04-28T19-50-12")},
Backup{Name: "five", Date: timeParse("2019-05-28T19-50-12")},
Backup{Name: "two", Date: timeParse("2019-02-28T19-50-12")},
Backup{Name: "one", Date: timeParse("2019-01-28T19-50-12")},
}
assert.Equal(t, expectedData, GetBackupsToDelete(testData, 3))
assert.Equal(t, []Backup{}, GetBackupsToDelete([]Backup{testData[0]}, 3))
Expand Down

0 comments on commit 1a10c79

Please sign in to comment.