mirror of
https://github.com/octoleo/syncthing.git
synced 2024-11-20 03:51:00 +00:00
28 lines
826 B
Go
28 lines
826 B
Go
|
package matchers
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"reflect"
|
||
|
|
||
|
"github.com/onsi/gomega/format"
|
||
|
)
|
||
|
|
||
|
type EqualMatcher struct {
|
||
|
Expected interface{}
|
||
|
}
|
||
|
|
||
|
func (matcher *EqualMatcher) Match(actual interface{}) (success bool, err 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.")
|
||
|
}
|
||
|
return reflect.DeepEqual(actual, matcher.Expected), nil
|
||
|
}
|
||
|
|
||
|
func (matcher *EqualMatcher) FailureMessage(actual interface{}) (message string) {
|
||
|
return format.Message(actual, "to equal", matcher.Expected)
|
||
|
}
|
||
|
|
||
|
func (matcher *EqualMatcher) NegatedFailureMessage(actual interface{}) (message string) {
|
||
|
return format.Message(actual, "not to equal", matcher.Expected)
|
||
|
}
|