Commit 43654448 authored by Kenichi Omichi's avatar Kenichi Omichi

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.
parent 22b6c699
...@@ -2038,6 +2038,11 @@ func RandomSuffix() string { ...@@ -2038,6 +2038,11 @@ func RandomSuffix() string {
return strconv.Itoa(r.Int() % 10000) return strconv.Itoa(r.Int() % 10000)
} }
// ExpectError expects an error happens, otherwise an exception raises
func ExpectError(err error, explain ...interface{}) {
gomega.Expect(err).To(gomega.HaveOccurred(), explain...)
}
// ExpectNoError checks if "err" is set, and if so, fails assertion while logging the error. // ExpectNoError checks if "err" is set, and if so, fails assertion while logging the error.
func ExpectNoError(err error, explain ...interface{}) { func ExpectNoError(err error, explain ...interface{}) {
ExpectNoErrorWithOffset(1, err, explain...) ExpectNoErrorWithOffset(1, err, explain...)
......
...@@ -484,7 +484,7 @@ func (t StorageClassTest) TestBindingWaitForFirstConsumerMultiPVC(claims []*v1.P ...@@ -484,7 +484,7 @@ func (t StorageClassTest) TestBindingWaitForFirstConsumerMultiPVC(claims []*v1.P
// Wait for ClaimProvisionTimeout (across all PVCs in parallel) and make sure the phase did not become Bound i.e. the Wait errors out // Wait for ClaimProvisionTimeout (across all PVCs in parallel) and make sure the phase did not become Bound i.e. the Wait errors out
By("checking the claims are in pending state") By("checking the claims are in pending state")
err = framework.WaitForPersistentVolumeClaimsPhase(v1.ClaimBound, t.Client, namespace, claimNames, 2*time.Second /* Poll */, framework.ClaimProvisionShortTimeout, true) err = framework.WaitForPersistentVolumeClaimsPhase(v1.ClaimBound, t.Client, namespace, claimNames, 2*time.Second /* Poll */, framework.ClaimProvisionShortTimeout, true)
Expect(err).To(HaveOccurred()) framework.ExpectError(err)
verifyPVCsPending(t.Client, createdClaims) verifyPVCsPending(t.Client, createdClaims)
By("creating a pod referring to the claims") By("creating a pod referring to the claims")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment