New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to match error with boolean function? #425
Comments
Expect(err).NotTo(HaveOccurred()) Does this help? |
or if you want to assert the exact error you can:
that's the actual error.
|
@onsi Thanks for helping. My original use case is that, I have a library, which returns library specific error and provides What I want to test is wheter my error is Expect(err).To(Or(BeNil(), MatchError(IsXXXError))) As you can see, since I want to use it inside I think those Moreover, can we have a quick way to convert arbitrary My current workaround is to use an if statement like: if err := DoSomething(); err != nil {
Expect(IsXXXError(err)).To(BeTrue())
} But it's long and doesn't give me useful error message when it fails. Gomega just says "false is not true". |
hey @kaoet I think your best bet here is to make one custom matcher that takes a Something like:
I imagine such a matcher would not be too hard to write - but let me know if you'd like some help with it. |
A helper function is another approach: err := DoSomething()
checkError(err) func checkError(err error) {
switch err.(type) {
case nil, OtherAcceptableErrorType:
return
default:
ExpectWithOffset(1, err).NotTo(HaveOccurred(), "extra message can be added here")
}
}
} |
Hi @kaoet. Have the responses above been helpful? |
@blgm No, finally we implemented a I'm always thinking |
I want to test whether my
err
is "not exist", I foundos.IsNotExist()
in the standard library. How can I use it in my tests? I'm wondering something likeBut that doesn't work.
The text was updated successfully, but these errors were encountered: