Skip to content

Commit 11bac54

Browse files
committed
test(backups): pin both sides of the Velero rename guard
The guard's regression cases only exercised renames, so dropping the IsRenamed conjunct (failing every non-VMInstance restore) or keying the check on targetApplicationRef.kind instead of the backup's kind left the package green. Add the inputs the guard must let through, a VMDisk copy that keeps its name and a VMDisk in-place restore without targetApplicationRef, and a VMDisk backup restored with a VMInstance target kind, which must still be rejected by the source kind. Assisted-By: LLM Signed-off-by: Andrey Kolkov <[email protected]>
1 parent 88073bb commit 11bac54

1 file changed

Lines changed: 42 additions & 8 deletions

File tree

‎internal/backupcontroller/velerostrategy_controller_test.go‎

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,35 +1158,63 @@ func TestReconcileVeleroRestore_RenameGuard(t *testing.T) {
11581158
tests := []struct {
11591159
name string
11601160
appKind string
1161+
targetKind string // targetApplicationRef.kind; defaults to appKind
1162+
targetName string // targetApplicationRef.name; "" omits targetApplicationRef
11611163
targetNS string
11621164
wantPhase backupsv1alpha1.RestoreJobPhase
11631165
wantMessage string
11641166
}{
11651167
{
11661168
name: "postgres cross-namespace rename is rejected",
11671169
appKind: "Postgres",
1170+
targetName: "dst",
11681171
targetNS: targetNS,
11691172
wantPhase: backupsv1alpha1.RestoreJobPhaseFailed,
11701173
wantMessage: `restoring Postgres "src" under a different name ("dst") is not supported by the Velero strategy`,
11711174
},
11721175
{
11731176
name: "vmdisk cross-namespace rename is rejected",
11741177
appKind: vmDiskAppKind,
1178+
targetName: "dst",
1179+
targetNS: targetNS,
1180+
wantPhase: backupsv1alpha1.RestoreJobPhaseFailed,
1181+
wantMessage: `restoring VMDisk "src" under a different name ("dst") is not supported by the Velero strategy`,
1182+
},
1183+
{
1184+
name: "vmdisk rename is rejected by the backup kind, not the target kind",
1185+
appKind: vmDiskAppKind,
1186+
targetKind: vmInstanceKind,
1187+
targetName: "dst",
11751188
targetNS: targetNS,
11761189
wantPhase: backupsv1alpha1.RestoreJobPhaseFailed,
11771190
wantMessage: `restoring VMDisk "src" under a different name ("dst") is not supported by the Velero strategy`,
11781191
},
11791192
{
11801193
name: "postgres same-namespace rename keeps the DataUpload message",
11811194
appKind: "Postgres",
1195+
targetName: "dst",
11821196
targetNS: "",
11831197
wantPhase: backupsv1alpha1.RestoreJobPhaseFailed,
11841198
wantMessage: "restoring to the same namespace with a different application name is not supported",
11851199
},
11861200
{
1187-
name: "vminstance cross-namespace rename passes the guard",
1188-
appKind: vmInstanceKind,
1189-
targetNS: targetNS,
1201+
name: "vminstance cross-namespace rename passes the guard",
1202+
appKind: vmInstanceKind,
1203+
targetName: "dst",
1204+
targetNS: targetNS,
1205+
wantPhase: backupsv1alpha1.RestoreJobPhaseRunning,
1206+
},
1207+
{
1208+
name: "vmdisk cross-namespace copy keeping the source name passes the guard",
1209+
appKind: vmDiskAppKind,
1210+
targetName: "src",
1211+
targetNS: targetNS,
1212+
wantPhase: backupsv1alpha1.RestoreJobPhaseRunning,
1213+
},
1214+
{
1215+
name: "vmdisk in-place restore without targetApplicationRef passes the guard",
1216+
appKind: vmDiskAppKind,
1217+
targetNS: "",
11901218
wantPhase: backupsv1alpha1.RestoreJobPhaseRunning,
11911219
},
11921220
}
@@ -1207,13 +1235,19 @@ func TestReconcileVeleroRestore_RenameGuard(t *testing.T) {
12071235
ObjectMeta: metav1.ObjectMeta{Name: "src-restore", Namespace: sourceNS},
12081236
Spec: backupsv1alpha1.RestoreJobSpec{
12091237
BackupRef: corev1.LocalObjectReference{Name: "src-sb"},
1210-
TargetApplicationRef: &corev1.TypedLocalObjectReference{
1211-
APIGroup: stringPtr("apps.cozystack.io"),
1212-
Kind: tt.appKind,
1213-
Name: "dst",
1214-
},
12151238
},
12161239
}
1240+
if tt.targetName != "" {
1241+
targetKind := tt.targetKind
1242+
if targetKind == "" {
1243+
targetKind = tt.appKind
1244+
}
1245+
restoreJob.Spec.TargetApplicationRef = &corev1.TypedLocalObjectReference{
1246+
APIGroup: stringPtr("apps.cozystack.io"),
1247+
Kind: targetKind,
1248+
Name: tt.targetName,
1249+
}
1250+
}
12171251
if tt.targetNS != "" {
12181252
raw, err := json.Marshal(RestoreOptions{CommonRestoreOptions: CommonRestoreOptions{TargetNamespace: tt.targetNS}})
12191253
if err != nil {

0 commit comments

Comments
 (0)