File tree Expand file tree Collapse file tree 2 files changed +34
-1
lines changed Expand file tree Collapse file tree 2 files changed +34
-1
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ require (
1010 github.com/onsi/ginkgo/v2 v2.13.1
1111 github.com/onsi/gomega v1.30.0
1212 google.golang.org/grpc v1.65.0
13+ google.golang.org/protobuf v1.34.1
1314 gopkg.in/yaml.v2 v2.4.0
1415 k8s.io/klog/v2 v2.130.1
1516)
@@ -24,6 +25,5 @@ require (
2425 golang.org/x/text v0.15.0 // indirect
2526 golang.org/x/tools v0.14.0 // indirect
2627 google.golang.org/genproto/googleapis/rpc v0.0.0-20240528184218-531527333157 // indirect
27- google.golang.org/protobuf v1.34.1 // indirect
2828 gopkg.in/yaml.v3 v3.0.1 // indirect
2929)
Original file line number Diff line number Diff line change 1+ package utils
2+
3+ import (
4+ "github.com/golang/mock/gomock"
5+ "google.golang.org/protobuf/encoding/prototext"
6+ "google.golang.org/protobuf/proto"
7+ )
8+
9+ // Protobuf returns a Matcher that relies upon proto.Equal to compare Protobuf messages
10+ // Example usage with mocked request:
11+ //
12+ // example.EXPECT().ExampleRequest(Protobuf(requestMsg)).Return(responseMsg, nil).AnyTimes()
13+ func Protobuf (msg proto.Message ) gomock.Matcher {
14+ return & ProtobufMatcher {msg }
15+ }
16+
17+ type ProtobufMatcher struct {
18+ msg proto.Message
19+ }
20+
21+ var _ gomock.Matcher = & ProtobufMatcher {}
22+
23+ func (p * ProtobufMatcher ) Matches (x interface {}) bool {
24+ otherMsg , ok := x .(proto.Message )
25+ if ! ok {
26+ return false
27+ }
28+ return proto .Equal (p .msg , otherMsg )
29+ }
30+
31+ func (p * ProtobufMatcher ) String () string {
32+ return prototext .Format (p .msg )
33+ }
You can’t perform that action at this time.
0 commit comments