mirror-to-gitea/vendor/github.com/onsi/gomega/matchers/have_occurred_matcher.go
vendor/github.com/onsi/gomega/matchers/have_occurred_matcher.goRaw
1// untested sections: 2
2
3package matchers
4
5import (
6 "fmt"
7
8 "github.com/onsi/gomega/format"
9)
10
11type HaveOccurredMatcher struct {
12}
13
14func (matcher *HaveOccurredMatcher) Match(actual interface{}) (success bool, err error) {
15 // is purely nil?
16 if actual == nil {
17 return false, nil
18 }
19
20 // must be an 'error' type
21 if !isError(actual) {
22 return false, fmt.Errorf("Expected an error-type. Got:\n%s", format.Object(actual, 1))
23 }
24
25 // must be non-nil (or a pointer to a non-nil)
26 return !isNil(actual), nil
27}
28
29func (matcher *HaveOccurredMatcher) FailureMessage(actual interface{}) (message string) {
30 return fmt.Sprintf("Expected an error to have occurred. Got:\n%s", format.Object(actual, 1))
31}
32
33func (matcher *HaveOccurredMatcher) NegatedFailureMessage(actual interface{}) (message string) {
34 return fmt.Sprintf("Unexpected error:\n%s\n%s\n%s", format.Object(actual, 1), format.IndentString(actual.(error).Error(), 1), "occurred")
35}