Skip to content

Commit 217e08d

Browse files
authored
Merge pull request kubernetes#77123 from k-toyoda-pi/use_expect_no_error_e2e_apps_1
use framework.ExpectNoError() for e2e/apps
2 parents 6f1fd17 + 2c098b3 commit 217e08d

File tree

8 files changed

+139
-142
lines changed

8 files changed

+139
-142
lines changed

test/e2e/apps/cronjob.go

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -61,21 +61,21 @@ var _ = SIGDescribe("CronJob", func() {
6161
cronJob := newTestCronJob("concurrent", "*/1 * * * ?", batchv1beta1.AllowConcurrent,
6262
sleepCommand, nil)
6363
cronJob, err := createCronJob(f.ClientSet, f.Namespace.Name, cronJob)
64-
gomega.Expect(err).NotTo(gomega.HaveOccurred(), "Failed to create CronJob in namespace %s", f.Namespace.Name)
64+
framework.ExpectNoError(err, "Failed to create CronJob in namespace %s", f.Namespace.Name)
6565

6666
ginkgo.By("Ensuring more than one job is running at a time")
6767
err = waitForActiveJobs(f.ClientSet, f.Namespace.Name, cronJob.Name, 2)
68-
gomega.Expect(err).NotTo(gomega.HaveOccurred(), "Failed to wait for active jobs in CronJob %s in namespace %s", cronJob.Name, f.Namespace.Name)
68+
framework.ExpectNoError(err, "Failed to wait for active jobs in CronJob %s in namespace %s", cronJob.Name, f.Namespace.Name)
6969

7070
ginkgo.By("Ensuring at least two running jobs exists by listing jobs explicitly")
7171
jobs, err := f.ClientSet.BatchV1().Jobs(f.Namespace.Name).List(metav1.ListOptions{})
72-
gomega.Expect(err).NotTo(gomega.HaveOccurred(), "Failed to list the CronJobs in namespace %s", f.Namespace.Name)
72+
framework.ExpectNoError(err, "Failed to list the CronJobs in namespace %s", f.Namespace.Name)
7373
activeJobs, _ := filterActiveJobs(jobs)
7474
gomega.Expect(len(activeJobs) >= 2).To(gomega.BeTrue())
7575

7676
ginkgo.By("Removing cronjob")
7777
err = deleteCronJob(f.ClientSet, f.Namespace.Name, cronJob.Name)
78-
gomega.Expect(err).NotTo(gomega.HaveOccurred(), "Failed to delete CronJob %s in namespace %s", cronJob.Name, f.Namespace.Name)
78+
framework.ExpectNoError(err, "Failed to delete CronJob %s in namespace %s", cronJob.Name, f.Namespace.Name)
7979
})
8080

8181
// suspended should not schedule jobs
@@ -86,20 +86,20 @@ var _ = SIGDescribe("CronJob", func() {
8686
t := true
8787
cronJob.Spec.Suspend = &t
8888
cronJob, err := createCronJob(f.ClientSet, f.Namespace.Name, cronJob)
89-
gomega.Expect(err).NotTo(gomega.HaveOccurred(), "Failed to create CronJob in namespace %s", f.Namespace.Name)
89+
framework.ExpectNoError(err, "Failed to create CronJob in namespace %s", f.Namespace.Name)
9090

9191
ginkgo.By("Ensuring no jobs are scheduled")
9292
err = waitForNoJobs(f.ClientSet, f.Namespace.Name, cronJob.Name, false)
9393
gomega.Expect(err).To(gomega.HaveOccurred())
9494

9595
ginkgo.By("Ensuring no job exists by listing jobs explicitly")
9696
jobs, err := f.ClientSet.BatchV1().Jobs(f.Namespace.Name).List(metav1.ListOptions{})
97-
gomega.Expect(err).NotTo(gomega.HaveOccurred(), "Failed to list the CronJobs in namespace %s", f.Namespace.Name)
97+
framework.ExpectNoError(err, "Failed to list the CronJobs in namespace %s", f.Namespace.Name)
9898
gomega.Expect(jobs.Items).To(gomega.HaveLen(0))
9999

100100
ginkgo.By("Removing cronjob")
101101
err = deleteCronJob(f.ClientSet, f.Namespace.Name, cronJob.Name)
102-
gomega.Expect(err).NotTo(gomega.HaveOccurred(), "Failed to delete CronJob %s in namespace %s", cronJob.Name, f.Namespace.Name)
102+
framework.ExpectNoError(err, "Failed to delete CronJob %s in namespace %s", cronJob.Name, f.Namespace.Name)
103103
})
104104

105105
// only single active job is allowed for ForbidConcurrent
@@ -108,20 +108,20 @@ var _ = SIGDescribe("CronJob", func() {
108108
cronJob := newTestCronJob("forbid", "*/1 * * * ?", batchv1beta1.ForbidConcurrent,
109109
sleepCommand, nil)
110110
cronJob, err := createCronJob(f.ClientSet, f.Namespace.Name, cronJob)
111-
gomega.Expect(err).NotTo(gomega.HaveOccurred(), "Failed to create CronJob in namespace %s", f.Namespace.Name)
111+
framework.ExpectNoError(err, "Failed to create CronJob in namespace %s", f.Namespace.Name)
112112

113113
ginkgo.By("Ensuring a job is scheduled")
114114
err = waitForActiveJobs(f.ClientSet, f.Namespace.Name, cronJob.Name, 1)
115-
gomega.Expect(err).NotTo(gomega.HaveOccurred(), "Failed to schedule CronJob %s", cronJob.Name)
115+
framework.ExpectNoError(err, "Failed to schedule CronJob %s", cronJob.Name)
116116

117117
ginkgo.By("Ensuring exactly one is scheduled")
118118
cronJob, err = getCronJob(f.ClientSet, f.Namespace.Name, cronJob.Name)
119-
gomega.Expect(err).NotTo(gomega.HaveOccurred(), "Failed to get CronJob %s", cronJob.Name)
119+
framework.ExpectNoError(err, "Failed to get CronJob %s", cronJob.Name)
120120
gomega.Expect(cronJob.Status.Active).Should(gomega.HaveLen(1))
121121

122122
ginkgo.By("Ensuring exactly one running job exists by listing jobs explicitly")
123123
jobs, err := f.ClientSet.BatchV1().Jobs(f.Namespace.Name).List(metav1.ListOptions{})
124-
gomega.Expect(err).NotTo(gomega.HaveOccurred(), "Failed to list the CronJobs in namespace %s", f.Namespace.Name)
124+
framework.ExpectNoError(err, "Failed to list the CronJobs in namespace %s", f.Namespace.Name)
125125
activeJobs, _ := filterActiveJobs(jobs)
126126
gomega.Expect(activeJobs).To(gomega.HaveLen(1))
127127

@@ -131,7 +131,7 @@ var _ = SIGDescribe("CronJob", func() {
131131

132132
ginkgo.By("Removing cronjob")
133133
err = deleteCronJob(f.ClientSet, f.Namespace.Name, cronJob.Name)
134-
gomega.Expect(err).NotTo(gomega.HaveOccurred(), "Failed to delete CronJob %s in namespace %s", cronJob.Name, f.Namespace.Name)
134+
framework.ExpectNoError(err, "Failed to delete CronJob %s in namespace %s", cronJob.Name, f.Namespace.Name)
135135
})
136136

137137
// only single active job is allowed for ReplaceConcurrent
@@ -140,30 +140,30 @@ var _ = SIGDescribe("CronJob", func() {
140140
cronJob := newTestCronJob("replace", "*/1 * * * ?", batchv1beta1.ReplaceConcurrent,
141141
sleepCommand, nil)
142142
cronJob, err := createCronJob(f.ClientSet, f.Namespace.Name, cronJob)
143-
gomega.Expect(err).NotTo(gomega.HaveOccurred(), "Failed to create CronJob in namespace %s", f.Namespace.Name)
143+
framework.ExpectNoError(err, "Failed to create CronJob in namespace %s", f.Namespace.Name)
144144

145145
ginkgo.By("Ensuring a job is scheduled")
146146
err = waitForActiveJobs(f.ClientSet, f.Namespace.Name, cronJob.Name, 1)
147-
gomega.Expect(err).NotTo(gomega.HaveOccurred(), "Failed to schedule CronJob %s in namespace %s", cronJob.Name, f.Namespace.Name)
147+
framework.ExpectNoError(err, "Failed to schedule CronJob %s in namespace %s", cronJob.Name, f.Namespace.Name)
148148

149149
ginkgo.By("Ensuring exactly one is scheduled")
150150
cronJob, err = getCronJob(f.ClientSet, f.Namespace.Name, cronJob.Name)
151-
gomega.Expect(err).NotTo(gomega.HaveOccurred(), "Failed to get CronJob %s", cronJob.Name)
151+
framework.ExpectNoError(err, "Failed to get CronJob %s", cronJob.Name)
152152
gomega.Expect(cronJob.Status.Active).Should(gomega.HaveLen(1))
153153

154154
ginkgo.By("Ensuring exactly one running job exists by listing jobs explicitly")
155155
jobs, err := f.ClientSet.BatchV1().Jobs(f.Namespace.Name).List(metav1.ListOptions{})
156-
gomega.Expect(err).NotTo(gomega.HaveOccurred(), "Failed to list the jobs in namespace %s", f.Namespace.Name)
156+
framework.ExpectNoError(err, "Failed to list the jobs in namespace %s", f.Namespace.Name)
157157
activeJobs, _ := filterActiveJobs(jobs)
158158
gomega.Expect(activeJobs).To(gomega.HaveLen(1))
159159

160160
ginkgo.By("Ensuring the job is replaced with a new one")
161161
err = waitForJobReplaced(f.ClientSet, f.Namespace.Name, jobs.Items[0].Name)
162-
gomega.Expect(err).NotTo(gomega.HaveOccurred(), "Failed to replace CronJob %s in namespace %s", jobs.Items[0].Name, f.Namespace.Name)
162+
framework.ExpectNoError(err, "Failed to replace CronJob %s in namespace %s", jobs.Items[0].Name, f.Namespace.Name)
163163

164164
ginkgo.By("Removing cronjob")
165165
err = deleteCronJob(f.ClientSet, f.Namespace.Name, cronJob.Name)
166-
gomega.Expect(err).NotTo(gomega.HaveOccurred(), "Failed to delete CronJob %s in namespace %s", cronJob.Name, f.Namespace.Name)
166+
framework.ExpectNoError(err, "Failed to delete CronJob %s in namespace %s", cronJob.Name, f.Namespace.Name)
167167
})
168168

169169
// shouldn't give us unexpected warnings
@@ -172,21 +172,21 @@ var _ = SIGDescribe("CronJob", func() {
172172
cronJob := newTestCronJob("concurrent", "*/1 * * * ?", batchv1beta1.AllowConcurrent,
173173
nil, nil)
174174
cronJob, err := createCronJob(f.ClientSet, f.Namespace.Name, cronJob)
175-
gomega.Expect(err).NotTo(gomega.HaveOccurred(), "Failed to create CronJob in namespace %s", f.Namespace.Name)
175+
framework.ExpectNoError(err, "Failed to create CronJob in namespace %s", f.Namespace.Name)
176176

177177
ginkgo.By("Ensuring at least two jobs and at least one finished job exists by listing jobs explicitly")
178178
err = waitForJobsAtLeast(f.ClientSet, f.Namespace.Name, 2)
179-
gomega.Expect(err).NotTo(gomega.HaveOccurred(), "Failed to ensure at least two job exists in namespace %s", f.Namespace.Name)
179+
framework.ExpectNoError(err, "Failed to ensure at least two job exists in namespace %s", f.Namespace.Name)
180180
err = waitForAnyFinishedJob(f.ClientSet, f.Namespace.Name)
181-
gomega.Expect(err).NotTo(gomega.HaveOccurred(), "Failed to ensure at least on finished job exists in namespace %s", f.Namespace.Name)
181+
framework.ExpectNoError(err, "Failed to ensure at least on finished job exists in namespace %s", f.Namespace.Name)
182182

183183
ginkgo.By("Ensuring no unexpected event has happened")
184184
err = waitForEventWithReason(f.ClientSet, f.Namespace.Name, cronJob.Name, []string{"MissingJob", "UnexpectedJob"})
185185
gomega.Expect(err).To(gomega.HaveOccurred())
186186

187187
ginkgo.By("Removing cronjob")
188188
err = deleteCronJob(f.ClientSet, f.Namespace.Name, cronJob.Name)
189-
gomega.Expect(err).NotTo(gomega.HaveOccurred(), "Failed to delete CronJob %s in namespace %s", cronJob.Name, f.Namespace.Name)
189+
framework.ExpectNoError(err, "Failed to delete CronJob %s in namespace %s", cronJob.Name, f.Namespace.Name)
190190
})
191191

192192
// deleted jobs should be removed from the active list
@@ -195,15 +195,15 @@ var _ = SIGDescribe("CronJob", func() {
195195
cronJob := newTestCronJob("forbid", "*/1 * * * ?", batchv1beta1.ForbidConcurrent,
196196
sleepCommand, nil)
197197
cronJob, err := createCronJob(f.ClientSet, f.Namespace.Name, cronJob)
198-
gomega.Expect(err).NotTo(gomega.HaveOccurred(), "Failed to create CronJob in namespace %s", f.Namespace.Name)
198+
framework.ExpectNoError(err, "Failed to create CronJob in namespace %s", f.Namespace.Name)
199199

200200
ginkgo.By("Ensuring a job is scheduled")
201201
err = waitForActiveJobs(f.ClientSet, f.Namespace.Name, cronJob.Name, 1)
202-
gomega.Expect(err).NotTo(gomega.HaveOccurred(), "Failed to ensure a %s cronjob is scheduled in namespace %s", cronJob.Name, f.Namespace.Name)
202+
framework.ExpectNoError(err, "Failed to ensure a %s cronjob is scheduled in namespace %s", cronJob.Name, f.Namespace.Name)
203203

204204
ginkgo.By("Ensuring exactly one is scheduled")
205205
cronJob, err = getCronJob(f.ClientSet, f.Namespace.Name, cronJob.Name)
206-
gomega.Expect(err).NotTo(gomega.HaveOccurred(), "Failed to ensure exactly one %s cronjob is scheduled in namespace %s", cronJob.Name, f.Namespace.Name)
206+
framework.ExpectNoError(err, "Failed to ensure exactly one %s cronjob is scheduled in namespace %s", cronJob.Name, f.Namespace.Name)
207207
gomega.Expect(cronJob.Status.Active).Should(gomega.HaveLen(1))
208208

209209
ginkgo.By("Deleting the job")
@@ -217,15 +217,15 @@ var _ = SIGDescribe("CronJob", func() {
217217

218218
ginkgo.By("Ensuring the job is not in the cronjob active list")
219219
err = waitForJobNotActive(f.ClientSet, f.Namespace.Name, cronJob.Name, job.Name)
220-
gomega.Expect(err).NotTo(gomega.HaveOccurred(), "Failed to ensure the %s cronjob is not in active list in namespace %s", cronJob.Name, f.Namespace.Name)
220+
framework.ExpectNoError(err, "Failed to ensure the %s cronjob is not in active list in namespace %s", cronJob.Name, f.Namespace.Name)
221221

222222
ginkgo.By("Ensuring MissingJob event has occurred")
223223
err = waitForEventWithReason(f.ClientSet, f.Namespace.Name, cronJob.Name, []string{"MissingJob"})
224-
gomega.Expect(err).NotTo(gomega.HaveOccurred(), "Failed to ensure missing job event has occurred for %s cronjob in namespace %s", cronJob.Name, f.Namespace.Name)
224+
framework.ExpectNoError(err, "Failed to ensure missing job event has occurred for %s cronjob in namespace %s", cronJob.Name, f.Namespace.Name)
225225

226226
ginkgo.By("Removing cronjob")
227227
err = deleteCronJob(f.ClientSet, f.Namespace.Name, cronJob.Name)
228-
gomega.Expect(err).NotTo(gomega.HaveOccurred(), "Failed to remove %s cronjob in namespace %s", cronJob.Name, f.Namespace.Name)
228+
framework.ExpectNoError(err, "Failed to remove %s cronjob in namespace %s", cronJob.Name, f.Namespace.Name)
229229
})
230230

231231
// cleanup of successful finished jobs, with limit of one successful job
@@ -235,37 +235,37 @@ var _ = SIGDescribe("CronJob", func() {
235235
cronJob := newTestCronJob("concurrent-limit", "*/1 * * * ?", batchv1beta1.AllowConcurrent,
236236
successCommand, &successLimit)
237237
cronJob, err := createCronJob(f.ClientSet, f.Namespace.Name, cronJob)
238-
gomega.Expect(err).NotTo(gomega.HaveOccurred(), "Failed to create allowconcurrent cronjob with custom history limits in namespace %s", f.Namespace.Name)
238+
framework.ExpectNoError(err, "Failed to create allowconcurrent cronjob with custom history limits in namespace %s", f.Namespace.Name)
239239

240240
// Job is going to complete instantly: do not check for an active job
241241
// as we are most likely to miss it
242242

243243
ginkgo.By("Ensuring a finished job exists")
244244
err = waitForAnyFinishedJob(f.ClientSet, f.Namespace.Name)
245-
gomega.Expect(err).NotTo(gomega.HaveOccurred(), "Failed to ensure a finished cronjob exists in namespace %s", f.Namespace.Name)
245+
framework.ExpectNoError(err, "Failed to ensure a finished cronjob exists in namespace %s", f.Namespace.Name)
246246

247247
ginkgo.By("Ensuring a finished job exists by listing jobs explicitly")
248248
jobs, err := f.ClientSet.BatchV1().Jobs(f.Namespace.Name).List(metav1.ListOptions{})
249-
gomega.Expect(err).NotTo(gomega.HaveOccurred(), "Failed to ensure a finished cronjob exists by listing jobs explicitly in namespace %s", f.Namespace.Name)
249+
framework.ExpectNoError(err, "Failed to ensure a finished cronjob exists by listing jobs explicitly in namespace %s", f.Namespace.Name)
250250
_, finishedJobs := filterActiveJobs(jobs)
251251
gomega.Expect(len(finishedJobs) == 1).To(gomega.BeTrue())
252252

253253
// Job should get deleted when the next job finishes the next minute
254254
ginkgo.By("Ensuring this job and its pods does not exist anymore")
255255
err = waitForJobToDisappear(f.ClientSet, f.Namespace.Name, finishedJobs[0])
256-
gomega.Expect(err).NotTo(gomega.HaveOccurred(), "Failed to ensure that job does not exists anymore in namespace %s", f.Namespace.Name)
256+
framework.ExpectNoError(err, "Failed to ensure that job does not exists anymore in namespace %s", f.Namespace.Name)
257257
err = waitForJobsPodToDisappear(f.ClientSet, f.Namespace.Name, finishedJobs[0])
258-
gomega.Expect(err).NotTo(gomega.HaveOccurred(), "Failed to ensure that pods for job does not exists anymore in namespace %s", f.Namespace.Name)
258+
framework.ExpectNoError(err, "Failed to ensure that pods for job does not exists anymore in namespace %s", f.Namespace.Name)
259259

260260
ginkgo.By("Ensuring there is 1 finished job by listing jobs explicitly")
261261
jobs, err = f.ClientSet.BatchV1().Jobs(f.Namespace.Name).List(metav1.ListOptions{})
262-
gomega.Expect(err).NotTo(gomega.HaveOccurred(), "Failed to ensure there is one finished job by listing job explicitly in namespace %s", f.Namespace.Name)
262+
framework.ExpectNoError(err, "Failed to ensure there is one finished job by listing job explicitly in namespace %s", f.Namespace.Name)
263263
_, finishedJobs = filterActiveJobs(jobs)
264264
gomega.Expect(len(finishedJobs) == 1).To(gomega.BeTrue())
265265

266266
ginkgo.By("Removing cronjob")
267267
err = deleteCronJob(f.ClientSet, f.Namespace.Name, cronJob.Name)
268-
gomega.Expect(err).NotTo(gomega.HaveOccurred(), "Failed to remove the %s cronjob in namespace %s", cronJob.Name, f.Namespace.Name)
268+
framework.ExpectNoError(err, "Failed to remove the %s cronjob in namespace %s", cronJob.Name, f.Namespace.Name)
269269
})
270270
})
271271

test/e2e/apps/daemon_restart.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ import (
3737
imageutils "k8s.io/kubernetes/test/utils/image"
3838

3939
"github.com/onsi/ginkgo"
40-
"github.com/onsi/gomega"
4140
)
4241

4342
// This test primarily checks 2 things:
@@ -115,7 +114,7 @@ func (r *RestartDaemonConfig) waitUp() {
115114
func (r *RestartDaemonConfig) kill() {
116115
framework.Logf("Killing %v", r)
117116
_, err := framework.NodeExec(r.nodeName, fmt.Sprintf("pgrep %v | xargs -I {} sudo kill {}", r.daemonName))
118-
gomega.Expect(err).NotTo(gomega.HaveOccurred())
117+
framework.ExpectNoError(err)
119118
}
120119

121120
// Restart checks if the daemon is up, kills it, and waits till it comes back up
@@ -208,7 +207,7 @@ var _ = SIGDescribe("DaemonRestart [Disruptive]", func() {
208207
Replicas: numPods,
209208
CreatedPods: &[]*v1.Pod{},
210209
}
211-
gomega.Expect(framework.RunRC(config)).NotTo(gomega.HaveOccurred())
210+
framework.ExpectNoError(framework.RunRC(config))
212211
replacePods(*config.CreatedPods, existingPods)
213212

214213
stopCh = make(chan struct{})

test/e2e/apps/disruption.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ var _ = SIGDescribe("DisruptionController", func() {
7272
}
7373
return pdb.Status.PodDisruptionsAllowed > 0, nil
7474
})
75-
gomega.Expect(err).NotTo(gomega.HaveOccurred())
75+
framework.ExpectNoError(err)
7676
})
7777

7878
evictionCases := []struct {
@@ -179,7 +179,7 @@ var _ = SIGDescribe("DisruptionController", func() {
179179

180180
return false, nil
181181
})
182-
gomega.Expect(err).NotTo(gomega.HaveOccurred())
182+
framework.ExpectNoError(err)
183183

184184
e := &policy.Eviction{
185185
ObjectMeta: metav1.ObjectMeta{
@@ -210,7 +210,7 @@ var _ = SIGDescribe("DisruptionController", func() {
210210
}
211211
return true, nil
212212
})
213-
gomega.Expect(err).NotTo(gomega.HaveOccurred())
213+
framework.ExpectNoError(err)
214214
}
215215
})
216216
}
@@ -228,7 +228,7 @@ func createPDBMinAvailableOrDie(cs kubernetes.Interface, ns string, minAvailable
228228
},
229229
}
230230
_, err := cs.PolicyV1beta1().PodDisruptionBudgets(ns).Create(&pdb)
231-
gomega.Expect(err).NotTo(gomega.HaveOccurred())
231+
framework.ExpectNoError(err)
232232
}
233233

234234
func createPDBMaxUnavailableOrDie(cs kubernetes.Interface, ns string, maxUnavailable intstr.IntOrString) {
@@ -243,7 +243,7 @@ func createPDBMaxUnavailableOrDie(cs kubernetes.Interface, ns string, maxUnavail
243243
},
244244
}
245245
_, err := cs.PolicyV1beta1().PodDisruptionBudgets(ns).Create(&pdb)
246-
gomega.Expect(err).NotTo(gomega.HaveOccurred())
246+
framework.ExpectNoError(err)
247247
}
248248

249249
func createPodsOrDie(cs kubernetes.Interface, ns string, n int) {

0 commit comments

Comments
 (0)