uber-go / mock

GoMock is a mocking framework for the Go programming language.
Apache License 2.0
1.85k stars 106 forks source link

Proto specific comparison #61

Closed elb3k closed 11 months ago

elb3k commented 11 months ago

Gomock is used with GRPC services. And sometimes there is an error when matching the proto messages. Using proto.Equal if the arguments are proto messages will be helpful.

CLAassistant commented 11 months ago

CLA assistant check
All committers have signed the CLA.

r-hang commented 11 months ago

I believe gomock's default matcher should not take on technology specific dependencies outside of go's standard ecosystem.

If proto specific logic is added, there's an argument that thrift specific logic should be added and so on and so forth which increases the maintenance burden of this library. Looking at this change, a custom matcher for this use case seems sufficient.

r-hang commented 11 months ago

Wont fix. We can continue to discuss this in an issue or a Discussion but any change for gomock's default matchers should be proto agnostic.

Sample code for a custom proto matcher.

type protoMatcher struct{ msg proto.Message }

var _ gomock.Matcher = (*protoMatcher)(nil)

func (m *protoMatcher) String() string { / *... TODO .. */ }

func (m *protoMatcher) Matches(x any) bool {
  other, ok := x.(proto.Message)
  if !ok { return false }

  return proto.Equal(m.msg, other)
}