Documentation ¶
Overview ¶
Package errxpect supplies Gomega with assertions for mult-return value functions for simpler error testing.
A typical use of the errxpect package is by importing it into the in the current file's file block for easy reference without needing the package name.
import . "github.com/thediveo/errxpect"
Before, Gomega forced you to write assertions where you are only interested in checking the error return value of a multi-return value function:
// func multifoo() (string, int, error) { ... } _, _, err := multifoo() Expect(err).To(Succeed())
This can now be rewritten in a more concise form as (something which isn't allowed in stock Gomega Expect-ations):
Errxpect(multifoo()).To(HaveOccured())
ExpectWithError() needs to be slightly phrased differently, due to Golang's language restrictions, but probably even more neat now:
Errxpect(multifoo()).WithOffset(1).To(Succeed())
Index ¶
- type ErrorAssertion
- func (errorassertion *ErrorAssertion) NotTo(matcher types.GomegaMatcher, optionalDescription ...interface{}) bool
- func (errorassertion *ErrorAssertion) Should(matcher types.GomegaMatcher, optionalDescription ...interface{}) bool
- func (errorassertion *ErrorAssertion) ShouldNot(matcher types.GomegaMatcher, optionalDescription ...interface{}) bool
- func (errorassertion *ErrorAssertion) To(matcher types.GomegaMatcher, optionalDescription ...interface{}) bool
- func (errorassertion *ErrorAssertion) ToNot(matcher types.GomegaMatcher, optionalDescription ...interface{}) bool
- func (errorassertion *ErrorAssertion) WithOffset(offset int) *ErrorAssertion
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ErrorAssertion ¶ added in v0.9.1
type ErrorAssertion struct {
// contains filtered or unexported fields
}
ErrorAssertion implements the GomegaMatcher interface, while checking that actual multi-value returns are only consisting of the trailing error and all other return values must be zero.
func Errxpect ¶
func Errxpect(actual ...interface{}) *ErrorAssertion
Errxpect wraps an actual multi-value allowing error assertions to be made on it:
func foo() (string, bool, error) { return "", false, errors.New("DOH!") } Errxpect(foo()).To(HaveOccured())
As Golang doesn't feature automatic multi-return value passing into a varargs function if there are additional parameters present, use WithOffset() on the return value of Errxpect, such as:
Errxpect(foo()).WithOffset(1).To(Succeed())
func (*ErrorAssertion) NotTo ¶ added in v0.9.1
func (errorassertion *ErrorAssertion) NotTo(matcher types.GomegaMatcher, optionalDescription ...interface{}) bool
NotTo makes an assertion that should not be true.
func (*ErrorAssertion) Should ¶ added in v0.9.1
func (errorassertion *ErrorAssertion) Should(matcher types.GomegaMatcher, optionalDescription ...interface{}) bool
Should makes an assertion that should be true.
func (*ErrorAssertion) ShouldNot ¶ added in v0.9.1
func (errorassertion *ErrorAssertion) ShouldNot(matcher types.GomegaMatcher, optionalDescription ...interface{}) bool
ShouldNot makes an assertion that should not be true.
func (*ErrorAssertion) To ¶ added in v0.9.1
func (errorassertion *ErrorAssertion) To(matcher types.GomegaMatcher, optionalDescription ...interface{}) bool
To makes an assertion that should be true.
func (*ErrorAssertion) ToNot ¶ added in v0.9.1
func (errorassertion *ErrorAssertion) ToNot(matcher types.GomegaMatcher, optionalDescription ...interface{}) bool
ToNot makes an assertion that should not be true.
func (*ErrorAssertion) WithOffset ¶ added in v0.9.1
func (errorassertion *ErrorAssertion) WithOffset(offset int) *ErrorAssertion
WithOffset replaces ExpectWithOffset() when using Errxpect in order to modify the call-stack offset when computing line numbers.
This is most useful in helper functions that make assertions. If you want Gomega's error message to refer to the calling line in the test (as opposed to the line in the helper function) set the argument of `Errxpect(...).WithOffset(offset)` appropriately.