5 "github.com/onsi/gomega/format"
9 type MatchErrorMatcher struct {
13 func (matcher *MatchErrorMatcher) Match(actual interface{}) (success bool, err error) {
15 return false, fmt.Errorf("Expected an error, got nil")
19 return false, fmt.Errorf("Expected an error. Got:\n%s", format.Object(actual, 1))
22 actualErr := actual.(error)
24 if isString(matcher.Expected) {
25 return reflect.DeepEqual(actualErr.Error(), matcher.Expected), nil
28 if isError(matcher.Expected) {
29 return reflect.DeepEqual(actualErr, matcher.Expected), nil
32 var subMatcher omegaMatcher
33 var hasSubMatcher bool
34 if matcher.Expected != nil {
35 subMatcher, hasSubMatcher = (matcher.Expected).(omegaMatcher)
37 return subMatcher.Match(actualErr.Error())
41 return false, fmt.Errorf("MatchError must be passed an error, string, or Matcher that can match on strings. Got:\n%s", format.Object(matcher.Expected, 1))
44 func (matcher *MatchErrorMatcher) FailureMessage(actual interface{}) (message string) {
45 return format.Message(actual, "to match error", matcher.Expected)
48 func (matcher *MatchErrorMatcher) NegatedFailureMessage(actual interface{}) (message string) {
49 return format.Message(actual, "not to match error", matcher.Expected)