diff --git a/ghttp/handlers.go b/ghttp/handlers.go index f9c2fcb..531f89d 100644 --- a/ghttp/handlers.go +++ b/ghttp/handlers.go @@ -8,10 +8,8 @@ import ( "fmt" "net/http" "net/url" - "reflect" "strings" - "github.com/golang/protobuf/proto" "github.com/bsm/gomega" . "github.com/bsm/gomega" "github.com/bsm/gomega/internal/gutil" @@ -174,32 +173,6 @@ func (g GHTTPWithGomega) VerifyFormKV(key string, values ...string) http.Handler return g.VerifyForm(url.Values{key: values}) } -//VerifyProtoRepresenting returns a handler that verifies that the body of the request is a valid protobuf -//representation of the passed message. -// -//VerifyProtoRepresenting also verifies that the request's content type is application/x-protobuf -func (g GHTTPWithGomega) VerifyProtoRepresenting(expected proto.Message) http.HandlerFunc { - return CombineHandlers( - g.VerifyContentType("application/x-protobuf"), - func(w http.ResponseWriter, req *http.Request) { - body, err := gutil.ReadAll(req.Body) - g.gomega.Expect(err).ShouldNot(HaveOccurred()) - req.Body.Close() - - expectedType := reflect.TypeOf(expected) - actualValuePtr := reflect.New(expectedType.Elem()) - - actual, ok := actualValuePtr.Interface().(proto.Message) - g.gomega.Expect(ok).Should(BeTrue(), "Message value is not a proto.Message") - - err = proto.Unmarshal(body, actual) - g.gomega.Expect(err).ShouldNot(HaveOccurred(), "Failed to unmarshal protobuf") - - g.gomega.Expect(actual).Should(Equal(expected), "ProtoBuf Mismatch") - }, - ) -} - func copyHeader(src http.Header, dst http.Header) { for key, value := range src { dst[key] = value @@ -309,31 +282,6 @@ func (g GHTTPWithGomega) RespondWithJSONEncodedPtr(statusCode *int, object inter } } -//RespondWithProto returns a handler that responds to a request with the specified status code and a body -//containing the protobuf serialization of the provided message. -// -//Also, RespondWithProto can be given an optional http.Header. The headers defined therein will be added to the response headers. -func (g GHTTPWithGomega) RespondWithProto(statusCode int, message proto.Message, optionalHeader ...http.Header) http.HandlerFunc { - return func(w http.ResponseWriter, req *http.Request) { - data, err := proto.Marshal(message) - g.gomega.Expect(err).ShouldNot(HaveOccurred()) - - var headers http.Header - if len(optionalHeader) == 1 { - headers = optionalHeader[0] - } else { - headers = make(http.Header) - } - if _, found := headers["Content-Type"]; !found { - headers["Content-Type"] = []string{"application/x-protobuf"} - } - copyHeader(headers, w.Header()) - - w.WriteHeader(statusCode) - w.Write(data) - } -} - func VerifyRequest(method string, path interface{}, rawQuery ...string) http.HandlerFunc { return NewGHTTPWithGomega(gomega.Default).VerifyRequest(method, path, rawQuery...) } @@ -378,10 +326,6 @@ func VerifyFormKV(key string, values ...string) http.HandlerFunc { return NewGHTTPWithGomega(gomega.Default).VerifyFormKV(key, values...) } -func VerifyProtoRepresenting(expected proto.Message) http.HandlerFunc { - return NewGHTTPWithGomega(gomega.Default).VerifyProtoRepresenting(expected) -} - func RespondWith(statusCode int, body interface{}, optionalHeader ...http.Header) http.HandlerFunc { return NewGHTTPWithGomega(gomega.Default).RespondWith(statusCode, body, optionalHeader...) } @@ -397,7 +341,3 @@ func RespondWithJSONEncoded(statusCode int, object interface{}, optionalHeader . func RespondWithJSONEncodedPtr(statusCode *int, object interface{}, optionalHeader ...http.Header) http.HandlerFunc { return NewGHTTPWithGomega(gomega.Default).RespondWithJSONEncodedPtr(statusCode, object, optionalHeader...) } - -func RespondWithProto(statusCode int, message proto.Message, optionalHeader ...http.Header) http.HandlerFunc { - return NewGHTTPWithGomega(gomega.Default).RespondWithProto(statusCode, message, optionalHeader...) -} diff --git a/matchers.go b/matchers.go index f43c89c..d34f877 100644 --- a/matchers.go +++ b/matchers.go @@ -3,7 +3,6 @@ package gomega import ( "time" - "github.com/google/go-cmp/cmp" "github.com/bsm/gomega/matchers" "github.com/bsm/gomega/types" ) @@ -27,16 +26,6 @@ func BeEquivalentTo(expected interface{}) types.GomegaMatcher { } } -// BeComparableTo uses gocmp.Equal from github.com/google/go-cmp (instead of reflect.DeepEqual) to perform a deep comparison. -// You can pass cmp.Option as options. -// It is an error for actual and expected to be nil. Use BeNil() instead. -func BeComparableTo(expected interface{}, opts ...cmp.Option) types.GomegaMatcher { - return &matchers.BeComparableToMatcher{ - Expected: expected, - Options: opts, - } -} - // BeIdenticalTo uses the == operator to compare actual with expected. // BeIdenticalTo is strict about types when performing comparisons. // It is an error for both actual and expected to be nil. Use BeNil() instead. @@ -233,24 +222,6 @@ func MatchJSON(json interface{}) types.GomegaMatcher { } } -// MatchXML succeeds if actual is a string or stringer of XML that matches -// the expected XML. The XMLs are decoded and the resulting objects are compared via -// reflect.DeepEqual so things like whitespaces shouldn't matter. -func MatchXML(xml interface{}) types.GomegaMatcher { - return &matchers.MatchXMLMatcher{ - XMLToMatch: xml, - } -} - -// MatchYAML succeeds if actual is a string or stringer of YAML that matches -// the expected YAML. The YAML's are decoded and the resulting objects are compared via -// reflect.DeepEqual so things like key-ordering and whitespace shouldn't matter. -func MatchYAML(yaml interface{}) types.GomegaMatcher { - return &matchers.MatchYAMLMatcher{ - YAMLToMatch: yaml, - } -} - // BeEmpty succeeds if actual is empty. Actual must be of type string, array, map, chan, or slice. func BeEmpty() types.GomegaMatcher { return &matchers.BeEmptyMatcher{}