You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Protobuf equality doesn't work with the default Equal matcher because protobufs have special fields. The best way to test protobuf equality is using proto.Equal. I'm proposing a simple matcher that uses protobuf.Equal.
Something like this:
// EqualProto succeeds if actual proto matches the passed-in proto.
func EqualProto(message proto.Message) types.GomegaMatcher {
return &equalProtoMatcher{message: message}
}
type equalProtoMatcher struct {
message proto.Message
}
func (matcher *equalProtoMatcher) Match(actual interface{}) (bool, error) {
message, ok := actual.(proto.Message)
if !ok {
return false, fmt.Errorf("EqualProto matcher expects a proto message. Got:\n%s", format.Object(actual, 1))
}
return proto.Equal(message, matcher.message), nil
}
func (matcher *equalProtoMatcher) FailureMessage(actual interface{}) string {
return format.Message(actual, "to equal", matcher.message)
}
func (matcher *equalProtoMatcher) NegatedFailureMessage(actual interface{}) string {
return format.Message(actual, "not to equal %v", matcher.message)
}
The text was updated successfully, but these errors were encountered:
Related issue regarding time.Time: #264. Both time.Time and protobufs follow the convention of having an Equal method of the form "(T) Equal(T) bool". Thoughts about special casing this form of Equal method?
Protobuf equality doesn't work with the default Equal matcher because protobufs have special fields. The best way to test protobuf equality is using proto.Equal. I'm proposing a simple matcher that uses protobuf.Equal.
Something like this:
The text was updated successfully, but these errors were encountered: