diff --git a/test/e2e/apimachinery/crd_conversion_webhook.go b/test/e2e/apimachinery/crd_conversion_webhook.go index 9e309e9f89f..641760ef971 100644 --- a/test/e2e/apimachinery/crd_conversion_webhook.go +++ b/test/e2e/apimachinery/crd_conversion_webhook.go @@ -349,25 +349,36 @@ func deployCustomResourceWebhookAndService(ctx context.Context, f *framework.Fra func verifyV1Object(crd *apiextensionsv1.CustomResourceDefinition, obj *unstructured.Unstructured) { gomega.Expect(obj.GetAPIVersion()).To(gomega.BeEquivalentTo(crd.Spec.Group + "/v1")) hostPort, exists := obj.Object["hostPort"] - framework.ExpectEqual(exists, true) + if !exists { + framework.Failf("HostPort not found.") + } gomega.Expect(hostPort).To(gomega.BeEquivalentTo("localhost:8080")) _, hostExists := obj.Object["host"] - framework.ExpectEqual(hostExists, false) + if hostExists { + framework.Failf("Host should not have been declared.") + } _, portExists := obj.Object["port"] - framework.ExpectEqual(portExists, false) + if portExists { + framework.Failf("Port should not have been declared.") + } } func verifyV2Object(crd *apiextensionsv1.CustomResourceDefinition, obj *unstructured.Unstructured) { gomega.Expect(obj.GetAPIVersion()).To(gomega.BeEquivalentTo(crd.Spec.Group + "/v2")) _, hostPortExists := obj.Object["hostPort"] - framework.ExpectEqual(hostPortExists, false) - + if hostPortExists { + framework.Failf("HostPort should not have been declared.") + } host, hostExists := obj.Object["host"] - framework.ExpectEqual(hostExists, true) + if !hostExists { + framework.Failf("Host declaration not found.") + } gomega.Expect(host).To(gomega.BeEquivalentTo("localhost")) port, portExists := obj.Object["port"] - framework.ExpectEqual(portExists, true) + if !portExists { + framework.Failf("Port declaration not found.") + } gomega.Expect(port).To(gomega.BeEquivalentTo("8080")) } diff --git a/test/e2e/apimachinery/namespace.go b/test/e2e/apimachinery/namespace.go index 7930e9b60fb..0d0fb9e71fa 100644 --- a/test/e2e/apimachinery/namespace.go +++ b/test/e2e/apimachinery/namespace.go @@ -426,7 +426,9 @@ var _ = SIGDescribe("Namespaces [Serial]", func() { break } } - framework.ExpectEqual(foundFinalizer, true, "Finalizer %q was not found. Namespace %q has %#v", fakeFinalizer, updatedNamespace.Spec.Finalizers) + if !foundFinalizer { + framework.Failf("Finalizer %q was not found. Namespace %q has %#v", fakeFinalizer, updatedNamespace.Name, updatedNamespace.Spec.Finalizers) + } framework.Logf("Namespace %q has %#v", updatedNamespace.Name, updatedNamespace.Spec.Finalizers) ginkgo.By(fmt.Sprintf("Removing e2e finalizer from namespace %q", ns)) @@ -453,7 +455,9 @@ var _ = SIGDescribe("Namespaces [Serial]", func() { break } } - framework.ExpectEqual(foundFinalizer, false, "Finalizer %q was found. Namespace %q has %#v", fakeFinalizer, updatedNamespace.Spec.Finalizers) + if foundFinalizer { + framework.Failf("Finalizer %q was found. Namespace %q has %#v", fakeFinalizer, updatedNamespace.Name, updatedNamespace.Spec.Finalizers) + } framework.Logf("Namespace %q has %#v", updatedNamespace.Name, updatedNamespace.Spec.Finalizers) }) diff --git a/test/e2e/apps/cronjob.go b/test/e2e/apps/cronjob.go index 8d19d7ab11e..78547403a34 100644 --- a/test/e2e/apps/cronjob.go +++ b/test/e2e/apps/cronjob.go @@ -24,6 +24,7 @@ import ( "github.com/onsi/ginkgo/v2" "github.com/onsi/gomega" + "github.com/onsi/gomega/format" batchv1 "k8s.io/api/batch/v1" v1 "k8s.io/api/core/v1" @@ -308,7 +309,9 @@ var _ = SIGDescribe("CronJob", func() { cronJob.Spec.TimeZone = &badTimeZone _, err := createCronJob(ctx, f.ClientSet, f.Namespace.Name, cronJob) framework.ExpectError(err, "CronJob creation should fail with invalid time zone error") - framework.ExpectEqual(apierrors.IsInvalid(err), true, "CronJob creation should fail with invalid time zone error") + if !apierrors.IsInvalid(err) { + framework.Failf("Failed to create CronJob, invalid time zone.") + } }) /* @@ -387,8 +390,9 @@ var _ = SIGDescribe("CronJob", func() { for sawAnnotations := false; !sawAnnotations; { select { case evt, ok := <-cjWatch.ResultChan(): + if !ok { - framework.Fail("watch channel should not close") + framework.Fail("Watch channel is closed.") } framework.ExpectEqual(evt.Type, watch.Modified) watchedCronJob, isCronJob := evt.Object.(*batchv1.CronJob) @@ -439,6 +443,7 @@ var _ = SIGDescribe("CronJob", func() { return err }) framework.ExpectNoError(err) + if !updatedStatus.Status.LastScheduleTime.Equal(&now2) { framework.Failf("updated object status expected to have updated lastScheduleTime %#v, got %#v", statusToUpdate.Status.LastScheduleTime, updatedStatus.Status.LastScheduleTime) } @@ -454,9 +459,8 @@ var _ = SIGDescribe("CronJob", func() { // CronJob resource delete operations expectFinalizer := func(cj *batchv1.CronJob, msg string) { framework.ExpectNotEqual(cj.DeletionTimestamp, nil, fmt.Sprintf("expected deletionTimestamp, got nil on step: %q, cronjob: %+v", msg, cj)) - if len(cj.Finalizers) == 0 { - framework.Failf("expected finalizers on cronjob, got none on step: %q, cronjob: %+v", msg, cj) - } + gomega.Expect(len(cj.Finalizers)).To(gomega.BeNumerically(">", 0), "expected finalizers on cronjob, got none on step: %q, cronjob: %+v", msg, cj) + } ginkgo.By("deleting") @@ -469,10 +473,8 @@ var _ = SIGDescribe("CronJob", func() { // If controller does not support finalizers, we expect a 404. Otherwise we validate finalizer behavior. if err == nil { expectFinalizer(cj, "deleting cronjob") - } else { - if !apierrors.IsNotFound(err) { - framework.Failf("expected 404, got %v", err) - } + } else if !apierrors.IsNotFound(err) { + framework.Failf("expected 404, got %v", err) } ginkgo.By("deleting a collection") @@ -481,10 +483,7 @@ var _ = SIGDescribe("CronJob", func() { cjs, err = cjClient.List(ctx, metav1.ListOptions{LabelSelector: "special-label=" + f.UniqueName}) framework.ExpectNoError(err) // Should have <= 2 items since some cronjobs might not have been deleted yet due to finalizers - if len(cjs.Items) > 2 { - framework.Logf("got unexpected filtered list: %v", cjs.Items) - framework.Fail("filtered list should be <= 2") - } + gomega.Expect(len(cjs.Items)).To(gomega.BeNumerically("<=", 2), "filtered list length should be <= 2, got:\n%s", format.Object(cjs.Items, 1)) // Validate finalizers for _, cj := range cjs.Items { expectFinalizer(&cj, "deleting cronjob collection") diff --git a/test/e2e/apps/job.go b/test/e2e/apps/job.go index 00003ee7a47..cc58dd1c8e9 100644 --- a/test/e2e/apps/job.go +++ b/test/e2e/apps/job.go @@ -299,7 +299,7 @@ var _ = SIGDescribe("Job", func() { } } if !exists { - framework.Failf("Expected suspended job to exist. It was not found.") + framework.Failf("Job was expected to be completed or failed") } ginkgo.By("Updating the job with suspend=false") @@ -357,7 +357,7 @@ var _ = SIGDescribe("Job", func() { } } if !exists { - framework.Failf("Expected suspended job to exist. It was not found.") + framework.Failf("Job was expected to be completed or failed") } }) diff --git a/test/e2e/apps/rc.go b/test/e2e/apps/rc.go index e6bdde7f06a..b54d6e3cb0c 100644 --- a/test/e2e/apps/rc.go +++ b/test/e2e/apps/rc.go @@ -45,6 +45,8 @@ import ( admissionapi "k8s.io/pod-security-admission/api" "github.com/onsi/ginkgo/v2" + "github.com/onsi/gomega" + "github.com/onsi/gomega/format" ) var _ = SIGDescribe("ReplicationController", func() { @@ -247,6 +249,7 @@ var _ = SIGDescribe("ReplicationController", func() { return true, nil }) framework.ExpectNoError(err, "Wait until condition with watch events should not return an error") + if !eventFound { framework.Failf("failed to find RC %v event", watch.Added) } @@ -271,7 +274,6 @@ var _ = SIGDescribe("ReplicationController", func() { if !eventFound { framework.Fail("Failed to find updated ready replica count") } - ginkgo.By("fetching ReplicationController status") rcStatusUnstructured, err := dc.Resource(rcResource).Namespace(testRcNamespace).Get(ctx, testRcName, metav1.GetOptions{}, "status") framework.ExpectNoError(err, "Failed to fetch ReplicationControllerStatus") @@ -306,7 +308,7 @@ var _ = SIGDescribe("ReplicationController", func() { }) framework.ExpectNoError(err, "Wait until condition with watch events should not return an error") if !eventFound { - framework.Failf("failed to find RC %v event", watch.Added) + framework.Failf("Failed to find RC %v event", watch.Added) } ginkgo.By("waiting for ReplicationController's scale to be the max amount") @@ -360,6 +362,7 @@ var _ = SIGDescribe("ReplicationController", func() { return true, nil }) framework.ExpectNoError(err, "Wait until condition with watch events should not return an error") + if !eventFound { framework.Failf("failed to find RC %v event", watch.Added) } @@ -367,9 +370,7 @@ var _ = SIGDescribe("ReplicationController", func() { ginkgo.By("listing all ReplicationControllers") rcs, err := f.ClientSet.CoreV1().ReplicationControllers("").List(ctx, metav1.ListOptions{LabelSelector: "test-rc-static=true"}) framework.ExpectNoError(err, "failed to list ReplicationController") - if len(rcs.Items) == 0 { - framework.Fail("Expected to find a ReplicationController but none was found") - } + gomega.Expect(len(rcs.Items)).To(gomega.BeNumerically(">", 0), "Expected to find a ReplicationController but none was found") ginkgo.By("checking that ReplicationController has expected values") foundRc := false @@ -382,8 +383,7 @@ var _ = SIGDescribe("ReplicationController", func() { } } if !foundRc { - framework.Logf("Got unexpected replication controller list %v", rcs.Items) - framework.Failf("could not find ReplicationController %s", testRcName) + framework.Failf("ReplicationController doesn't have expected values.\nValues that are in the ReplicationController list:\n%s", format.Object(rcs.Items, 1)) } // Delete ReplicationController @@ -407,7 +407,6 @@ var _ = SIGDescribe("ReplicationController", func() { if !eventFound { framework.Failf("failed to find RC %v event", watch.Added) } - return actualWatchEvents }, func() (err error) { _ = f.ClientSet.CoreV1().ReplicationControllers(testRcNamespace).DeleteCollection(ctx, metav1.DeleteOptions{}, metav1.ListOptions{LabelSelector: "test-rc-static=true"}) diff --git a/test/e2e/scheduling/limit_range.go b/test/e2e/scheduling/limit_range.go index 0bb77388cca..14980114b88 100644 --- a/test/e2e/scheduling/limit_range.go +++ b/test/e2e/scheduling/limit_range.go @@ -318,7 +318,9 @@ var _ = SIGDescribe("LimitRange", func() { framework.ExpectNoError(err, "Failed to patch limitRange %q", lrName) framework.ExpectEqual(patchedLimitRange.Labels[lrName], "patched", "%q label didn't have value 'patched' for this limitRange. Current labels: %v", lrName, patchedLimitRange.Labels) checkMinLimitRange := apiequality.Semantic.DeepEqual(patchedLimitRange.Spec.Limits[0].Min, newMin) - framework.ExpectEqual(checkMinLimitRange, true, "LimitRange does not have the correct min limitRange. Currently is %#v ", patchedLimitRange.Spec.Limits[0].Min) + if !checkMinLimitRange { + framework.Failf("LimitRange does not have the correct min limitRange. Currently is %#v ", patchedLimitRange.Spec.Limits[0].Min) + } framework.Logf("LimitRange %q has been patched", lrName) ginkgo.By(fmt.Sprintf("Delete LimitRange %q by Collection with labelSelector: %q", lrName, patchedLabelSelector))