mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-10-19 13:49:53 +00:00
aad99ebcb7
Bumps [github.com/onsi/gomega](https://github.com/onsi/gomega) from 1.19.0 to 1.20.0. - [Release notes](https://github.com/onsi/gomega/releases) - [Changelog](https://github.com/onsi/gomega/blob/master/CHANGELOG.md) - [Commits](https://github.com/onsi/gomega/compare/v1.19.0...v1.20.0) --- updated-dependencies: - dependency-name: github.com/onsi/gomega dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com>
50 lines
1.5 KiB
Go
50 lines
1.5 KiB
Go
package matchers
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
|
|
"github.com/google/go-cmp/cmp"
|
|
"github.com/onsi/gomega/format"
|
|
)
|
|
|
|
type BeComparableToMatcher struct {
|
|
Expected interface{}
|
|
Options cmp.Options
|
|
}
|
|
|
|
func (matcher *BeComparableToMatcher) Match(actual interface{}) (success bool, matchErr error) {
|
|
if actual == nil && matcher.Expected == nil {
|
|
return false, fmt.Errorf("Refusing to compare <nil> to <nil>.\nBe explicit and use BeNil() instead. This is to avoid mistakes where both sides of an assertion are erroneously uninitialized.")
|
|
}
|
|
// Shortcut for byte slices.
|
|
// Comparing long byte slices with reflect.DeepEqual is very slow,
|
|
// so use bytes.Equal if actual and expected are both byte slices.
|
|
if actualByteSlice, ok := actual.([]byte); ok {
|
|
if expectedByteSlice, ok := matcher.Expected.([]byte); ok {
|
|
return bytes.Equal(actualByteSlice, expectedByteSlice), nil
|
|
}
|
|
}
|
|
|
|
defer func() {
|
|
if r := recover(); r != nil {
|
|
success = false
|
|
if err, ok := r.(error); ok {
|
|
matchErr = err
|
|
} else if errMsg, ok := r.(string); ok {
|
|
matchErr = fmt.Errorf(errMsg)
|
|
}
|
|
}
|
|
}()
|
|
|
|
return cmp.Equal(actual, matcher.Expected, matcher.Options...), nil
|
|
}
|
|
|
|
func (matcher *BeComparableToMatcher) FailureMessage(actual interface{}) (message string) {
|
|
return cmp.Diff(matcher.Expected, actual, matcher.Options)
|
|
}
|
|
|
|
func (matcher *BeComparableToMatcher) NegatedFailureMessage(actual interface{}) (message string) {
|
|
return format.Message(actual, "not to equal", matcher.Expected)
|
|
}
|