@@ -41,7 +41,7 @@ import (
41
41
func TestMachineToInfrastructureMapFunc (t * testing.T ) {
42
42
g := NewWithT (t )
43
43
44
- var testcases = []struct {
44
+ testcases : = []struct {
45
45
name string
46
46
input schema.GroupVersionKind
47
47
request client.Object
@@ -110,7 +110,7 @@ func TestMachineToInfrastructureMapFunc(t *testing.T) {
110
110
}
111
111
112
112
func TestClusterToInfrastructureMapFunc (t * testing.T ) {
113
- var testcases = []struct {
113
+ testcases : = []struct {
114
114
name string
115
115
input schema.GroupVersionKind
116
116
request * clusterv1.Cluster
@@ -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 {
@@ -876,8 +878,10 @@ func TestRemoveOwnerRef(t *testing.T) {
876
878
}
877
879
for _ , tt := range tests {
878
880
t .Run (tt .name , func (t * testing.T ) {
879
- newOwnerRefs := RemoveOwnerRef (ownerRefs , tt .toBeRemoved )
880
- g .Expect (HasOwnerRef (newOwnerRefs , tt .toBeRemoved )).NotTo (BeTrue ())
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 ())
881
885
})
882
886
}
883
887
}
0 commit comments