From 0cd58b825f3feb994a67ce5d58dddd50f63c65f1 Mon Sep 17 00:00:00 2001 From: Nikhil Sharma Date: Wed, 1 Dec 2021 17:08:30 +0530 Subject: [PATCH] Changed code to improve output for files under test/e2e/apimachinery --- test/e2e/apimachinery/aggregator.go | 4 ++- .../custom_resource_definition.go | 4 ++- test/e2e/apimachinery/resource_quota.go | 36 ++++++++++++++----- 3 files changed, 33 insertions(+), 11 deletions(-) diff --git a/test/e2e/apimachinery/aggregator.go b/test/e2e/apimachinery/aggregator.go index 6616a45cd8d..20f2915f36b 100644 --- a/test/e2e/apimachinery/aggregator.go +++ b/test/e2e/apimachinery/aggregator.go @@ -512,7 +512,9 @@ func TestSampleAPIServer(f *framework.Framework, aggrclient *aggregatorclient.Cl break } } - framework.ExpectEqual(locatedWardle, true, "Unable to find v1alpha1.wardle.example.com in APIServiceList") + if !locatedWardle { + framework.Failf("Unable to find v1alpha1.wardle.example.com in APIServiceList") + } // kubectl delete flunder test-flunder err = dynamicClient.Delete(context.TODO(), flunderName, metav1.DeleteOptions{}) diff --git a/test/e2e/apimachinery/custom_resource_definition.go b/test/e2e/apimachinery/custom_resource_definition.go index 1d4c5ecaf6d..4f636940ac8 100644 --- a/test/e2e/apimachinery/custom_resource_definition.go +++ b/test/e2e/apimachinery/custom_resource_definition.go @@ -339,7 +339,9 @@ var _ = SIGDescribe("CustomResourceDefinition resources [Privileged:ClusterAdmin }}, metav1.CreateOptions{}) framework.ExpectNoError(err, "creating CR") v, found, err := unstructured.NestedFieldNoCopy(u2.Object, "a") - framework.ExpectEqual(found, true, "\"a\" is defaulted") + if !found { + framework.Failf("field `a` should have been defaulted in %+v", u2.Object) + } framework.ExpectEqual(v, "A", "\"a\" is defaulted to \"A\"") // Deleting default for a, adding default "B" for b and waiting for the CR to get defaulted on read for b diff --git a/test/e2e/apimachinery/resource_quota.go b/test/e2e/apimachinery/resource_quota.go index c561e962c71..b2c1e5d4b68 100644 --- a/test/e2e/apimachinery/resource_quota.go +++ b/test/e2e/apimachinery/resource_quota.go @@ -909,7 +909,9 @@ var _ = SIGDescribe("ResourceQuota", func() { ginkgo.By("Verifying the deleted ResourceQuota") _, err = client.CoreV1().ResourceQuotas(ns).Get(context.TODO(), quotaName, metav1.GetOptions{}) - framework.ExpectEqual(apierrors.IsNotFound(err), true) + if !apierrors.IsNotFound(err) { + framework.Failf("Expected `not found` error, got: %v", err) + } }) }) @@ -1099,7 +1101,9 @@ var _ = SIGDescribe("ResourceQuota [Feature:PodPriority]", func() { ginkgo.It("should verify ResourceQuota's priority class scope (quota set to pod count: 1) against a pod with same priority class.", func() { _, err := f.ClientSet.SchedulingV1().PriorityClasses().Create(context.TODO(), &schedulingv1.PriorityClass{ObjectMeta: metav1.ObjectMeta{Name: "pclass1"}, Value: int32(1000)}, metav1.CreateOptions{}) - framework.ExpectEqual(err == nil || apierrors.IsAlreadyExists(err), true) + if err != nil && !apierrors.IsAlreadyExists(err) { + framework.Failf("unexpected error while creating priority class: %v", err) + } hard := v1.ResourceList{} hard[v1.ResourcePods] = resource.MustParse("1") @@ -1138,7 +1142,9 @@ var _ = SIGDescribe("ResourceQuota [Feature:PodPriority]", func() { ginkgo.It("should verify ResourceQuota's priority class scope (quota set to pod count: 1) against 2 pods with same priority class.", func() { _, err := f.ClientSet.SchedulingV1().PriorityClasses().Create(context.TODO(), &schedulingv1.PriorityClass{ObjectMeta: metav1.ObjectMeta{Name: "pclass2"}, Value: int32(1000)}, metav1.CreateOptions{}) - framework.ExpectEqual(err == nil || apierrors.IsAlreadyExists(err), true) + if err != nil && !apierrors.IsAlreadyExists(err) { + framework.Failf("unexpected error while creating priority class: %v", err) + } hard := v1.ResourceList{} hard[v1.ResourcePods] = resource.MustParse("1") @@ -1183,7 +1189,9 @@ var _ = SIGDescribe("ResourceQuota [Feature:PodPriority]", func() { ginkgo.It("should verify ResourceQuota's priority class scope (quota set to pod count: 1) against 2 pods with different priority class.", func() { _, err := f.ClientSet.SchedulingV1().PriorityClasses().Create(context.TODO(), &schedulingv1.PriorityClass{ObjectMeta: metav1.ObjectMeta{Name: "pclass3"}, Value: int32(1000)}, metav1.CreateOptions{}) - framework.ExpectEqual(err == nil || apierrors.IsAlreadyExists(err), true) + if err != nil && !apierrors.IsAlreadyExists(err) { + framework.Failf("unexpected error while creating priority class: %v", err) + } hard := v1.ResourceList{} hard[v1.ResourcePods] = resource.MustParse("1") @@ -1229,10 +1237,14 @@ var _ = SIGDescribe("ResourceQuota [Feature:PodPriority]", func() { ginkgo.It("should verify ResourceQuota's multiple priority class scope (quota set to pod count: 2) against 2 pods with same priority classes.", func() { _, err := f.ClientSet.SchedulingV1().PriorityClasses().Create(context.TODO(), &schedulingv1.PriorityClass{ObjectMeta: metav1.ObjectMeta{Name: "pclass5"}, Value: int32(1000)}, metav1.CreateOptions{}) - framework.ExpectEqual(err == nil || apierrors.IsAlreadyExists(err), true) + if err != nil && !apierrors.IsAlreadyExists(err) { + framework.Failf("unexpected error while creating priority class: %v", err) + } _, err = f.ClientSet.SchedulingV1().PriorityClasses().Create(context.TODO(), &schedulingv1.PriorityClass{ObjectMeta: metav1.ObjectMeta{Name: "pclass6"}, Value: int32(1000)}, metav1.CreateOptions{}) - framework.ExpectEqual(err == nil || apierrors.IsAlreadyExists(err), true) + if err != nil && !apierrors.IsAlreadyExists(err) { + framework.Failf("unexpected error while creating priority class: %v", err) + } hard := v1.ResourceList{} hard[v1.ResourcePods] = resource.MustParse("2") @@ -1284,7 +1296,9 @@ var _ = SIGDescribe("ResourceQuota [Feature:PodPriority]", func() { ginkgo.It("should verify ResourceQuota's priority class scope (quota set to pod count: 1) against a pod with different priority class (ScopeSelectorOpNotIn).", func() { _, err := f.ClientSet.SchedulingV1().PriorityClasses().Create(context.TODO(), &schedulingv1.PriorityClass{ObjectMeta: metav1.ObjectMeta{Name: "pclass7"}, Value: int32(1000)}, metav1.CreateOptions{}) - framework.ExpectEqual(err == nil || apierrors.IsAlreadyExists(err), true) + if err != nil && !apierrors.IsAlreadyExists(err) { + framework.Failf("unexpected error while creating priority class: %v", err) + } hard := v1.ResourceList{} hard[v1.ResourcePods] = resource.MustParse("1") @@ -1318,7 +1332,9 @@ var _ = SIGDescribe("ResourceQuota [Feature:PodPriority]", func() { ginkgo.It("should verify ResourceQuota's priority class scope (quota set to pod count: 1) against a pod with different priority class (ScopeSelectorOpExists).", func() { _, err := f.ClientSet.SchedulingV1().PriorityClasses().Create(context.TODO(), &schedulingv1.PriorityClass{ObjectMeta: metav1.ObjectMeta{Name: "pclass8"}, Value: int32(1000)}, metav1.CreateOptions{}) - framework.ExpectEqual(err == nil || apierrors.IsAlreadyExists(err), true) + if err != nil && !apierrors.IsAlreadyExists(err) { + framework.Failf("unexpected error while creating priority class: %v", err) + } hard := v1.ResourceList{} hard[v1.ResourcePods] = resource.MustParse("1") @@ -1357,7 +1373,9 @@ var _ = SIGDescribe("ResourceQuota [Feature:PodPriority]", func() { ginkgo.It("should verify ResourceQuota's priority class scope (cpu, memory quota set) against a pod with same priority class.", func() { _, err := f.ClientSet.SchedulingV1().PriorityClasses().Create(context.TODO(), &schedulingv1.PriorityClass{ObjectMeta: metav1.ObjectMeta{Name: "pclass9"}, Value: int32(1000)}, metav1.CreateOptions{}) - framework.ExpectEqual(err == nil || apierrors.IsAlreadyExists(err), true) + if err != nil && !apierrors.IsAlreadyExists(err) { + framework.Failf("unexpected error while creating priority class: %v", err) + } hard := v1.ResourceList{} hard[v1.ResourcePods] = resource.MustParse("1")