@@ -840,17 +840,19 @@ func TestIsSupportedVersionSkew(t *testing.T) {
840
840
841
841
func TestRemoveOwnerRef (t * testing.T ) {
842
842
g := NewWithT (t )
843
- ownerRefs := []metav1.OwnerReference {
844
- {
845
- APIVersion : "dazzlings.info/v1" ,
846
- Kind : "Twilight" ,
847
- Name : "m4g1c" ,
848
- },
849
- {
850
- APIVersion : "bar.cluster.x-k8s.io/v1beta1" ,
851
- Kind : "TestCluster" ,
852
- Name : "bar-1" ,
853
- },
843
+ makeOwnerRefs := func () []metav1.OwnerReference {
844
+ return []metav1.OwnerReference {
845
+ {
846
+ APIVersion : "dazzlings.info/v1" ,
847
+ Kind : "Twilight" ,
848
+ Name : "m4g1c" ,
849
+ },
850
+ {
851
+ APIVersion : "bar.cluster.x-k8s.io/v1beta1" ,
852
+ Kind : "TestCluster" ,
853
+ Name : "bar-1" ,
854
+ },
855
+ }
854
856
}
855
857
856
858
tests := []struct {
@@ -874,15 +876,12 @@ func TestRemoveOwnerRef(t *testing.T) {
874
876
},
875
877
},
876
878
}
877
-
878
- originalOwnerRefs := append ([]metav1.OwnerReference {}, ownerRefs ... )
879
879
for _ , tt := range tests {
880
880
t .Run (tt .name , func (t * testing.T ) {
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" )
881
+ // Use a fresh ownerRefs slice for each test, because RemoveOwnerRef may modify the underlying array.
882
+ ownerRefs := makeOwnerRefs ()
883
+ ownerRefs = RemoveOwnerRef (ownerRefs , tt .toBeRemoved )
884
+ g .Expect (HasOwnerRef (ownerRefs , tt .toBeRemoved )).NotTo (BeTrue ())
886
885
})
887
886
}
888
887
}
0 commit comments