Skip to content

Commit 5e5bfbc

Browse files
committed
Add test to demonstrate that RemoveOwnerRef mutates its input
1 parent a943e75 commit 5e5bfbc

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

util/util_test.go

+9-4
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ import (
4141
func TestMachineToInfrastructureMapFunc(t *testing.T) {
4242
g := NewWithT(t)
4343

44-
var testcases = []struct {
44+
testcases := []struct {
4545
name string
4646
input schema.GroupVersionKind
4747
request client.Object
@@ -110,7 +110,7 @@ func TestMachineToInfrastructureMapFunc(t *testing.T) {
110110
}
111111

112112
func TestClusterToInfrastructureMapFunc(t *testing.T) {
113-
var testcases = []struct {
113+
testcases := []struct {
114114
name string
115115
input schema.GroupVersionKind
116116
request *clusterv1.Cluster
@@ -874,10 +874,15 @@ func TestRemoveOwnerRef(t *testing.T) {
874874
},
875875
},
876876
}
877+
878+
originalOwnerRefs := append([]metav1.OwnerReference{}, ownerRefs...)
877879
for _, tt := range tests {
878880
t.Run(tt.name, func(t *testing.T) {
879-
newOwnerRefs := RemoveOwnerRef(ownerRefs, tt.toBeRemoved)
880-
g.Expect(HasOwnerRef(newOwnerRefs, tt.toBeRemoved)).NotTo(BeTrue())
881+
result := RemoveOwnerRef(ownerRefs, tt.toBeRemoved)
882+
// RemoveOwnerRef should remove the owner ref, if it is found.
883+
g.Expect(HasOwnerRef(result, tt.toBeRemoved)).NotTo(BeTrue())
884+
// RemoveOwnerRef should not mutate its input.
885+
g.Expect(ownerRefs).To(Equal(originalOwnerRefs), "RemoveOwnerRef mutated its input")
881886
})
882887
}
883888
}

0 commit comments

Comments
 (0)