Skip to content

Commit 1c3a075

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 9a8caf0 commit 1c3a075

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
@@ -476,6 +476,45 @@ func TestReconcileRedis_RequeuesOnMissingStrategy(t *testing.T) {
476476
}
477477
}
478478

479+
// TestReconcileRedis_FailsOnUnmappableKind mirrors the restore-path test: an
480+
// applicationRef.kind that passes the Redis gate but has no REST mapping (a CRD
481+
// that isn't installed) must fail the BackupJob terminally, not requeue forever.
482+
func TestReconcileRedis_FailsOnUnmappableKind(t *testing.T) {
483+
app := newRedisApp("cache", "tenant-test")
484+
strategy := newRedisStrategy("redis-strategy")
485+
now := metav1.Now()
486+
backupJob := &backupsv1alpha1.BackupJob{
487+
ObjectMeta: metav1.ObjectMeta{Name: "test-bj", Namespace: "tenant-test"},
488+
Spec: backupsv1alpha1.BackupJobSpec{
489+
ApplicationRef: newRedisAppRef("cache"),
490+
BackupClassName: "cozy-default",
491+
},
492+
Status: backupsv1alpha1.BackupJobStatus{StartedAt: &now, Phase: backupsv1alpha1.BackupJobPhaseRunning},
493+
}
494+
495+
r, _ := newRedisTestEnv(t, app, clientfake.NewClientBuilder().WithObjects(backupJob, strategy))
496+
r.RESTMapper = &noMatchRESTMapper{
497+
mockRESTMapper: &mockRESTMapper{},
498+
gk: schema.GroupKind{Group: backupsv1alpha1.DefaultApplicationAPIGroup, Kind: "Redis"},
499+
}
500+
ctx := context.Background()
501+
502+
if _, err := r.reconcileRedis(ctx, backupJob, newRedisResolved("redis-strategy", nil)); err != nil {
503+
t.Fatalf("reconcileRedis() should fail terminally for an unmappable kind, not return a requeue error: %v", err)
504+
}
505+
506+
updated := &backupsv1alpha1.BackupJob{}
507+
if err := r.Get(ctx, client.ObjectKeyFromObject(backupJob), updated); err != nil {
508+
t.Fatalf("get backupjob: %v", err)
509+
}
510+
if updated.Status.Phase != backupsv1alpha1.BackupJobPhaseFailed {
511+
t.Errorf("expected phase Failed for unmappable kind, got %q", updated.Status.Phase)
512+
}
513+
if want := "not found or kind not registered"; !strings.Contains(updated.Status.Message, want) {
514+
t.Errorf("expected message to contain %q, got %q", want, updated.Status.Message)
515+
}
516+
}
517+
479518
func TestReconcileRedisRestore_CreatesBatchJobInTargetNamespace(t *testing.T) {
480519
targetApp := newRedisApp("cache-copy", "tenant-test")
481520
strategy := &strategyv1alpha1.Redis{

0 commit comments

Comments
 (0)