@@ -417,27 +417,35 @@ var _ = Describe("RestoreManager Test", func() {
417417 })
418418
419419 Context ("BuildContinuousRestoreManager" , func () {
420- It ("respects UnifyFullAndContinuousRestore annotation" , func () {
421- By ("create a continuous backup" )
420+ const (
421+ continuousBackupStartTime = "2023-01-01T09:00:00Z"
422+ continuousBackupEndTime = "2023-01-01T12:00:00Z"
423+ )
424+
425+ createContinuousBackupAndRestore := func (restoreTime string ) (* dpv1alpha1.Backup , * dpv1alpha1.Restore ) {
422426 continuousBackup := mockBackupForRestore (
423427 & testCtx , actionSet .Name , testdp .BackupPVCName , true , false , dpv1alpha1 .BackupTypeContinuous ,
424- "2023-01-01T09:00:00Z" , "2023-01-01T12:00:00Z" , "test-backup-continuous" ,
428+ continuousBackupStartTime , continuousBackupEndTime , "test-backup-continuous" ,
425429 )
426430
427- By ("create a completed backup" )
428- _ = mockBackupForRestore (& testCtx , actionSet .Name , testdp .BackupPVCName , true , false , dpv1alpha1 .BackupTypeFull , "" , "2023-01-01T10:00:00Z" , "" )
429-
430431 schedulingSpec := dpv1alpha1.SchedulingSpec {
431432 NodeName : nodeName ,
432433 }
433434
434- By ("create restore" )
435435 restore := testdp .NewRestoreFactory (testCtx .DefaultNamespace , testdp .RestoreName ).
436436 SetBackup (continuousBackup .Name , testCtx .DefaultNamespace ).
437437 SetSchedulingSpec (schedulingSpec ).
438438 Create (& testCtx ).
439- SetRestoreTime ("2023-01-01T11:30:00Z" ).
439+ SetRestoreTime (restoreTime ).
440440 Get ()
441+ return continuousBackup , restore
442+ }
443+
444+ It ("respects UnifyFullAndContinuousRestore annotation" , func () {
445+ By ("create a completed backup" )
446+ _ = mockBackupForRestore (& testCtx , actionSet .Name , testdp .BackupPVCName , true , false , dpv1alpha1 .BackupTypeFull , "" , "2023-01-01T10:00:00Z" , "" )
447+
448+ continuousBackup , restore := createContinuousBackupAndRestore ("2023-01-01T11:30:00Z" )
441449
442450 By ("create restore manager" )
443451 reqCtx := getReqCtx ()
@@ -465,6 +473,60 @@ var _ = Describe("RestoreManager Test", func() {
465473 Expect (restoreMGR .PostReadyBackupSets ).Should (HaveLen (1 ))
466474
467475 })
476+
477+ When ("restoreTime is at boundary values" , func () {
478+ It ("should fail when restoreTime equals backup start time" , func () {
479+ _ = mockBackupForRestore (& testCtx , actionSet .Name , testdp .BackupPVCName , true , false , dpv1alpha1 .BackupTypeFull , "" , "2023-01-01T09:00:00Z" , "" )
480+ continuousBackup , restore := createContinuousBackupAndRestore (continuousBackupStartTime )
481+
482+ reqCtx := getReqCtx ()
483+ restoreMGR := NewRestoreManager (restore , recorder , k8sClient .Scheme (), k8sClient )
484+ backupSet , err := restoreMGR .GetBackupActionSetByNamespaced (reqCtx , k8sClient , continuousBackup .Name , testCtx .DefaultNamespace )
485+ Expect (err ).ShouldNot (HaveOccurred ())
486+
487+ _ = restoreMGR .BuildContinuousRestoreManager (reqCtx , k8sClient , * backupSet )
488+ Expect (restoreMGR .PostReadyBackupSets ).Should (HaveLen (2 ))
489+ })
490+
491+ It ("should fail when restoreTime equals backup end time" , func () {
492+ _ = mockBackupForRestore (& testCtx , actionSet .Name , testdp .BackupPVCName , true , false , dpv1alpha1 .BackupTypeFull , "" , "2023-01-01T10:00:00Z" , "" )
493+ continuousBackup , restore := createContinuousBackupAndRestore (continuousBackupEndTime )
494+
495+ reqCtx := getReqCtx ()
496+ restoreMGR := NewRestoreManager (restore , recorder , k8sClient .Scheme (), k8sClient )
497+ backupSet , err := restoreMGR .GetBackupActionSetByNamespaced (reqCtx , k8sClient , continuousBackup .Name , testCtx .DefaultNamespace )
498+ Expect (err ).ShouldNot (HaveOccurred ())
499+
500+ _ = restoreMGR .BuildContinuousRestoreManager (reqCtx , k8sClient , * backupSet )
501+ Expect (restoreMGR .PostReadyBackupSets ).Should (HaveLen (2 ))
502+ })
503+
504+ It ("should failed when restoreTime is before backup start time" , func () {
505+ _ = mockBackupForRestore (& testCtx , actionSet .Name , testdp .BackupPVCName , true , false , dpv1alpha1 .BackupTypeFull , "" , "2023-01-01T10:00:00Z" , "" )
506+ continuousBackup , restore := createContinuousBackupAndRestore ("2023-01-01T08:00:00Z" )
507+
508+ reqCtx := getReqCtx ()
509+ restoreMGR := NewRestoreManager (restore , recorder , k8sClient .Scheme (), k8sClient )
510+ backupSet , err := restoreMGR .GetBackupActionSetByNamespaced (reqCtx , k8sClient , continuousBackup .Name , testCtx .DefaultNamespace )
511+ Expect (err ).ShouldNot (HaveOccurred ())
512+
513+ err = restoreMGR .BuildContinuousRestoreManager (reqCtx , k8sClient , * backupSet )
514+ Expect (err ).Should (HaveOccurred ())
515+ })
516+
517+ It ("should failed when restoreTime is after backup end time" , func () {
518+ _ = mockBackupForRestore (& testCtx , actionSet .Name , testdp .BackupPVCName , true , false , dpv1alpha1 .BackupTypeFull , "" , "2023-01-01T10:00:00Z" , "" )
519+ continuousBackup , restore := createContinuousBackupAndRestore ("2023-01-01T13:00:00Z" )
520+
521+ reqCtx := getReqCtx ()
522+ restoreMGR := NewRestoreManager (restore , recorder , k8sClient .Scheme (), k8sClient )
523+ backupSet , err := restoreMGR .GetBackupActionSetByNamespaced (reqCtx , k8sClient , continuousBackup .Name , testCtx .DefaultNamespace )
524+ Expect (err ).ShouldNot (HaveOccurred ())
525+
526+ err = restoreMGR .BuildContinuousRestoreManager (reqCtx , k8sClient , * backupSet )
527+ Expect (err ).Should (HaveOccurred ())
528+ })
529+ })
468530 })
469531 })
470532
0 commit comments