Skip to content

Commit a350b95

Browse files
jbduncanonsi
authored andcommitted
Maintain source backwards compatibility
1 parent a6c8875 commit a350b95

File tree

2 files changed

+12
-15
lines changed

2 files changed

+12
-15
lines changed

ghttp/handlers.go

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import (
1616
"github.com/onsi/gomega/internal/gutil"
1717
"github.com/onsi/gomega/types"
1818
"google.golang.org/protobuf/proto"
19+
"google.golang.org/protobuf/protoadapt"
20+
"google.golang.org/protobuf/runtime/protoiface"
1921
)
2022

2123
type GHTTPWithGomega struct {
@@ -193,7 +195,7 @@ func (g GHTTPWithGomega) VerifyFormKV(key string, values ...string) http.Handler
193195
// representation of the passed message.
194196
//
195197
// VerifyProtoRepresenting also verifies that the request's content type is application/x-protobuf
196-
func (g GHTTPWithGomega) VerifyProtoRepresenting(expected proto.Message) http.HandlerFunc {
198+
func (g GHTTPWithGomega) VerifyProtoRepresenting(expected protoiface.MessageV1) http.HandlerFunc {
197199
return CombineHandlers(
198200
g.VerifyContentType("application/x-protobuf"),
199201
func(w http.ResponseWriter, req *http.Request) {
@@ -204,13 +206,14 @@ func (g GHTTPWithGomega) VerifyProtoRepresenting(expected proto.Message) http.Ha
204206
expectedType := reflect.TypeOf(expected)
205207
actualValuePtr := reflect.New(expectedType.Elem())
206208

207-
actual, ok := actualValuePtr.Interface().(proto.Message)
208-
g.gomega.Expect(ok).Should(BeTrueBecause("Message value should be a proto.Message"))
209+
actual, ok := actualValuePtr.Interface().(protoiface.MessageV1)
210+
g.gomega.Expect(ok).Should(BeTrueBecause("Message value should be a protoiface.MessageV1"))
209211

210-
err = proto.Unmarshal(body, actual)
212+
err = proto.Unmarshal(body, protoadapt.MessageV2Of(actual))
211213
g.gomega.Expect(err).ShouldNot(HaveOccurred(), "Failed to unmarshal protobuf")
212214

213-
g.gomega.Expect(proto.Equal(expected, actual)).Should(BeTrue(), "ProtoBuf Mismatch")
215+
g.gomega.Expect(proto.Equal(protoadapt.MessageV2Of(expected), protoadapt.MessageV2Of(actual))).
216+
Should(BeTrue(), "ProtoBuf Mismatch")
214217
},
215218
)
216219
}
@@ -328,9 +331,9 @@ func (g GHTTPWithGomega) RespondWithJSONEncodedPtr(statusCode *int, object inter
328331
// containing the protobuf serialization of the provided message.
329332
//
330333
// Also, RespondWithProto can be given an optional http.Header. The headers defined therein will be added to the response headers.
331-
func (g GHTTPWithGomega) RespondWithProto(statusCode int, message proto.Message, optionalHeader ...http.Header) http.HandlerFunc {
334+
func (g GHTTPWithGomega) RespondWithProto(statusCode int, message protoadapt.MessageV1, optionalHeader ...http.Header) http.HandlerFunc {
332335
return func(w http.ResponseWriter, req *http.Request) {
333-
data, err := proto.Marshal(message)
336+
data, err := proto.Marshal(protoadapt.MessageV2Of(message))
334337
g.gomega.Expect(err).ShouldNot(HaveOccurred())
335338

336339
var headers http.Header
@@ -397,7 +400,7 @@ func VerifyFormKV(key string, values ...string) http.HandlerFunc {
397400
return NewGHTTPWithGomega(gomega.Default).VerifyFormKV(key, values...)
398401
}
399402

400-
func VerifyProtoRepresenting(expected proto.Message) http.HandlerFunc {
403+
func VerifyProtoRepresenting(expected protoiface.MessageV1) http.HandlerFunc {
401404
return NewGHTTPWithGomega(gomega.Default).VerifyProtoRepresenting(expected)
402405
}
403406

@@ -417,6 +420,6 @@ func RespondWithJSONEncodedPtr(statusCode *int, object interface{}, optionalHead
417420
return NewGHTTPWithGomega(gomega.Default).RespondWithJSONEncodedPtr(statusCode, object, optionalHeader...)
418421
}
419422

420-
func RespondWithProto(statusCode int, message proto.Message, optionalHeader ...http.Header) http.HandlerFunc {
423+
func RespondWithProto(statusCode int, message protoadapt.MessageV1, optionalHeader ...http.Header) http.HandlerFunc {
421424
return NewGHTTPWithGomega(gomega.Default).RespondWithProto(statusCode, message, optionalHeader...)
422425
}

go.sum

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ github.com/go-logr/logr v1.3.0 h1:2y3SDp0ZXuc6/cjLSZ+Q3ir+QB9T/iG5yYRXqsagWSY=
88
github.com/go-logr/logr v1.3.0/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
99
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI=
1010
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572/go.mod h1:9Pwr4B2jHnOSGXyyzV8ROjYa2ojvAY6HCGYYfMoC3Ls=
11-
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
12-
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
1311
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
1412
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
1513
github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38 h1:yAJXTCF9TqKcTiHJAE8dj7HMvPfh66eeA2JYW7eFpSE=
@@ -31,10 +29,6 @@ golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
3129
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
3230
golang.org/x/tools v0.16.1 h1:TLyB3WofjdOEepBHAU20JdNC1Zbg87elYofWYAY5oZA=
3331
golang.org/x/tools v0.16.1/go.mod h1:kYVVN6I1mBNoB1OX+noeBjbRk4IUEPa7JJ+TJMEooJ0=
34-
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
35-
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
36-
google.golang.org/protobuf v1.28.0 h1:w43yiav+6bVFTBQFZX0r7ipe9JQ1QsbMgHwbBziscLw=
37-
google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
3832
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
3933
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
4034
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=

0 commit comments

Comments
 (0)