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 committed Jun 25, 2023
1 parent d9c892f commit 9d9d12e
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 9d9d12e

Please sign in to comment.