From f3ea5e5c9417c5d52b2b10b92700217e549d445e Mon Sep 17 00:00:00 2001 From: danielqsj Date: Fri, 10 May 2019 10:15:45 +0800 Subject: [PATCH] replace test error checking with more readable way --- test/e2e/apimachinery/resource_quota.go | 10 +++++----- test/e2e/apps/cronjob.go | 8 ++++---- test/e2e/apps/deployment.go | 2 +- test/e2e/kubectl/kubectl.go | 6 +++--- test/e2e/lifecycle/addon_update.go | 2 +- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/test/e2e/apimachinery/resource_quota.go b/test/e2e/apimachinery/resource_quota.go index c05d32ffa3a7e..2b129db0351f9 100644 --- a/test/e2e/apimachinery/resource_quota.go +++ b/test/e2e/apimachinery/resource_quota.go @@ -216,7 +216,7 @@ var _ = SIGDescribe("ResourceQuota", func() { requests[v1.ResourceMemory] = resource.MustParse("100Mi") pod = newTestPodForQuota(f, "fail-pod", requests, v1.ResourceList{}) pod, err = f.ClientSet.CoreV1().Pods(f.Namespace.Name).Create(pod) - gomega.Expect(err).To(gomega.HaveOccurred()) + framework.ExpectError(err) ginkgo.By("Not allowing a pod to be created that exceeds remaining quota(validation on extended resources)") requests = v1.ResourceList{} @@ -228,7 +228,7 @@ var _ = SIGDescribe("ResourceQuota", func() { limits[v1.ResourceName(extendedResourceName)] = resource.MustParse("2") pod = newTestPodForQuota(f, "fail-pod-for-extended-resource", requests, limits) pod, err = f.ClientSet.CoreV1().Pods(f.Namespace.Name).Create(pod) - gomega.Expect(err).To(gomega.HaveOccurred()) + framework.ExpectError(err) ginkgo.By("Ensuring a pod cannot update its resource requirements") // a pod cannot dynamically update its resource requirements. @@ -238,7 +238,7 @@ var _ = SIGDescribe("ResourceQuota", func() { requests[v1.ResourceEphemeralStorage] = resource.MustParse("10Gi") podToUpdate.Spec.Containers[0].Resources.Requests = requests _, err = f.ClientSet.CoreV1().Pods(f.Namespace.Name).Update(podToUpdate) - gomega.Expect(err).To(gomega.HaveOccurred()) + framework.ExpectError(err) ginkgo.By("Ensuring attempts to update pod resource requirements did not change quota usage") err = waitForResourceQuota(f.ClientSet, f.Namespace.Name, quotaName, usedResources) @@ -561,7 +561,7 @@ var _ = SIGDescribe("ResourceQuota", func() { }, }, resourceClient, testcrd.Crd) // since we only give one quota, this creation should fail. - gomega.Expect(err).To(gomega.HaveOccurred()) + framework.ExpectError(err) ginkgo.By("Deleting a custom resource") err = deleteCustomResource(resourceClient, testcr.GetName()) @@ -1052,7 +1052,7 @@ var _ = SIGDescribe("ResourceQuota [Feature:PodPriority]", func() { podName2 := "testpod-pclass2-2" pod2 := newTestPodForQuotaWithPriority(f, podName2, v1.ResourceList{}, v1.ResourceList{}, "pclass2") pod2, err = f.ClientSet.CoreV1().Pods(f.Namespace.Name).Create(pod2) - gomega.Expect(err).To(gomega.HaveOccurred()) + framework.ExpectError(err) ginkgo.By("Deleting first pod") err = f.ClientSet.CoreV1().Pods(f.Namespace.Name).Delete(pod.Name, metav1.NewDeleteOptions(0)) diff --git a/test/e2e/apps/cronjob.go b/test/e2e/apps/cronjob.go index 93e8cb620d02f..ae9dbcc5d6a68 100644 --- a/test/e2e/apps/cronjob.go +++ b/test/e2e/apps/cronjob.go @@ -91,7 +91,7 @@ var _ = SIGDescribe("CronJob", func() { ginkgo.By("Ensuring no jobs are scheduled") err = waitForNoJobs(f.ClientSet, f.Namespace.Name, cronJob.Name, false) - gomega.Expect(err).To(gomega.HaveOccurred()) + framework.ExpectError(err) ginkgo.By("Ensuring no job exists by listing jobs explicitly") jobs, err := f.ClientSet.BatchV1().Jobs(f.Namespace.Name).List(metav1.ListOptions{}) @@ -128,7 +128,7 @@ var _ = SIGDescribe("CronJob", func() { ginkgo.By("Ensuring no more jobs are scheduled") err = waitForActiveJobs(f.ClientSet, f.Namespace.Name, cronJob.Name, 2) - gomega.Expect(err).To(gomega.HaveOccurred()) + framework.ExpectError(err) ginkgo.By("Removing cronjob") err = deleteCronJob(f.ClientSet, f.Namespace.Name, cronJob.Name) @@ -183,7 +183,7 @@ var _ = SIGDescribe("CronJob", func() { ginkgo.By("Ensuring no unexpected event has happened") err = waitForEventWithReason(f.ClientSet, f.Namespace.Name, cronJob.Name, []string{"MissingJob", "UnexpectedJob"}) - gomega.Expect(err).To(gomega.HaveOccurred()) + framework.ExpectError(err) ginkgo.By("Removing cronjob") err = deleteCronJob(f.ClientSet, f.Namespace.Name, cronJob.Name) @@ -213,7 +213,7 @@ var _ = SIGDescribe("CronJob", func() { ginkgo.By("Ensuring job was deleted") _, err = jobutil.GetJob(f.ClientSet, f.Namespace.Name, job.Name) - gomega.Expect(err).To(gomega.HaveOccurred()) + framework.ExpectError(err) gomega.Expect(errors.IsNotFound(err)).To(gomega.BeTrue()) ginkgo.By("Ensuring the job is not in the cronjob active list") diff --git a/test/e2e/apps/deployment.go b/test/e2e/apps/deployment.go index 5209a6930d129..d084cf948fc44 100644 --- a/test/e2e/apps/deployment.go +++ b/test/e2e/apps/deployment.go @@ -198,7 +198,7 @@ func stopDeployment(c clientset.Interface, ns, deploymentName string) { e2elog.Logf("Ensuring deployment %s was deleted", deploymentName) _, err = c.AppsV1().Deployments(ns).Get(deployment.Name, metav1.GetOptions{}) - gomega.Expect(err).To(gomega.HaveOccurred()) + framework.ExpectError(err) gomega.Expect(errors.IsNotFound(err)).To(gomega.BeTrue()) e2elog.Logf("Ensuring deployment %s's RSes were deleted", deploymentName) selector, err := metav1.LabelSelectorAsSelector(deployment.Spec.Selector) diff --git a/test/e2e/kubectl/kubectl.go b/test/e2e/kubectl/kubectl.go index e1440e568d5dd..485484ec757b6 100644 --- a/test/e2e/kubectl/kubectl.go +++ b/test/e2e/kubectl/kubectl.go @@ -711,7 +711,7 @@ metadata: ginkgo.By("trying to use kubectl with invalid token") _, err = framework.RunHostCmd(ns, simplePodName, "/tmp/kubectl get pods --token=invalid --v=7 2>&1") e2elog.Logf("got err %v", err) - gomega.Expect(err).To(gomega.HaveOccurred()) + framework.ExpectError(err) gomega.Expect(err).To(gomega.ContainSubstring("Using in-cluster namespace")) gomega.Expect(err).To(gomega.ContainSubstring("Using in-cluster configuration")) gomega.Expect(err).To(gomega.ContainSubstring("Authorization: Bearer invalid")) @@ -720,7 +720,7 @@ metadata: ginkgo.By("trying to use kubectl with invalid server") _, err = framework.RunHostCmd(ns, simplePodName, "/tmp/kubectl get pods --server=invalid --v=6 2>&1") e2elog.Logf("got err %v", err) - gomega.Expect(err).To(gomega.HaveOccurred()) + framework.ExpectError(err) gomega.Expect(err).To(gomega.ContainSubstring("Unable to connect to the server")) gomega.Expect(err).To(gomega.ContainSubstring("GET http://invalid/api")) @@ -1717,7 +1717,7 @@ metadata: ginkgo.By("verifying the job " + jobName + " was deleted") _, err = c.BatchV1().Jobs(ns).Get(jobName, metav1.GetOptions{}) - gomega.Expect(err).To(gomega.HaveOccurred()) + framework.ExpectError(err) gomega.Expect(apierrs.IsNotFound(err)).To(gomega.BeTrue()) }) }) diff --git a/test/e2e/lifecycle/addon_update.go b/test/e2e/lifecycle/addon_update.go index 7152bc161d602..a4bf1a8ca709b 100644 --- a/test/e2e/lifecycle/addon_update.go +++ b/test/e2e/lifecycle/addon_update.go @@ -334,7 +334,7 @@ var _ = SIGDescribe("Addon update", func() { ginkgo.By("verify invalid addons weren't created") _, err = f.ClientSet.CoreV1().ReplicationControllers(addonNsName).Get("invalid-addon-test", metav1.GetOptions{}) - gomega.Expect(err).To(gomega.HaveOccurred()) + framework.ExpectError(err) // Invalid addon manifests and the "ensure exist class" addon will be deleted by the deferred function. })