Skip to content

Commit 7fd9598

Browse files
authored
Merge pull request #8769 from killianmuldoon/pr-without-error
🌱 Improve gomega fail handling in clusterClass rollout
2 parents 755c9ea + 288763a commit 7fd9598

File tree

1 file changed

+12
-25
lines changed

1 file changed

+12
-25
lines changed

test/e2e/clusterclass_rollout.go

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ func assertControlPlane(g Gomega, clusterClassObjects clusterClassObjects, clust
363363
clusterv1.TemplateClonedFromNameAnnotation: clusterClass.Spec.ControlPlane.MachineInfrastructure.Ref.Name,
364364
},
365365
clusterClassObjects.ControlPlaneInfrastructureMachineTemplate.GetAnnotations(),
366-
).without(corev1.LastAppliedConfigAnnotation),
366+
).without(g, corev1.LastAppliedConfigAnnotation),
367367
))
368368

369369
// ControlPlane InfrastructureMachineTemplate.spec.template.metadata
@@ -395,7 +395,7 @@ func assertControlPlaneMachines(g Gomega, clusterObjects clusterObjects, cluster
395395
g.Expect(
396396
union(
397397
machine.Annotations,
398-
).without(controlplanev1.KubeadmClusterConfigurationAnnotation),
398+
).without(g, controlplanev1.KubeadmClusterConfigurationAnnotation),
399399
).To(BeEquivalentTo(
400400
controlPlaneMachineTemplateMetadata.Annotations,
401401
))
@@ -443,7 +443,7 @@ func assertControlPlaneMachines(g Gomega, clusterObjects clusterObjects, cluster
443443
g.Expect(
444444
union(
445445
bootstrapConfig.GetAnnotations(),
446-
).ignore(clusterv1.MachineCertificatesExpiryDateAnnotation),
446+
).without(g, clusterv1.MachineCertificatesExpiryDateAnnotation),
447447
).To(BeEquivalentTo(
448448
controlPlaneMachineTemplateMetadata.Annotations,
449449
))
@@ -476,7 +476,7 @@ func assertMachineDeployments(g Gomega, clusterClassObjects clusterClassObjects,
476476
g.Expect(
477477
union(
478478
machineDeployment.Annotations,
479-
).without(clusterv1.RevisionAnnotation),
479+
).without(g, clusterv1.RevisionAnnotation),
480480
).To(BeEquivalentTo(
481481
union(
482482
mdTopology.Metadata.Annotations,
@@ -535,7 +535,7 @@ func assertMachineDeployments(g Gomega, clusterClassObjects clusterClassObjects,
535535
clusterv1.TemplateClonedFromNameAnnotation: mdClass.Template.Infrastructure.Ref.Name,
536536
},
537537
ccInfrastructureMachineTemplate.GetAnnotations(),
538-
).without(corev1.LastAppliedConfigAnnotation),
538+
).without(g, corev1.LastAppliedConfigAnnotation),
539539
))
540540
// MachineDeployment InfrastructureMachineTemplate.spec.template.metadata
541541
g.Expect(infrastructureMachineTemplateTemplateMetadata.Labels).To(BeEquivalentTo(
@@ -567,7 +567,7 @@ func assertMachineDeployments(g Gomega, clusterClassObjects clusterClassObjects,
567567
clusterv1.TemplateClonedFromNameAnnotation: mdClass.Template.Bootstrap.Ref.Name,
568568
},
569569
ccBootstrapConfigTemplate.GetAnnotations(),
570-
).without(corev1.LastAppliedConfigAnnotation),
570+
).without(g, corev1.LastAppliedConfigAnnotation),
571571
))
572572
// MachineDeployment BootstrapConfigTemplate.spec.template.metadata
573573
g.Expect(bootstrapConfigTemplateTemplateMetadata.Labels).To(BeEquivalentTo(
@@ -602,11 +602,11 @@ func assertMachineSets(g Gomega, clusterObjects clusterObjects, cluster *cluster
602602
g.Expect(
603603
union(
604604
machineSet.Annotations,
605-
).without(clusterv1.DesiredReplicasAnnotation, clusterv1.MaxReplicasAnnotation, clusterv1.RevisionAnnotation),
605+
).without(g, clusterv1.DesiredReplicasAnnotation, clusterv1.MaxReplicasAnnotation, clusterv1.RevisionAnnotation),
606606
).To(BeEquivalentTo(
607607
union(
608608
machineDeployment.Annotations,
609-
).without(clusterv1.RevisionAnnotation),
609+
).without(g, clusterv1.RevisionAnnotation),
610610
))
611611
// MachineDeployment MachineSet.spec.selector
612612
g.Expect(machineSet.Spec.Selector.MatchLabels).To(BeEquivalentTo(
@@ -807,24 +807,11 @@ func union(maps ...map[string]string) unionMap {
807807

808808
// without removes keys from a unionMap.
809809
// Note: This allows ignoring specific keys while comparing maps.
810-
func (m unionMap) without(keys ...string) unionMap {
810+
func (m unionMap) without(g Gomega, keys ...string) unionMap {
811811
for _, key := range keys {
812-
// Fail if the key does not exist in the map.
813-
// Note: Failing here ensures we only use without for keys that actually exist.
814-
if _, ok := m[key]; !ok {
815-
Fail(fmt.Sprintf("key %q does not exist in map %s", key, m))
816-
}
817-
818-
delete(m, key)
819-
}
820-
return m
821-
}
822-
823-
// ignore removes keys from a unionMap only if they exist.
824-
// Note: This allows ignoring specific keys while comparing maps and is a more tolerant version of `without()`.
825-
func (m unionMap) ignore(keys ...string) unionMap {
826-
for _, key := range keys {
827-
// Only remove the item from the map if it exists.
812+
// Expect key to exist in the map to ensure without is only used for keys that actually exist.
813+
_, ok := m[key]
814+
g.Expect(ok).To(BeTrue(), fmt.Sprintf("key %q does not exist in map %s", key, m))
828815
delete(m, key)
829816
}
830817
return m

0 commit comments

Comments
 (0)