@@ -97,16 +97,40 @@ var _ = Describe("RestoreManager Test", func() {
9797
9898 })
9999
100- mockBackupForRestore := func (testCtx * testutil.TestContext , actionSetName , backupPVCName string , mockBackupCompleted , useVolumeSnapshotBackup bool ) * dpv1alpha1.Backup {
101- backup := testdp .NewFakeBackup (testCtx , nil )
100+ mockBackupForRestore := func (
101+ testCtx * testutil.TestContext , actionSetName , backupPVCName string ,
102+ mockBackupCompleted , useVolumeSnapshotBackup bool ,
103+ backupType dpv1alpha1.BackupType ,
104+ startTime , endTime string ,
105+ backupName string ,
106+ ) * dpv1alpha1.Backup {
107+ backup := testdp .NewFakeBackup (testCtx , func (backup * dpv1alpha1.Backup ) {
108+ if backup .Labels == nil {
109+ backup .Labels = make (map [string ]string )
110+ }
111+ backup .Labels [dptypes .BackupTypeLabelKey ] = string (backupType )
112+ backup .Labels [dptypes .BackupPolicyLabelKey ] = testdp .BackupPolicyName
113+ if backupName != "" {
114+ backup .Name = backupName
115+ }
116+ })
102117 if mockBackupCompleted {
103118 // then mock backup to completed
104119 backupMethodName := testdp .BackupMethodName
105120 if useVolumeSnapshotBackup {
106121 backupMethodName = testdp .VSBackupMethodName
107122 }
108123 Expect (testapps .ChangeObjStatus (testCtx , backup , func () {
109- endTime , _ := time .Parse (time .RFC3339 , "2023-01-01T10:00:00Z" )
124+ var end * metav1.Time
125+ if endTime != "" {
126+ endTime , _ := time .Parse (time .RFC3339 , endTime )
127+ end = & metav1.Time {Time : endTime }
128+ }
129+ var start * metav1.Time
130+ if startTime != "" {
131+ startTime , _ := time .Parse (time .RFC3339 , startTime )
132+ start = & metav1.Time {Time : startTime }
133+ }
110134 backup .Status .Phase = dpv1alpha1 .BackupPhaseCompleted
111135 backup .Status .PersistentVolumeClaimName = backupPVCName
112136 testdp .MockBackupStatusTarget (backup , dpv1alpha1 .PodSelectionStrategyAny )
@@ -115,7 +139,8 @@ var _ = Describe("RestoreManager Test", func() {
115139 }
116140 backup .Status .TimeRange = & dpv1alpha1.BackupTimeRange {
117141 TimeZone : "+08:00" ,
118- End : & metav1.Time {Time : endTime },
142+ Start : start ,
143+ End : end ,
119144 }
120145 testdp .MockBackupStatusMethod (backup , backupMethodName , testdp .DataVolumeName , actionSetName )
121146 })).Should (Succeed ())
@@ -125,7 +150,7 @@ var _ = Describe("RestoreManager Test", func() {
125150
126151 initResources := func (reqCtx intctrlutil.RequestCtx , _ int , useVolumeSnapshot bool , change func (f * testdp.MockRestoreFactory )) (* RestoreManager , * BackupActionSet ) {
127152 By ("create a completed backup" )
128- backup := mockBackupForRestore (& testCtx , actionSet .Name , testdp .BackupPVCName , true , useVolumeSnapshot )
153+ backup := mockBackupForRestore (& testCtx , actionSet .Name , testdp .BackupPVCName , true , useVolumeSnapshot , dpv1alpha1 . BackupTypeFull , "" , "2023-01-01T10:00:00Z" , "" )
129154
130155 schedulingSpec := dpv1alpha1.SchedulingSpec {
131156 NodeName : nodeName ,
@@ -358,6 +383,57 @@ var _ = Describe("RestoreManager Test", func() {
358383 })).Should (Succeed ())
359384 testPostReady (false )
360385 })
386+
387+ Context ("BuildContinuousRestoreManager" , func () {
388+ It ("respects UnifyFullAndContinuousRestore annotation" , func () {
389+ By ("create a continuous backup" )
390+ continuousBackup := mockBackupForRestore (
391+ & testCtx , actionSet .Name , testdp .BackupPVCName , true , false , dpv1alpha1 .BackupTypeContinuous ,
392+ "2023-01-01T09:00:00Z" , "2023-01-01T12:00:00Z" , "test-backup-continuous" ,
393+ )
394+
395+ By ("create a completed backup" )
396+ _ = mockBackupForRestore (& testCtx , actionSet .Name , testdp .BackupPVCName , true , false , dpv1alpha1 .BackupTypeFull , "" , "2023-01-01T10:00:00Z" , "" )
397+
398+ schedulingSpec := dpv1alpha1.SchedulingSpec {
399+ NodeName : nodeName ,
400+ }
401+
402+ By ("create restore" )
403+ restore := testdp .NewRestoreFactory (testCtx .DefaultNamespace , testdp .RestoreName ).
404+ SetBackup (continuousBackup .Name , testCtx .DefaultNamespace ).
405+ SetSchedulingSpec (schedulingSpec ).
406+ Create (& testCtx ).
407+ SetRestoreTime ("2023-01-01T11:30:00Z" ).
408+ Get ()
409+
410+ By ("create restore manager" )
411+ reqCtx := getReqCtx ()
412+ restoreMGR := NewRestoreManager (restore , recorder , k8sClient .Scheme (), k8sClient )
413+ backupSet , err := restoreMGR .GetBackupActionSetByNamespaced (reqCtx , k8sClient , continuousBackup .Name , testCtx .DefaultNamespace )
414+ Expect (err ).ShouldNot (HaveOccurred ())
415+
416+ Expect (restoreMGR .BuildContinuousRestoreManager (reqCtx , k8sClient , * backupSet )).Should (Succeed ())
417+ Expect (restoreMGR .PostReadyBackupSets ).Should (HaveLen (2 ))
418+
419+ By ("set UnifyFullAndContinuousRestore annotation" )
420+ Eventually (testapps .GetAndChangeObj (& testCtx , client .ObjectKeyFromObject (actionSet ), func (actionset * dpv1alpha1.ActionSet ) {
421+ if actionset .Annotations == nil {
422+ actionset .Annotations = make (map [string ]string )
423+ }
424+ actionset .Annotations [constant .SkipBaseBackupRestoreInPitrAnnotationKey ] = "true"
425+ })).Should (Succeed ())
426+
427+ By ("check length of backupsets" )
428+ restoreMGR = NewRestoreManager (restore , recorder , k8sClient .Scheme (), k8sClient )
429+ backupSet , err = restoreMGR .GetBackupActionSetByNamespaced (reqCtx , k8sClient , continuousBackup .Name , testCtx .DefaultNamespace )
430+ Expect (err ).ShouldNot (HaveOccurred ())
431+
432+ Expect (restoreMGR .BuildContinuousRestoreManager (reqCtx , k8sClient , * backupSet )).Should (Succeed ())
433+ Expect (restoreMGR .PostReadyBackupSets ).Should (HaveLen (1 ))
434+
435+ })
436+ })
361437 })
362438
363439})
0 commit comments