Fix: Improves the log for failing tests in e2e/apps.

Issue #105678
This commit is contained in:
Paulo Gonçalves Lima 2023-01-28 02:50:32 -03:00
parent 4c4d4ad0a4
commit d1278a0830
6 changed files with 48 additions and 33 deletions

View File

@ -349,25 +349,36 @@ func deployCustomResourceWebhookAndService(ctx context.Context, f *framework.Fra
func verifyV1Object(crd *apiextensionsv1.CustomResourceDefinition, obj *unstructured.Unstructured) { func verifyV1Object(crd *apiextensionsv1.CustomResourceDefinition, obj *unstructured.Unstructured) {
gomega.Expect(obj.GetAPIVersion()).To(gomega.BeEquivalentTo(crd.Spec.Group + "/v1")) gomega.Expect(obj.GetAPIVersion()).To(gomega.BeEquivalentTo(crd.Spec.Group + "/v1"))
hostPort, exists := obj.Object["hostPort"] hostPort, exists := obj.Object["hostPort"]
framework.ExpectEqual(exists, true) if !exists {
framework.Failf("HostPort not found.")
}
gomega.Expect(hostPort).To(gomega.BeEquivalentTo("localhost:8080")) gomega.Expect(hostPort).To(gomega.BeEquivalentTo("localhost:8080"))
_, hostExists := obj.Object["host"] _, hostExists := obj.Object["host"]
framework.ExpectEqual(hostExists, false) if hostExists {
framework.Failf("Host should not have been declared.")
}
_, portExists := obj.Object["port"] _, 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) { func verifyV2Object(crd *apiextensionsv1.CustomResourceDefinition, obj *unstructured.Unstructured) {
gomega.Expect(obj.GetAPIVersion()).To(gomega.BeEquivalentTo(crd.Spec.Group + "/v2")) gomega.Expect(obj.GetAPIVersion()).To(gomega.BeEquivalentTo(crd.Spec.Group + "/v2"))
_, hostPortExists := obj.Object["hostPort"] _, hostPortExists := obj.Object["hostPort"]
framework.ExpectEqual(hostPortExists, false) if hostPortExists {
framework.Failf("HostPort should not have been declared.")
}
host, hostExists := obj.Object["host"] host, hostExists := obj.Object["host"]
framework.ExpectEqual(hostExists, true) if !hostExists {
framework.Failf("Host declaration not found.")
}
gomega.Expect(host).To(gomega.BeEquivalentTo("localhost")) gomega.Expect(host).To(gomega.BeEquivalentTo("localhost"))
port, portExists := obj.Object["port"] port, portExists := obj.Object["port"]
framework.ExpectEqual(portExists, true) if !portExists {
framework.Failf("Port declaration not found.")
}
gomega.Expect(port).To(gomega.BeEquivalentTo("8080")) gomega.Expect(port).To(gomega.BeEquivalentTo("8080"))
} }

View File

@ -426,7 +426,9 @@ var _ = SIGDescribe("Namespaces [Serial]", func() {
break 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) framework.Logf("Namespace %q has %#v", updatedNamespace.Name, updatedNamespace.Spec.Finalizers)
ginkgo.By(fmt.Sprintf("Removing e2e finalizer from namespace %q", ns)) ginkgo.By(fmt.Sprintf("Removing e2e finalizer from namespace %q", ns))
@ -453,7 +455,9 @@ var _ = SIGDescribe("Namespaces [Serial]", func() {
break 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) framework.Logf("Namespace %q has %#v", updatedNamespace.Name, updatedNamespace.Spec.Finalizers)
}) })

View File

@ -24,6 +24,7 @@ import (
"github.com/onsi/ginkgo/v2" "github.com/onsi/ginkgo/v2"
"github.com/onsi/gomega" "github.com/onsi/gomega"
"github.com/onsi/gomega/format"
batchv1 "k8s.io/api/batch/v1" batchv1 "k8s.io/api/batch/v1"
v1 "k8s.io/api/core/v1" v1 "k8s.io/api/core/v1"
@ -308,7 +309,9 @@ var _ = SIGDescribe("CronJob", func() {
cronJob.Spec.TimeZone = &badTimeZone cronJob.Spec.TimeZone = &badTimeZone
_, err := createCronJob(ctx, f.ClientSet, f.Namespace.Name, cronJob) _, err := createCronJob(ctx, f.ClientSet, f.Namespace.Name, cronJob)
framework.ExpectError(err, "CronJob creation should fail with invalid time zone error") 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; { for sawAnnotations := false; !sawAnnotations; {
select { select {
case evt, ok := <-cjWatch.ResultChan(): case evt, ok := <-cjWatch.ResultChan():
if !ok { if !ok {
framework.Fail("watch channel should not close") framework.Fail("Watch channel is closed.")
} }
framework.ExpectEqual(evt.Type, watch.Modified) framework.ExpectEqual(evt.Type, watch.Modified)
watchedCronJob, isCronJob := evt.Object.(*batchv1.CronJob) watchedCronJob, isCronJob := evt.Object.(*batchv1.CronJob)
@ -439,6 +443,7 @@ var _ = SIGDescribe("CronJob", func() {
return err return err
}) })
framework.ExpectNoError(err) framework.ExpectNoError(err)
if !updatedStatus.Status.LastScheduleTime.Equal(&now2) { 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) 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 // CronJob resource delete operations
expectFinalizer := func(cj *batchv1.CronJob, msg string) { 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)) framework.ExpectNotEqual(cj.DeletionTimestamp, nil, fmt.Sprintf("expected deletionTimestamp, got nil on step: %q, cronjob: %+v", msg, cj))
if len(cj.Finalizers) == 0 { gomega.Expect(len(cj.Finalizers)).To(gomega.BeNumerically(">", 0), "expected finalizers on cronjob, got none on step: %q, cronjob: %+v", msg, cj)
framework.Failf("expected finalizers on cronjob, got none on step: %q, cronjob: %+v", msg, cj)
}
} }
ginkgo.By("deleting") ginkgo.By("deleting")
@ -469,11 +473,9 @@ var _ = SIGDescribe("CronJob", func() {
// If controller does not support finalizers, we expect a 404. Otherwise we validate finalizer behavior. // If controller does not support finalizers, we expect a 404. Otherwise we validate finalizer behavior.
if err == nil { if err == nil {
expectFinalizer(cj, "deleting cronjob") expectFinalizer(cj, "deleting cronjob")
} else { } else if !apierrors.IsNotFound(err) {
if !apierrors.IsNotFound(err) {
framework.Failf("expected 404, got %v", err) framework.Failf("expected 404, got %v", err)
} }
}
ginkgo.By("deleting a collection") ginkgo.By("deleting a collection")
err = cjClient.DeleteCollection(ctx, metav1.DeleteOptions{}, metav1.ListOptions{LabelSelector: "special-label=" + f.UniqueName}) err = cjClient.DeleteCollection(ctx, metav1.DeleteOptions{}, metav1.ListOptions{LabelSelector: "special-label=" + f.UniqueName})
@ -481,10 +483,7 @@ var _ = SIGDescribe("CronJob", func() {
cjs, err = cjClient.List(ctx, metav1.ListOptions{LabelSelector: "special-label=" + f.UniqueName}) cjs, err = cjClient.List(ctx, metav1.ListOptions{LabelSelector: "special-label=" + f.UniqueName})
framework.ExpectNoError(err) framework.ExpectNoError(err)
// Should have <= 2 items since some cronjobs might not have been deleted yet due to finalizers // Should have <= 2 items since some cronjobs might not have been deleted yet due to finalizers
if len(cjs.Items) > 2 { gomega.Expect(len(cjs.Items)).To(gomega.BeNumerically("<=", 2), "filtered list length should be <= 2, got:\n%s", format.Object(cjs.Items, 1))
framework.Logf("got unexpected filtered list: %v", cjs.Items)
framework.Fail("filtered list should be <= 2")
}
// Validate finalizers // Validate finalizers
for _, cj := range cjs.Items { for _, cj := range cjs.Items {
expectFinalizer(&cj, "deleting cronjob collection") expectFinalizer(&cj, "deleting cronjob collection")

View File

@ -299,7 +299,7 @@ var _ = SIGDescribe("Job", func() {
} }
} }
if !exists { 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") ginkgo.By("Updating the job with suspend=false")
@ -357,7 +357,7 @@ var _ = SIGDescribe("Job", func() {
} }
} }
if !exists { if !exists {
framework.Failf("Expected suspended job to exist. It was not found.") framework.Failf("Job was expected to be completed or failed")
} }
}) })

View File

@ -45,6 +45,8 @@ import (
admissionapi "k8s.io/pod-security-admission/api" admissionapi "k8s.io/pod-security-admission/api"
"github.com/onsi/ginkgo/v2" "github.com/onsi/ginkgo/v2"
"github.com/onsi/gomega"
"github.com/onsi/gomega/format"
) )
var _ = SIGDescribe("ReplicationController", func() { var _ = SIGDescribe("ReplicationController", func() {
@ -247,6 +249,7 @@ var _ = SIGDescribe("ReplicationController", func() {
return true, nil return true, nil
}) })
framework.ExpectNoError(err, "Wait until condition with watch events should not return an error") framework.ExpectNoError(err, "Wait until condition with watch events should not return an error")
if !eventFound { if !eventFound {
framework.Failf("failed to find RC %v event", watch.Added) framework.Failf("failed to find RC %v event", watch.Added)
} }
@ -271,7 +274,6 @@ var _ = SIGDescribe("ReplicationController", func() {
if !eventFound { if !eventFound {
framework.Fail("Failed to find updated ready replica count") framework.Fail("Failed to find updated ready replica count")
} }
ginkgo.By("fetching ReplicationController status") ginkgo.By("fetching ReplicationController status")
rcStatusUnstructured, err := dc.Resource(rcResource).Namespace(testRcNamespace).Get(ctx, testRcName, metav1.GetOptions{}, "status") rcStatusUnstructured, err := dc.Resource(rcResource).Namespace(testRcNamespace).Get(ctx, testRcName, metav1.GetOptions{}, "status")
framework.ExpectNoError(err, "Failed to fetch ReplicationControllerStatus") 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") framework.ExpectNoError(err, "Wait until condition with watch events should not return an error")
if !eventFound { 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") ginkgo.By("waiting for ReplicationController's scale to be the max amount")
@ -360,6 +362,7 @@ var _ = SIGDescribe("ReplicationController", func() {
return true, nil return true, nil
}) })
framework.ExpectNoError(err, "Wait until condition with watch events should not return an error") framework.ExpectNoError(err, "Wait until condition with watch events should not return an error")
if !eventFound { if !eventFound {
framework.Failf("failed to find RC %v event", watch.Added) framework.Failf("failed to find RC %v event", watch.Added)
} }
@ -367,9 +370,7 @@ var _ = SIGDescribe("ReplicationController", func() {
ginkgo.By("listing all ReplicationControllers") ginkgo.By("listing all ReplicationControllers")
rcs, err := f.ClientSet.CoreV1().ReplicationControllers("").List(ctx, metav1.ListOptions{LabelSelector: "test-rc-static=true"}) rcs, err := f.ClientSet.CoreV1().ReplicationControllers("").List(ctx, metav1.ListOptions{LabelSelector: "test-rc-static=true"})
framework.ExpectNoError(err, "failed to list ReplicationController") framework.ExpectNoError(err, "failed to list ReplicationController")
if len(rcs.Items) == 0 { gomega.Expect(len(rcs.Items)).To(gomega.BeNumerically(">", 0), "Expected to find a ReplicationController but none was found")
framework.Fail("Expected to find a ReplicationController but none was found")
}
ginkgo.By("checking that ReplicationController has expected values") ginkgo.By("checking that ReplicationController has expected values")
foundRc := false foundRc := false
@ -382,8 +383,7 @@ var _ = SIGDescribe("ReplicationController", func() {
} }
} }
if !foundRc { if !foundRc {
framework.Logf("Got unexpected replication controller list %v", rcs.Items) framework.Failf("ReplicationController doesn't have expected values.\nValues that are in the ReplicationController list:\n%s", format.Object(rcs.Items, 1))
framework.Failf("could not find ReplicationController %s", testRcName)
} }
// Delete ReplicationController // Delete ReplicationController
@ -407,7 +407,6 @@ var _ = SIGDescribe("ReplicationController", func() {
if !eventFound { if !eventFound {
framework.Failf("failed to find RC %v event", watch.Added) framework.Failf("failed to find RC %v event", watch.Added)
} }
return actualWatchEvents return actualWatchEvents
}, func() (err error) { }, func() (err error) {
_ = f.ClientSet.CoreV1().ReplicationControllers(testRcNamespace).DeleteCollection(ctx, metav1.DeleteOptions{}, metav1.ListOptions{LabelSelector: "test-rc-static=true"}) _ = f.ClientSet.CoreV1().ReplicationControllers(testRcNamespace).DeleteCollection(ctx, metav1.DeleteOptions{}, metav1.ListOptions{LabelSelector: "test-rc-static=true"})

View File

@ -318,7 +318,9 @@ var _ = SIGDescribe("LimitRange", func() {
framework.ExpectNoError(err, "Failed to patch limitRange %q", lrName) 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) 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) 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) framework.Logf("LimitRange %q has been patched", lrName)
ginkgo.By(fmt.Sprintf("Delete LimitRange %q by Collection with labelSelector: %q", lrName, patchedLabelSelector)) ginkgo.By(fmt.Sprintf("Delete LimitRange %q by Collection with labelSelector: %q", lrName, patchedLabelSelector))