Skip to content

Commit b199b4d

Browse files
test(backups): catch a shared stoppedAt pointer in the Backup deep copy
The assertion compared the original's stoppedAt with the variable it points to, so it held even when DeepCopy shared the pointer. It now compares against the value saved before the copy is mutated. Assisted-by: LLM Signed-off-by: Mattia Eleuteri <[email protected]>
1 parent e186842 commit b199b4d

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

‎internal/backupcontroller/cnpgtypes/deepcopy_test.go‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ package cnpgtypes
44

55
import (
66
"testing"
7-
87
"time"
98

109
corev1 "k8s.io/api/core/v1"
@@ -36,10 +35,12 @@ func TestBackupStatusDeepCopyStoppedAt(t *testing.T) {
3635
stopped := metav1.NewTime(time.Date(2026, 9, 21, 6, 27, 23, 0, time.UTC))
3736
original := &Backup{Status: BackupStatus{BackupID: "20260921T062713", StoppedAt: &stopped}}
3837

38+
want := stopped.Time
39+
3940
copied := original.DeepCopy()
4041
copied.Status.StoppedAt.Time = copied.Status.StoppedAt.Add(time.Hour)
4142

42-
if !original.Status.StoppedAt.Equal(&stopped) {
43+
if !original.Status.StoppedAt.Time.Equal(want) {
4344
t.Fatalf("mutating the copy's stoppedAt changed the original: %v", original.Status.StoppedAt)
4445
}
4546
}

0 commit comments

Comments
 (0)