-
Notifications
You must be signed in to change notification settings - Fork 1
/
update.patch
153 lines (146 loc) · 5.79 KB
/
update.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
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{}