2016-05-22 13:04:37 +00:00
|
|
|
package matchers
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2018-10-08 13:14:49 +00:00
|
|
|
|
2016-05-22 13:04:37 +00:00
|
|
|
"github.com/onsi/gomega/format"
|
|
|
|
)
|
|
|
|
|
|
|
|
type HaveOccurredMatcher struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
func (matcher *HaveOccurredMatcher) Match(actual interface{}) (success bool, err error) {
|
2018-10-08 13:14:49 +00:00
|
|
|
// is purely nil?
|
|
|
|
if actual == nil {
|
2016-05-22 13:04:37 +00:00
|
|
|
return false, nil
|
|
|
|
}
|
|
|
|
|
2018-10-08 13:14:49 +00:00
|
|
|
// must be an 'error' type
|
|
|
|
if !isError(actual) {
|
|
|
|
return false, fmt.Errorf("Expected an error-type. Got:\n%s", format.Object(actual, 1))
|
2016-05-22 13:04:37 +00:00
|
|
|
}
|
|
|
|
|
2018-10-08 13:14:49 +00:00
|
|
|
// must be non-nil (or a pointer to a non-nil)
|
|
|
|
return !isNil(actual), nil
|
2016-05-22 13:04:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (matcher *HaveOccurredMatcher) FailureMessage(actual interface{}) (message string) {
|
|
|
|
return fmt.Sprintf("Expected an error to have occurred. Got:\n%s", format.Object(actual, 1))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (matcher *HaveOccurredMatcher) NegatedFailureMessage(actual interface{}) (message string) {
|
|
|
|
return fmt.Sprintf("Expected error:\n%s\n%s\n%s", format.Object(actual, 1), format.IndentString(actual.(error).Error(), 1), "not to have occurred")
|
|
|
|
}
|