Skip to content

Commit 4365444

Browse files
author
Kenichi Omichi
committed
Add ExpectError() to e2e test framework
There is a lot of gomega.Expect(err).To(gomega.HaveOccurred()) callers which expect an error happens in e2e tests. However these test code seems confusing because the code readers need to take care of To() or NotTo() on each test scenario. This adds ExpectError() for more readable test code. In addition, this applies ExpectError() to e2e provisioning.go as a sample.
1 parent 22b6c69 commit 4365444

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

test/e2e/framework/util.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2038,6 +2038,11 @@ func RandomSuffix() string {
20382038
return strconv.Itoa(r.Int() % 10000)
20392039
}
20402040

2041+
// ExpectError expects an error happens, otherwise an exception raises
2042+
func ExpectError(err error, explain ...interface{}) {
2043+
gomega.Expect(err).To(gomega.HaveOccurred(), explain...)
2044+
}
2045+
20412046
// ExpectNoError checks if "err" is set, and if so, fails assertion while logging the error.
20422047
func ExpectNoError(err error, explain ...interface{}) {
20432048
ExpectNoErrorWithOffset(1, err, explain...)

test/e2e/storage/testsuites/provisioning.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ func (t StorageClassTest) TestBindingWaitForFirstConsumerMultiPVC(claims []*v1.P
484484
// Wait for ClaimProvisionTimeout (across all PVCs in parallel) and make sure the phase did not become Bound i.e. the Wait errors out
485485
By("checking the claims are in pending state")
486486
err = framework.WaitForPersistentVolumeClaimsPhase(v1.ClaimBound, t.Client, namespace, claimNames, 2*time.Second /* Poll */, framework.ClaimProvisionShortTimeout, true)
487-
Expect(err).To(HaveOccurred())
487+
framework.ExpectError(err)
488488
verifyPVCsPending(t.Client, createdClaims)
489489

490490
By("creating a pod referring to the claims")

0 commit comments

Comments
 (0)