Skip to content

Commit 268ec29

Browse files
androndoclaude
andcommitted
test(backups): assert driver-initiated Backup uses method=plugin
Review follow-up (#3300): ensureCNPGBackup stamps spec.method=plugin + spec.pluginConfiguration on the postgresql.cnpg.io/Backup it creates — the field that routes a driver-initiated run through the barman-cloud plugin. If it regressed to the default (barmanObjectStore) method, CNPG would run the legacy method against a Cluster that no longer has one and every platform backup would fail. Add TestEnsureCNPGBackup_UsesPluginMethod asserting method, plugin name, and cluster ref. (The chart ScheduledBackup path was already covered; the driver path was not.) Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> Signed-off-by: Andrey Kolkov <[email protected]>
1 parent 2212367 commit 268ec29

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

‎internal/backupcontroller/cnpgstrategy_controller_test.go‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1430,6 +1430,33 @@ func TestApplyClusterPluginBackup_PatchesExistingCluster(t *testing.T) {
14301430
}
14311431
}
14321432

1433+
// TestEnsureCNPGBackup_UsesPluginMethod locks in that driver-initiated backups
1434+
// go through the barman-cloud plugin. spec.method / spec.pluginConfiguration is
1435+
// the single field that routes the run: if it regressed to the default
1436+
// (barmanObjectStore) method, CNPG would run the legacy method against a Cluster
1437+
// that no longer has one and every platform backup would fail.
1438+
func TestEnsureCNPGBackup_UsesPluginMethod(t *testing.T) {
1439+
j := &backupsv1alpha1.BackupJob{
1440+
ObjectMeta: metav1.ObjectMeta{Namespace: "tenant", Name: "bj"},
1441+
}
1442+
c := newCNPGStrategyTestClient(t, j)
1443+
r := &BackupJobReconciler{Client: c}
1444+
1445+
bk, err := r.ensureCNPGBackup(context.Background(), j, "postgres-app")
1446+
if err != nil {
1447+
t.Fatalf("ensureCNPGBackup: %v", err)
1448+
}
1449+
if bk.Spec.Method != cnpgtypes.BackupMethodPlugin {
1450+
t.Errorf("Backup spec.method: got %q, want %q", bk.Spec.Method, cnpgtypes.BackupMethodPlugin)
1451+
}
1452+
if bk.Spec.PluginConfiguration == nil || bk.Spec.PluginConfiguration.Name != cnpgtypes.PluginName {
1453+
t.Errorf("Backup spec.pluginConfiguration: got %+v, want name=%q", bk.Spec.PluginConfiguration, cnpgtypes.PluginName)
1454+
}
1455+
if bk.Spec.Cluster.Name != "postgres-app" {
1456+
t.Errorf("Backup spec.cluster.name: got %q, want postgres-app", bk.Spec.Cluster.Name)
1457+
}
1458+
}
1459+
14331460
// TestReconcileCNPG_StartedAtPreservedAcrossStaleCache locks in the bug fix
14341461
// for the StartedAt race called out in the branch review: a second reconcile
14351462
// with a stale local copy (which observes StartedAt==nil) must NOT advance

0 commit comments

Comments
 (0)