Skip to content

Commit 0413b0d

Browse files
androndoclaude
andcommitted
test(backups): cover Redis backup-path unmappable kind
The restore path already asserts a terminal failure for an applicationRef that passes the Redis gate but has no REST mapping; add the symmetric backup-path case so both dispatch sides are covered. Signed-off-by: Andrey Kolkov <[email protected]> Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
1 parent 5a8c7b6 commit 0413b0d

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

‎internal/backupcontroller/redisstrategy_controller_test.go‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,45 @@ func TestReconcileRedis_RequeuesOnMissingStrategy(t *testing.T) {
516516
}
517517
}
518518

519+
// TestReconcileRedis_FailsOnUnmappableKind mirrors the restore-path test: an
520+
// applicationRef.kind that passes the Redis gate but has no REST mapping (a CRD
521+
// that isn't installed) must fail the BackupJob terminally, not requeue forever.
522+
func TestReconcileRedis_FailsOnUnmappableKind(t *testing.T) {
523+
app := newRedisApp("cache", "tenant-test")
524+
strategy := newRedisStrategy("redis-strategy")
525+
now := metav1.Now()
526+
backupJob := &backupsv1alpha1.BackupJob{
527+
ObjectMeta: metav1.ObjectMeta{Name: "test-bj", Namespace: "tenant-test"},
528+
Spec: backupsv1alpha1.BackupJobSpec{
529+
ApplicationRef: newRedisAppRef("cache"),
530+
BackupClassName: "cozy-default",
531+
},
532+
Status: backupsv1alpha1.BackupJobStatus{StartedAt: &now, Phase: backupsv1alpha1.BackupJobPhaseRunning},
533+
}
534+
535+
r, _ := newRedisTestEnv(t, app, clientfake.NewClientBuilder().WithObjects(backupJob, strategy))
536+
r.RESTMapper = &noMatchRESTMapper{
537+
mockRESTMapper: &mockRESTMapper{},
538+
gk: schema.GroupKind{Group: backupsv1alpha1.DefaultApplicationAPIGroup, Kind: "Redis"},
539+
}
540+
ctx := context.Background()
541+
542+
if _, err := r.reconcileRedis(ctx, backupJob, newRedisResolved("redis-strategy", nil)); err != nil {
543+
t.Fatalf("reconcileRedis() should fail terminally for an unmappable kind, not return a requeue error: %v", err)
544+
}
545+
546+
updated := &backupsv1alpha1.BackupJob{}
547+
if err := r.Get(ctx, client.ObjectKeyFromObject(backupJob), updated); err != nil {
548+
t.Fatalf("get backupjob: %v", err)
549+
}
550+
if updated.Status.Phase != backupsv1alpha1.BackupJobPhaseFailed {
551+
t.Errorf("expected phase Failed for unmappable kind, got %q", updated.Status.Phase)
552+
}
553+
if want := "not found or kind not registered"; !strings.Contains(updated.Status.Message, want) {
554+
t.Errorf("expected message to contain %q, got %q", want, updated.Status.Message)
555+
}
556+
}
557+
519558
func TestReconcileRedisRestore_CreatesBatchJobInTargetNamespace(t *testing.T) {
520559
targetApp := newRedisApp("cache-copy", "tenant-test")
521560
strategy := &strategyv1alpha1.Redis{

0 commit comments

Comments
 (0)