Skip to content

Commit a17f2ba

Browse files
authored
Merge pull request #4943 from damdo/should-bool-add-failure-message
🌱 test: add failure message to Eventually().Should(bool) everywhere
2 parents ac9913b + a7c55e1 commit a17f2ba

17 files changed

+40
-36
lines changed

api/v1beta2/awscluster_webhook_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package v1beta2
1818

1919
import (
2020
"context"
21+
"fmt"
2122
"strings"
2223
"testing"
2324
"time"
@@ -597,7 +598,7 @@ func TestAWSClusterValidateCreate(t *testing.T) {
597598
g.Eventually(func() bool {
598599
err := testEnv.Get(ctx, key, c)
599600
return err == nil
600-
}, 10*time.Second).Should(BeTrue())
601+
}, 10*time.Second).Should(BeTrue(), fmt.Sprintf("Eventually failed getting the newly created cluster %q", cluster.Name))
601602

602603
if tt.expect != nil {
603604
tt.expect(g, c.Spec.ControlPlaneLoadBalancer)

controllers/awscluster_controller_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ func TestAWSClusterReconcilerIntegrationTests(t *testing.T) {
215215
}
216216
err := testEnv.Get(ctx, key, cluster)
217217
return err == nil
218-
}, 10*time.Second).Should(BeTrue())
218+
}, 10*time.Second).Should(BeTrue(), fmt.Sprintf("Eventually failed getting the newly created cluster %q", awsCluster.Name))
219219

220220
defer teardown()
221221
defer t.Cleanup(func() {
@@ -316,7 +316,7 @@ func TestAWSClusterReconcilerIntegrationTests(t *testing.T) {
316316
}
317317
err := testEnv.Get(ctx, key, cluster)
318318
return err == nil
319-
}, 10*time.Second).Should(BeTrue())
319+
}, 10*time.Second).Should(BeTrue(), fmt.Sprintf("Eventually failed getting the newly created cluster %q", awsCluster.Name))
320320

321321
defer teardown()
322322
defer t.Cleanup(func() {
@@ -424,7 +424,7 @@ func TestAWSClusterReconcilerIntegrationTests(t *testing.T) {
424424
}
425425
err := testEnv.Get(ctx, key, cluster)
426426
return err == nil
427-
}, 10*time.Second).Should(BeTrue())
427+
}, 10*time.Second).Should(BeTrue(), fmt.Sprintf("Eventually failed getting the newly created cluster %q", awsCluster.Name))
428428

429429
defer teardown()
430430
defer t.Cleanup(func() {
@@ -532,7 +532,8 @@ func TestAWSClusterReconcilerIntegrationTests(t *testing.T) {
532532
}
533533
err := testEnv.Get(ctx, key, cluster)
534534
return err == nil
535-
}, 10*time.Second).Should(BeTrue())
535+
}, 10*time.Second).Should(BeTrue(), fmt.Sprintf("Eventually failed getting the newly created cluster %q", awsCluster.Name))
536+
536537
defer t.Cleanup(func() {
537538
g.Expect(testEnv.Cleanup(ctx, &awsCluster, controllerIdentity, ns)).To(Succeed())
538539
})
@@ -597,7 +598,7 @@ func TestAWSClusterReconcilerIntegrationTests(t *testing.T) {
597598
}
598599
err := testEnv.Get(ctx, key, cluster)
599600
return err == nil
600-
}, 10*time.Second).Should(BeTrue())
601+
}, 10*time.Second).Should(BeTrue(), fmt.Sprintf("Eventually failed getting the newly created cluster %q", awsCluster.Name))
601602

602603
defer t.Cleanup(func() {
603604
g.Expect(testEnv.Cleanup(ctx, &awsCluster, controllerIdentity, ns)).To(Succeed())

controllers/awscluster_controller_unit_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,7 @@ func createCluster(g *WithT, awsCluster *infrav1.AWSCluster, namespace string) {
628628
}
629629
err := testEnv.Get(ctx, key, cluster)
630630
return err == nil
631-
}, 10*time.Second).Should(BeTrue())
631+
}, 10*time.Second).Should(BeTrue(), fmt.Sprintf("Eventually failed getting the newly created cluster %q", awsCluster.Name))
632632
}
633633
}
634634

controllers/awsmachine_controller_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ func createAWSMachine(g *WithT, awsMachine *infrav1.AWSMachine) {
450450
Namespace: awsMachine.Namespace,
451451
}
452452
return testEnv.Get(ctx, key, machine) == nil
453-
}, 10*time.Second).Should(BeTrue())
453+
}, 10*time.Second).Should(BeTrue(), fmt.Sprintf("Eventually failed get the newly created machine %q", awsMachine.Name))
454454
}
455455

456456
func getAWSMachine() *infrav1.AWSMachine {

controllers/awsmachine_controller_unit_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2459,7 +2459,7 @@ func TestAWSMachineReconcilerReconcile(t *testing.T) {
24592459
}
24602460
err = testEnv.Get(ctx, key, machine)
24612461
return err == nil
2462-
}, 10*time.Second).Should(BeTrue())
2462+
}, 10*time.Second).Should(BeTrue(), fmt.Sprintf("Eventually failed get the newly created machine %q", tc.awsMachine.Name))
24632463

24642464
result, err := reconciler.Reconcile(ctx, ctrl.Request{
24652465
NamespacedName: client.ObjectKey{

controlplane/eks/controllers/awsmanagedcontrolplane_controller_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ func TestAWSManagedControlPlaneReconcilerIntegrationTests(t *testing.T) {
141141
}
142142
err := testEnv.Get(ctx, key, controlPlane)
143143
return err == nil
144-
}, 10*time.Second).Should(BeTrue())
144+
}, 10*time.Second).Should(BeTrue(), fmt.Sprintf("Eventually failed getting the newly created AWSManagedControlPlane %q", awsManagedControlPlane.Name))
145145

146146
defer t.Cleanup(func() {
147147
g.Expect(testEnv.Cleanup(ctx, &cluster, &awsManagedCluster, &awsManagedControlPlane, controllerIdentity, ns)).To(Succeed())

exp/controlleridentitycreator/awscontrolleridentity_controller_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,6 @@ func TestAWSControllerIdentityController(t *testing.T) {
5454
return true
5555
}
5656
return false
57-
}, 10*time.Second).Should(BeTrue())
57+
}, 10*time.Second).Should(BeTrue(), "Eventually failed ensuring AWSClusterControllerIdentity instance is created")
5858
})
5959
}

exp/instancestate/awsinstancestate_controller_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,14 @@ func TestAWSInstanceStateController(t *testing.T) {
135135
exist = exist && ok
136136
}
137137
return exist
138-
}, 10*time.Second).Should(BeTrue())
138+
}, 10*time.Second).Should(BeTrue(), "Eventually failed ensuring queue URLs are up-to-date")
139139

140140
deleteAWSCluster(g, "aws-cluster-2")
141141
t.Log("Ensuring we stop tracking deleted queue")
142142
g.Eventually(func() bool {
143143
_, ok := instanceStateReconciler.queueURLs.Load("aws-cluster-2")
144144
return ok
145-
}, 10*time.Second).Should(BeFalse())
145+
}, 10*time.Second).Should(BeFalse(), "Eventually failed ensuring we stop tracking deleted queue")
146146

147147
persistObject(g, createAWSCluster("aws-cluster-3"))
148148
t.Log("Ensuring newly created cluster is added to tracked clusters")
@@ -153,7 +153,7 @@ func TestAWSInstanceStateController(t *testing.T) {
153153
exist = exist && ok
154154
}
155155
return exist
156-
}, 10*time.Second).Should(BeTrue())
156+
}, 10*time.Second).Should(BeTrue(), "Eventually failed ensuring newly created cluster is added to the tracked clusters")
157157

158158
t.Log("Ensuring machine is labelled with correct instance state")
159159
g.Eventually(func() bool {
@@ -166,7 +166,7 @@ func TestAWSInstanceStateController(t *testing.T) {
166166
labels := m.GetLabels()
167167
val := labels[Ec2InstanceStateLabelKey]
168168
return val == "shutting-down"
169-
}, 10*time.Second).Should(BeTrue())
169+
}, 10*time.Second).Should(BeTrue(), "Eventually failed ensuring machine is labelled with correct instance state")
170170
})
171171
}
172172

exp/instancestate/helpers_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package instancestate
1818

1919
import (
2020
"context"
21+
"fmt"
2122
"time"
2223

2324
. "github.com/onsi/ginkgo/v2"
@@ -50,7 +51,7 @@ func persistObject(g *WithT, o client.Object) {
5051
g.Eventually(func() bool {
5152
err := k8sClient.Get(ctx, lookupKey, o)
5253
return err == nil
53-
}, time.Second*10).Should(BeTrue())
54+
}, time.Second*10).Should(BeTrue(), fmt.Sprintf("Eventually failed getting the newly created object %v", lookupKey))
5455
}
5556

5657
func deleteAWSCluster(g *WithT, name string) {

test/e2e/shared/aws.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ func deleteResourcesInCloudFormation(prov client.ConfigProvider, t *cfn_bootstra
509509
}
510510
code, ok := awserrors.Code(err)
511511
return err == nil || (ok && code == iam.ErrCodeNoSuchEntityException)
512-
}, 5*time.Minute, 5*time.Second).Should(BeTrue())
512+
}, 5*time.Minute, 5*time.Second).Should(BeTrue(), fmt.Sprintf("Eventually failed deleting the following role: %q", role.RoleName))
513513
}
514514
for _, profile := range instanceProfiles {
515515
By(fmt.Sprintf("cleanup for profile with name '%s'", profile.InstanceProfileName))
@@ -522,7 +522,7 @@ func deleteResourcesInCloudFormation(prov client.ConfigProvider, t *cfn_bootstra
522522
}
523523
code, ok := awserrors.Code(err)
524524
return err == nil || (ok && code == iam.ErrCodeNoSuchEntityException)
525-
}, 5*time.Minute, 5*time.Second).Should(BeTrue())
525+
}, 5*time.Minute, 5*time.Second).Should(BeTrue(), fmt.Sprintf("Eventually failed cleaning up profile with name %q", profile.InstanceProfileName))
526526
}
527527
for _, group := range groups {
528528
repeat := false
@@ -534,7 +534,7 @@ func deleteResourcesInCloudFormation(prov client.ConfigProvider, t *cfn_bootstra
534534
}
535535
code, ok := awserrors.Code(err)
536536
return err == nil || (ok && code == iam.ErrCodeNoSuchEntityException)
537-
}, 5*time.Minute, 5*time.Second).Should(BeTrue())
537+
}, 5*time.Minute, 5*time.Second).Should(BeTrue(), fmt.Sprintf("Eventually failed deleting group %q", group.GroupName))
538538
}
539539
for _, policy := range policies {
540540
policies, err := iamSvc.ListPolicies(&iam.ListPoliciesInput{})
@@ -554,7 +554,7 @@ func deleteResourcesInCloudFormation(prov client.ConfigProvider, t *cfn_bootstra
554554
}
555555
code, ok := awserrors.Code(err)
556556
return err == nil || (ok && code == iam.ErrCodeNoSuchEntityException)
557-
}, 5*time.Minute, 5*time.Second).Should(BeTrue())
557+
}, 5*time.Minute, 5*time.Second).Should(BeTrue(), fmt.Sprintf("Eventually failed to delete policy %q", p.String()))
558558
// TODO: why is there a break here? Don't we want to clean up everything?
559559
break
560560
}
@@ -1130,7 +1130,7 @@ func WaitForInstanceState(e2eCtx *E2EContext, clusterName string, state string)
11301130
return true
11311131
}
11321132
return false
1133-
}, 5*time.Minute, 5*time.Second).Should(BeTrue())
1133+
}, 5*time.Minute, 5*time.Second).Should(BeTrue(), fmt.Sprintf("Eventually failed waiting for all cluster's EC2 instance to be in %q state", state))
11341134

11351135
return false
11361136
}
@@ -1547,7 +1547,7 @@ func WaitForNatGatewayState(e2eCtx *E2EContext, gatewayID string, state string)
15471547
gw, _ := GetNatGateway(e2eCtx, gatewayID)
15481548
gwState := *gw.State
15491549
return gwState == state
1550-
}, 3*time.Minute, 5*time.Second).Should(BeTrue())
1550+
}, 3*time.Minute, 5*time.Second).Should(BeTrue(), fmt.Sprintf("Eventually failed waiting for NAT Gateway to be in %q state", state))
15511551
return false
15521552
}
15531553

0 commit comments

Comments
 (0)