mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-10-19 13:49:53 +00:00
fb7dc13dfe
updated few packages in go.mod to latest available release. Signed-off-by: Madhu Rajanna <madhupr007@gmail.com>
56 lines
1.3 KiB
Go
56 lines
1.3 KiB
Go
package matchers
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"reflect"
|
|
|
|
"github.com/onsi/gomega/format"
|
|
)
|
|
|
|
type MatchErrorMatcher struct {
|
|
Expected interface{}
|
|
}
|
|
|
|
func (matcher *MatchErrorMatcher) Match(actual interface{}) (success bool, err error) {
|
|
if isNil(actual) {
|
|
return false, fmt.Errorf("Expected an error, got nil")
|
|
}
|
|
|
|
if !isError(actual) {
|
|
return false, fmt.Errorf("Expected an error. Got:\n%s", format.Object(actual, 1))
|
|
}
|
|
|
|
actualErr := actual.(error)
|
|
expected := matcher.Expected
|
|
|
|
if isError(expected) {
|
|
return reflect.DeepEqual(actualErr, expected) || errors.Is(actualErr, expected.(error)), nil
|
|
}
|
|
|
|
if isString(expected) {
|
|
return actualErr.Error() == expected, nil
|
|
}
|
|
|
|
var subMatcher omegaMatcher
|
|
var hasSubMatcher bool
|
|
if expected != nil {
|
|
subMatcher, hasSubMatcher = (expected).(omegaMatcher)
|
|
if hasSubMatcher {
|
|
return subMatcher.Match(actualErr.Error())
|
|
}
|
|
}
|
|
|
|
return false, fmt.Errorf(
|
|
"MatchError must be passed an error, a string, or a Matcher that can match on strings. Got:\n%s",
|
|
format.Object(expected, 1))
|
|
}
|
|
|
|
func (matcher *MatchErrorMatcher) FailureMessage(actual interface{}) (message string) {
|
|
return format.Message(actual, "to match error", matcher.Expected)
|
|
}
|
|
|
|
func (matcher *MatchErrorMatcher) NegatedFailureMessage(actual interface{}) (message string) {
|
|
return format.Message(actual, "not to match error", matcher.Expected)
|
|
}
|