Skip to content

Commit 67c5df9

Browse files
committed
Extend test to cover wider scope
Signed-off-by: Ales Raszka <[email protected]>
1 parent afacdec commit 67c5df9

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

controllers/backupcronjob/backupcronjob_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ func (r *BackupCronJobReconciler) getWorkspacePVCName(workspace *dw.DevWorkspace
464464
if dwOperatorConfig.Config.Workspace.PVCName != "" {
465465
pvcName = dwOperatorConfig.Config.Workspace.PVCName
466466
}
467-
return pvcName, workspace.Status.DevWorkspaceId + "/" + constants.DefaultProjectsSourcesRoot, nil
467+
return pvcName, workspace.Status.DevWorkspaceId + constants.DefaultProjectsSourcesRoot, nil
468468
}
469469
return "", "", nil
470470
}

controllers/backupcronjob/backupcronjob_controller_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import (
3838
dwv2 "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
3939
controllerv1alpha1 "github.com/devfile/devworkspace-operator/apis/controller/v1alpha1"
4040
"github.com/devfile/devworkspace-operator/pkg/conditions"
41+
"github.com/devfile/devworkspace-operator/pkg/constants"
4142
)
4243

4344
var _ = Describe("BackupCronJobReconciler", func() {
@@ -253,6 +254,25 @@ var _ = Describe("BackupCronJobReconciler", func() {
253254
jobList := &batchv1.JobList{}
254255
Expect(fakeClient.List(ctx, jobList, &client.ListOptions{Namespace: dw.Namespace})).To(Succeed())
255256
Expect(jobList.Items).To(HaveLen(1))
257+
job := jobList.Items[0]
258+
Expect(job.Labels[constants.DevWorkspaceIDLabel]).To(Equal("id-recent"))
259+
Expect(job.Spec.Template.Spec.ServiceAccountName).To(Equal("devworkspace-job-runner-id-recent"))
260+
container := job.Spec.Template.Spec.Containers[0]
261+
expectedEnvs := []corev1.EnvVar{
262+
{Name: "DEVWORKSPACE_NAME", Value: "dw-recent"},
263+
{Name: "DEVWORKSPACE_NAMESPACE", Value: "ns-a"},
264+
{Name: "WORKSPACE_ID", Value: "id-recent"},
265+
{Name: "BACKUP_SOURCE_PATH", Value: "/workspace/id-recent/projects"},
266+
{Name: "DEVWORKSPACE_BACKUP_REGISTRY", Value: "fake-registry"},
267+
{Name: "PODMAN_PUSH_OPTIONS", Value: "--tls-verify=false"},
268+
}
269+
Expect(container.Env).Should(ContainElements(expectedEnvs), "container env vars should include vars neeeded for backup")
270+
271+
expectedVolumeMounts := []corev1.VolumeMount{
272+
{MountPath: "/workspace", Name: "workspace-data"},
273+
{MountPath: "/var/lib/containers", Name: "build-storage"},
274+
}
275+
Expect(container.VolumeMounts).Should(ContainElements(expectedVolumeMounts), "container volume mounts should include mounts needed for backup")
256276
})
257277

258278
It("does not create a Job when the DevWorkspace was stopped beyond time range", func() {

0 commit comments

Comments
 (0)