File tree 2 files changed +34
-1
lines changed
2 files changed +34
-1
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ require (
10
10
github.com/onsi/ginkgo/v2 v2.13.1
11
11
github.com/onsi/gomega v1.30.0
12
12
google.golang.org/grpc v1.65.0
13
+ google.golang.org/protobuf v1.34.1
13
14
gopkg.in/yaml.v2 v2.4.0
14
15
k8s.io/klog/v2 v2.130.1
15
16
)
@@ -24,6 +25,5 @@ require (
24
25
golang.org/x/text v0.15.0 // indirect
25
26
golang.org/x/tools v0.14.0 // indirect
26
27
google.golang.org/genproto/googleapis/rpc v0.0.0-20240528184218-531527333157 // indirect
27
- google.golang.org/protobuf v1.34.1 // indirect
28
28
gopkg.in/yaml.v3 v3.0.1 // indirect
29
29
)
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