Skip to content

Commit

Permalink
*: fix unit test case
Browse files Browse the repository at this point in the history
Signed-off-by: BornChanger <[email protected]>
  • Loading branch information
BornChanger authored and ti-chi-bot committed Jul 4, 2023
1 parent 129615b commit 1231bf6
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions pkg/fedvolumebackup/backupschedule/backup_schedule_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,11 +345,9 @@ func (bm *backupScheduleManager) backupGCByMaxBackups(vbs *v1alpha1.VolumeBackup
return
}

//sort.Sort(byCreateTimeDesc(backupsList))
ascBackups := sortSnapshotBackups(backupsList)

sort.Sort(byCreateTimeDesc(backupsList))
var deleteCount int
for i, backup := range ascBackups {
for i, backup := range backupsList {
if i < int(*vbs.Spec.MaxBackups) {
continue
}
Expand All @@ -362,7 +360,7 @@ func (bm *backupScheduleManager) backupGCByMaxBackups(vbs *v1alpha1.VolumeBackup
klog.Infof("backup schedule %s/%s gc backup %s success", ns, bsName, backup.GetName())
}

if deleteCount == len(ascBackups) && deleteCount > 0 {
if deleteCount == len(backupsList) && deleteCount > 0 {
// All backups have been deleted, so the last backup information in the backupSchedule should be reset
bm.resetLastBackup(vbs)
}
Expand All @@ -374,6 +372,14 @@ func (bm *backupScheduleManager) resetLastBackup(vbs *v1alpha1.VolumeBackupSched
vbs.Status.AllBackupCleanTime = &metav1.Time{Time: bm.now()}
}

type byCreateTimeDesc []*v1alpha1.VolumeBackup

func (b byCreateTimeDesc) Len() int { return len(b) }
func (b byCreateTimeDesc) Swap(i, j int) { b[i], b[j] = b[j], b[i] }
func (b byCreateTimeDesc) Less(i, j int) bool {
return b[j].ObjectMeta.CreationTimestamp.Before(&b[i].ObjectMeta.CreationTimestamp)
}

var _ fedvolumebackup.BackupScheduleManager = &backupScheduleManager{}

type FakeBackupScheduleManager struct {
Expand Down

0 comments on commit 1231bf6

Please sign in to comment.