Skip to content

Commit 6433a76

Browse files
committed
Fix test with non-existent DWOC
Signed-off-by: Ales Raszka <[email protected]>
1 parent f083043 commit 6433a76

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

controllers/backupcronjob/backupcronjob_controller.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ func (r *BackupCronJobReconciler) executeBackupSync(ctx context.Context, dwOpera
250250
err = r.NonCachingClient.Status().Patch(ctx, dwOperatorConfig, origConfig)
251251
if err != nil {
252252
log.Error(err, "Failed to update DevWorkspaceOperatorConfig status with last backup time")
253-
// Not returning error as the backup jobs were created successfully
253+
return err
254254
}
255255
return nil
256256
}
@@ -299,7 +299,7 @@ func (r *BackupCronJobReconciler) createBackupJob(
299299
return err
300300
}
301301

302-
// Find a PVC with the name "claim-devworkspace" or based on the name from the operator config
302+
// Find a PVC with used by the workspace
303303
pvcName, workspacePath, err := r.getWorkspacePVCName(workspace, dwOperatorConfig, ctx, log)
304304
if err != nil {
305305
log.Error(err, "Failed to get workspace PVC name", "devworkspace", workspace.Name)

controllers/backupcronjob/backupcronjob_controller_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ var _ = Describe("BackupCronJobReconciler", func() {
5757
Expect(dwv2.AddToScheme(scheme)).To(Succeed())
5858
Expect(corev1.AddToScheme(scheme)).To(Succeed())
5959
Expect(batchv1.AddToScheme(scheme)).To(Succeed())
60-
fakeClient = fake.NewClientBuilder().WithScheme(scheme).Build()
60+
fakeClient = fake.NewClientBuilder().WithScheme(scheme).WithStatusSubresource(&controllerv1alpha1.DevWorkspaceOperatorConfig{}).Build()
6161
log = zap.New(zap.UseDevMode(true)).WithName("BackupCronJobReconcilerTest")
6262

6363
reconciler = BackupCronJobReconciler{
@@ -301,6 +301,7 @@ var _ = Describe("BackupCronJobReconciler", func() {
301301
},
302302
},
303303
}
304+
Expect(fakeClient.Create(ctx, dwoc)).To(Succeed())
304305
dw := createDevWorkspace("dw-recent", "ns-a", false, metav1.NewTime(time.Now().Add(-10*time.Minute)))
305306
dw.Status.Phase = dwv2.DevWorkspaceStatusStopped
306307
dw.Status.DevWorkspaceId = "id-recent"
@@ -334,6 +335,7 @@ var _ = Describe("BackupCronJobReconciler", func() {
334335
},
335336
},
336337
}
338+
Expect(fakeClient.Create(ctx, dwoc)).To(Succeed())
337339
dw := createDevWorkspace("dw-recent", "ns-a", false, metav1.NewTime(time.Now().Add(-10*time.Minute)))
338340
dw.Status.Phase = dwv2.DevWorkspaceStatusStopped
339341
dw.Status.DevWorkspaceId = "id-recent"
@@ -389,6 +391,7 @@ var _ = Describe("BackupCronJobReconciler", func() {
389391
LastBackupTime: &lastBackupTime,
390392
},
391393
}
394+
Expect(fakeClient.Create(ctx, dwoc)).To(Succeed())
392395
dw := createDevWorkspace("dw-old", "ns-b", false, metav1.NewTime(time.Now().Add(-60*time.Minute)))
393396
dw.Status.Phase = dwv2.DevWorkspaceStatusStopped
394397
dw.Status.DevWorkspaceId = "id-old"
@@ -421,6 +424,7 @@ var _ = Describe("BackupCronJobReconciler", func() {
421424
},
422425
},
423426
}
427+
Expect(fakeClient.Create(ctx, dwoc)).To(Succeed())
424428
dw := createDevWorkspace("dw-running", "ns-c", true, metav1.NewTime(time.Now().Add(-5*time.Minute)))
425429
Expect(fakeClient.Create(ctx, dw)).To(Succeed())
426430

@@ -452,6 +456,7 @@ var _ = Describe("BackupCronJobReconciler", func() {
452456
},
453457
},
454458
}
459+
Expect(fakeClient.Create(ctx, dwoc)).To(Succeed())
455460
dw := createDevWorkspace("dw-recent", "ns-a", false, metav1.NewTime(time.Now().Add(-10*time.Minute)))
456461
dw.Status.Phase = dwv2.DevWorkspaceStatusStopped
457462
dw.Status.DevWorkspaceId = "id-recent"
@@ -487,6 +492,7 @@ var _ = Describe("BackupCronJobReconciler", func() {
487492
},
488493
},
489494
}
495+
Expect(fakeClient.Create(ctx, dwoc)).To(Succeed())
490496
dw := createDevWorkspace("dw-recent", "ns-a", false, metav1.NewTime(time.Now().Add(-10*time.Minute)))
491497
dw.Status.Phase = dwv2.DevWorkspaceStatusStopped
492498
dw.Status.DevWorkspaceId = "id-recent"

0 commit comments

Comments
 (0)