@@ -44,7 +44,7 @@ func TestReconcileVolumeSnapshots(t *testing.T) {
4444 DiscoveryClient : discoveryClient ,
4545 Recorder : recorder ,
4646 }
47- ns := setupNamespace (t , cc )
47+ ns := require . Namespace (t , cc )
4848
4949 // Enable snapshots feature gate
5050 gate := feature .NewGate ()
@@ -368,7 +368,7 @@ func TestReconcileDedicatedSnapshotVolume(t *testing.T) {
368368
369369 t .Run ("SnapshotsDisabledDeletePvc" , func (t * testing.T ) {
370370 // Create cluster without snapshots spec
371- ns := setupNamespace (t , cc )
371+ ns := require . Namespace (t , cc )
372372 cluster := testCluster ()
373373 cluster .Namespace = ns .Name
374374 cluster .ObjectMeta .UID = "the-uid-123"
@@ -425,7 +425,7 @@ func TestReconcileDedicatedSnapshotVolume(t *testing.T) {
425425
426426 t .Run ("SnapshotsEnabledCreatePvcNoBackupNoRestore" , func (t * testing.T ) {
427427 // Create cluster with snapshots enabled
428- ns := setupNamespace (t , cc )
428+ ns := require . Namespace (t , cc )
429429 cluster := testCluster ()
430430 cluster .Namespace = ns .Name
431431 cluster .ObjectMeta .UID = "the-uid-123"
@@ -457,7 +457,7 @@ func TestReconcileDedicatedSnapshotVolume(t *testing.T) {
457457
458458 t .Run ("SnapshotsEnabledBackupExistsCreateRestore" , func (t * testing.T ) {
459459 // Create cluster with snapshots enabled
460- ns := setupNamespace (t , cc )
460+ ns := require . Namespace (t , cc )
461461 cluster := testCluster ()
462462 cluster .Namespace = ns .Name
463463 cluster .ObjectMeta .UID = "the-uid-123"
@@ -521,7 +521,7 @@ func TestReconcileDedicatedSnapshotVolume(t *testing.T) {
521521
522522 t .Run ("SnapshotsEnabledSuccessfulRestoreExists" , func (t * testing.T ) {
523523 // Create cluster with snapshots enabled
524- ns := setupNamespace (t , cc )
524+ ns := require . Namespace (t , cc )
525525 cluster := testCluster ()
526526 cluster .Namespace = ns .Name
527527 cluster .ObjectMeta .UID = "the-uid-123"
@@ -620,7 +620,7 @@ func TestReconcileDedicatedSnapshotVolume(t *testing.T) {
620620
621621 t .Run ("SnapshotsEnabledFailedRestoreExists" , func (t * testing.T ) {
622622 // Create cluster with snapshots enabled
623- ns := setupNamespace (t , cc )
623+ ns := require . Namespace (t , cc )
624624 cluster := testCluster ()
625625 cluster .Namespace = ns .Name
626626 cluster .ObjectMeta .UID = "the-uid-123"
@@ -722,7 +722,7 @@ func TestCreateDedicatedSnapshotVolume(t *testing.T) {
722722 Owner : client .FieldOwner (t .Name ()),
723723 }
724724
725- ns := setupNamespace (t , cc )
725+ ns := require . Namespace (t , cc )
726726 cluster := testCluster ()
727727 cluster .Namespace = ns .Name
728728 cluster .ObjectMeta .UID = "the-uid-123"
@@ -750,7 +750,7 @@ func TestDedicatedSnapshotVolumeRestore(t *testing.T) {
750750 Owner : client .FieldOwner (t .Name ()),
751751 }
752752
753- ns := setupNamespace (t , cc )
753+ ns := require . Namespace (t , cc )
754754 cluster := testCluster ()
755755 cluster .Namespace = ns .Name
756756 cluster .ObjectMeta .UID = "the-uid-123"
@@ -791,7 +791,7 @@ func TestGenerateSnapshotOfDedicatedSnapshotVolume(t *testing.T) {
791791 Client : cc ,
792792 Owner : client .FieldOwner (t .Name ()),
793793 }
794- ns := setupNamespace (t , cc )
794+ ns := require . Namespace (t , cc )
795795
796796 cluster := testCluster ()
797797 cluster .Namespace = ns .Name
@@ -822,7 +822,7 @@ func TestGenerateVolumeSnapshot(t *testing.T) {
822822 Client : cc ,
823823 Owner : client .FieldOwner (t .Name ()),
824824 }
825- ns := setupNamespace (t , cc )
825+ ns := require . Namespace (t , cc )
826826
827827 cluster := testCluster ()
828828 cluster .Namespace = ns .Name
@@ -851,7 +851,7 @@ func TestGetDedicatedSnapshotVolumeRestoreJob(t *testing.T) {
851851 Client : cc ,
852852 Owner : client .FieldOwner (t .Name ()),
853853 }
854- ns := setupNamespace (t , cc )
854+ ns := require . Namespace (t , cc )
855855
856856 cluster := testCluster ()
857857 cluster .Namespace = ns .Name
@@ -906,7 +906,7 @@ func TestGetLatestCompleteBackupJob(t *testing.T) {
906906 Client : cc ,
907907 Owner : client .FieldOwner (t .Name ()),
908908 }
909- ns := setupNamespace (t , cc )
909+ ns := require . Namespace (t , cc )
910910
911911 cluster := testCluster ()
912912 cluster .Namespace = ns .Name
@@ -974,29 +974,23 @@ func TestGetLatestCompleteBackupJob(t *testing.T) {
974974 })
975975
976976 t .Run ("TwoCompleteBackupJobs" , func (t * testing.T ) {
977- currentTime := metav1 .Now ()
978- earlierTime := metav1 .NewTime (currentTime . AddDate (- 1 , 0 , 0 ))
979- assert .Check (t , earlierTime .Before (& currentTime ))
977+ oneYearAgo := metav1 .NewTime ( time . Now (). AddDate ( - 1 , 0 , 0 ) )
978+ twoYearsAgo := metav1 .NewTime (time . Now (). AddDate (- 2 , 0 , 0 ))
979+ assert .Check (t , twoYearsAgo .Before (& oneYearAgo ))
980980
981981 job1 := testBackupJob (cluster , "backup-job-two-complete-1" )
982982 job1 .Namespace = ns .Name
983983
984- err := r .apply (ctx , job1 )
985- assert .NilError (t , err )
986-
987- job2 := testBackupJob (cluster , "backup-job-two-complete-2" )
988- job2 .Namespace = ns .Name
989-
990- assert .NilError (t , r .apply (ctx , job2 ))
984+ assert .NilError (t , r .apply (ctx , job1 ))
991985
992986 // Get job1 and update Status.
993987 assert .NilError (t , r .Client .Get (ctx , client .ObjectKeyFromObject (job1 ), job1 ))
994988
995989 job1 .Status = batchv1.JobStatus {
996990 Succeeded : 1 ,
997- CompletionTime : & currentTime ,
991+ CompletionTime : & oneYearAgo ,
998992 // K8SPG-714: ENVTEST_K8S_VERSION=1.32
999- StartTime : new (metav1.NewTime (currentTime .Add (- time .Minute ))),
993+ StartTime : new (metav1.NewTime (oneYearAgo .Add (- time .Minute ))),
1000994 Conditions : []batchv1.JobCondition {
1001995 {
1002996 Type : batchv1 .JobSuccessCriteriaMet ,
@@ -1014,14 +1008,19 @@ func TestGetLatestCompleteBackupJob(t *testing.T) {
10141008 }
10151009 assert .NilError (t , r .Client .Status ().Update (ctx , job1 ))
10161010
1011+ job2 := testBackupJob (cluster , "backup-job-two-complete-2" )
1012+ job2 .Namespace = ns .Name
1013+
1014+ assert .NilError (t , r .apply (ctx , job2 ))
1015+
10171016 // Get job2 and update Status.
10181017 assert .NilError (t , r .Client .Get (ctx , client .ObjectKeyFromObject (job2 ), job2 ))
10191018
10201019 job2 .Status = batchv1.JobStatus {
10211020 Succeeded : 1 ,
1022- CompletionTime : & earlierTime ,
1021+ CompletionTime : & twoYearsAgo ,
10231022 // K8SPG-714: ENVTEST_K8S_VERSION=1.32
1024- StartTime : new (metav1.NewTime (earlierTime .Add (- time .Minute ))),
1023+ StartTime : new (metav1.NewTime (twoYearsAgo .Add (- time .Minute ))),
10251024 Conditions : []batchv1.JobCondition {
10261025 {
10271026 Type : batchv1 .JobSuccessCriteriaMet ,
@@ -1160,7 +1159,7 @@ func TestGetSnapshotsForCluster(t *testing.T) {
11601159 Client : cc ,
11611160 Owner : client .FieldOwner (t .Name ()),
11621161 }
1163- ns := setupNamespace (t , cc )
1162+ ns := require . Namespace (t , cc )
11641163
11651164 cluster := testCluster ()
11661165 cluster .Namespace = ns .Name
@@ -1389,7 +1388,7 @@ func TestDeleteSnapshots(t *testing.T) {
13891388 Owner : client .FieldOwner (t .Name ()),
13901389 DiscoveryClient : discoveryClient ,
13911390 }
1392- ns := setupNamespace (t , cc )
1391+ ns := require . Namespace (t , cc )
13931392
13941393 cluster := testCluster ()
13951394 cluster .Namespace = ns .Name
0 commit comments