Skip to content

Commit

Permalink
Merge pull request kubernetes#77709 from danielqsj/test
Browse files Browse the repository at this point in the history
replace test error checking with more readable way
  • Loading branch information
k8s-ci-robot authored May 13, 2019
2 parents ed4c508 + f3ea5e5 commit 389252f
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 14 deletions.
10 changes: 5 additions & 5 deletions test/e2e/apimachinery/resource_quota.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand All @@ -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.
Expand All @@ -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)
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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))
Expand Down
8 changes: 4 additions & 4 deletions test/e2e/apps/cronjob.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{})
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/apps/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions test/e2e/kubectl/kubectl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand All @@ -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"))

Expand Down Expand Up @@ -1714,7 +1714,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())
})
})
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/lifecycle/addon_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,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.
})
Expand Down

0 comments on commit 389252f

Please sign in to comment.