Skip to content

Commit 397ac68

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 b13e276 commit 397ac68

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
@@ -1341,6 +1341,33 @@ func TestApplyClusterPluginBackup_PatchesExistingCluster(t *testing.T) {
13411341
}
13421342
}
13431343

1344+
// TestEnsureCNPGBackup_UsesPluginMethod locks in that driver-initiated backups
1345+
// go through the barman-cloud plugin. spec.method / spec.pluginConfiguration is
1346+
// the single field that routes the run: if it regressed to the default
1347+
// (barmanObjectStore) method, CNPG would run the legacy method against a Cluster
1348+
// that no longer has one and every platform backup would fail.
1349+
func TestEnsureCNPGBackup_UsesPluginMethod(t *testing.T) {
1350+
j := &backupsv1alpha1.BackupJob{
1351+
ObjectMeta: metav1.ObjectMeta{Namespace: "tenant", Name: "bj"},
1352+
}
1353+
c := newCNPGStrategyTestClient(t, j)
1354+
r := &BackupJobReconciler{Client: c}
1355+
1356+
bk, err := r.ensureCNPGBackup(context.Background(), j, "postgres-app")
1357+
if err != nil {
1358+
t.Fatalf("ensureCNPGBackup: %v", err)
1359+
}
1360+
if bk.Spec.Method != cnpgtypes.BackupMethodPlugin {
1361+
t.Errorf("Backup spec.method: got %q, want %q", bk.Spec.Method, cnpgtypes.BackupMethodPlugin)
1362+
}
1363+
if bk.Spec.PluginConfiguration == nil || bk.Spec.PluginConfiguration.Name != cnpgtypes.PluginName {
1364+
t.Errorf("Backup spec.pluginConfiguration: got %+v, want name=%q", bk.Spec.PluginConfiguration, cnpgtypes.PluginName)
1365+
}
1366+
if bk.Spec.Cluster.Name != "postgres-app" {
1367+
t.Errorf("Backup spec.cluster.name: got %q, want postgres-app", bk.Spec.Cluster.Name)
1368+
}
1369+
}
1370+
13441371
// TestReconcileCNPG_StartedAtPreservedAcrossStaleCache locks in the bug fix
13451372
// for the StartedAt race called out in the branch review: a second reconcile
13461373
// with a stale local copy (which observes StartedAt==nil) must NOT advance

0 commit comments

Comments
 (0)