mirror of
https://github.com/cozystack/cozystack.git
synced 2026-12-06 23:23:23 +09:00
test(backups): cover BackupJob failing on Velero FailedValidation
Removing the FailedValidation check from the BackupJob path left the suite green; only the RestoreJob side was pinned. Assisted-by: LLM Signed-off-by: Pujitha Paladugu <10557236+pujitha24@users.noreply.github.com>
This commit is contained in:
1 parent
cc9610cf14
commit
3c962df369
1 file changed
+52
@@ -2341,3 +2341,55 @@ func TestReconcileVeleroRestore_FailedValidation(t *testing.T) {
|
||||
t.Errorf("Ready condition = %+v, want message containing the validation error", ready)
|
||||
}
|
||||
}
|
||||
|
||||
func TestReconcileVelero_BackupFailedValidation(t *testing.T) {
|
||||
started := metav1.Now()
|
||||
backupJob := &backupsv1alpha1.BackupJob{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: "bj", Namespace: "tenant-src"},
|
||||
Status: backupsv1alpha1.BackupJobStatus{
|
||||
Phase: backupsv1alpha1.BackupJobPhaseRunning,
|
||||
StartedAt: &started,
|
||||
},
|
||||
}
|
||||
veleroBackup := &velerov1.Backup{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: "vb", Namespace: veleroNamespace, Labels: map[string]string{
|
||||
backupsv1alpha1.OwningJobNameLabel: backupJob.Name,
|
||||
backupsv1alpha1.OwningJobNamespaceLabel: backupJob.Namespace,
|
||||
}},
|
||||
Status: velerov1.BackupStatus{
|
||||
Phase: velerov1.BackupPhaseFailedValidation,
|
||||
ValidationErrors: []string{"storage location not found"},
|
||||
},
|
||||
}
|
||||
strategy := &strategyv1alpha1.Velero{ObjectMeta: metav1.ObjectMeta{Name: "cozy-default-velero"}}
|
||||
resolved := &ResolvedBackupConfig{
|
||||
StrategyRef: corev1.TypedLocalObjectReference{Kind: "Velero", Name: "cozy-default-velero"},
|
||||
}
|
||||
|
||||
testScheme := runtime.NewScheme()
|
||||
_ = scheme.AddToScheme(testScheme)
|
||||
_ = backupsv1alpha1.AddToScheme(testScheme)
|
||||
_ = velerov1.AddToScheme(testScheme)
|
||||
_ = strategyv1alpha1.AddToScheme(testScheme)
|
||||
reconciler := &BackupJobReconciler{Client: clientfake.NewClientBuilder().
|
||||
WithScheme(testScheme).
|
||||
WithObjects(backupJob, veleroBackup, strategy).
|
||||
WithStatusSubresource(&backupsv1alpha1.BackupJob{}).
|
||||
Build()}
|
||||
ctx := context.Background()
|
||||
|
||||
if _, err := reconciler.reconcileVelero(ctx, backupJob, resolved); err != nil {
|
||||
t.Fatalf("reconcileVelero() error = %v", err)
|
||||
}
|
||||
got := &backupsv1alpha1.BackupJob{}
|
||||
if err := reconciler.Get(ctx, client.ObjectKeyFromObject(backupJob), got); err != nil {
|
||||
t.Fatalf("get BackupJob: %v", err)
|
||||
}
|
||||
if got.Status.Phase != backupsv1alpha1.BackupJobPhaseFailed {
|
||||
t.Fatalf("phase = %q, want Failed", got.Status.Phase)
|
||||
}
|
||||
ready := meta.FindStatusCondition(got.Status.Conditions, "Ready")
|
||||
if ready == nil || !strings.Contains(ready.Message, "storage location not found") {
|
||||
t.Errorf("Ready condition = %+v, want message containing the validation error", ready)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user