@@ -28,8 +28,8 @@ func NewGHTTPWithGomega(gomega Gomega) *GHTTPWithGomega {
28
28
}
29
29
}
30
30
31
- //CombineHandler takes variadic list of handlers and produces one handler
32
- //that calls each handler in order.
31
+ // CombineHandler takes variadic list of handlers and produces one handler
32
+ // that calls each handler in order.
33
33
func CombineHandlers (handlers ... http.HandlerFunc ) http.HandlerFunc {
34
34
return func (w http.ResponseWriter , req * http.Request ) {
35
35
for _ , handler := range handlers {
@@ -38,11 +38,11 @@ func CombineHandlers(handlers ...http.HandlerFunc) http.HandlerFunc {
38
38
}
39
39
}
40
40
41
- //VerifyRequest returns a handler that verifies that a request uses the specified method to connect to the specified path
42
- //You may also pass in an optional rawQuery string which is tested against the request's `req.URL.RawQuery`
41
+ // VerifyRequest returns a handler that verifies that a request uses the specified method to connect to the specified path
42
+ // You may also pass in an optional rawQuery string which is tested against the request's `req.URL.RawQuery`
43
43
//
44
- //For path, you may pass in a string, in which case strict equality will be applied
45
- //Alternatively you can pass in a matcher (ContainSubstring("/foo") and MatchRegexp("/foo/[a-f0-9]+") for example)
44
+ // For path, you may pass in a string, in which case strict equality will be applied
45
+ // Alternatively you can pass in a matcher (ContainSubstring("/foo") and MatchRegexp("/foo/[a-f0-9]+") for example)
46
46
func (g GHTTPWithGomega ) VerifyRequest (method string , path interface {}, rawQuery ... string ) http.HandlerFunc {
47
47
return func (w http.ResponseWriter , req * http.Request ) {
48
48
g .gomega .Expect (req .Method ).Should (Equal (method ), "Method mismatch" )
@@ -61,24 +61,24 @@ func (g GHTTPWithGomega) VerifyRequest(method string, path interface{}, rawQuery
61
61
}
62
62
}
63
63
64
- //VerifyContentType returns a handler that verifies that a request has a Content-Type header set to the
65
- //specified value
64
+ // VerifyContentType returns a handler that verifies that a request has a Content-Type header set to the
65
+ // specified value
66
66
func (g GHTTPWithGomega ) VerifyContentType (contentType string ) http.HandlerFunc {
67
67
return func (w http.ResponseWriter , req * http.Request ) {
68
68
g .gomega .Expect (req .Header .Get ("Content-Type" )).Should (Equal (contentType ))
69
69
}
70
70
}
71
71
72
- //VerifyMimeType returns a handler that verifies that a request has a specified mime type set
73
- //in Content-Type header
72
+ // VerifyMimeType returns a handler that verifies that a request has a specified mime type set
73
+ // in Content-Type header
74
74
func (g GHTTPWithGomega ) VerifyMimeType (mimeType string ) http.HandlerFunc {
75
75
return func (w http.ResponseWriter , req * http.Request ) {
76
76
g .gomega .Expect (strings .Split (req .Header .Get ("Content-Type" ), ";" )[0 ]).Should (Equal (mimeType ))
77
77
}
78
78
}
79
79
80
- //VerifyBasicAuth returns a handler that verifies the request contains a BasicAuth Authorization header
81
- //matching the passed in username and password
80
+ // VerifyBasicAuth returns a handler that verifies the request contains a BasicAuth Authorization header
81
+ // matching the passed in username and password
82
82
func (g GHTTPWithGomega ) VerifyBasicAuth (username string , password string ) http.HandlerFunc {
83
83
return func (w http.ResponseWriter , req * http.Request ) {
84
84
auth := req .Header .Get ("Authorization" )
@@ -91,11 +91,11 @@ func (g GHTTPWithGomega) VerifyBasicAuth(username string, password string) http.
91
91
}
92
92
}
93
93
94
- //VerifyHeader returns a handler that verifies the request contains the passed in headers.
95
- //The passed in header keys are first canonicalized via http.CanonicalHeaderKey.
94
+ // VerifyHeader returns a handler that verifies the request contains the passed in headers.
95
+ // The passed in header keys are first canonicalized via http.CanonicalHeaderKey.
96
96
//
97
- //The request must contain *all* the passed in headers, but it is allowed to have additional headers
98
- //beyond the passed in set.
97
+ // The request must contain *all* the passed in headers, but it is allowed to have additional headers
98
+ // beyond the passed in set.
99
99
func (g GHTTPWithGomega ) VerifyHeader (header http.Header ) http.HandlerFunc {
100
100
return func (w http.ResponseWriter , req * http.Request ) {
101
101
for key , values := range header {
@@ -105,9 +105,9 @@ func (g GHTTPWithGomega) VerifyHeader(header http.Header) http.HandlerFunc {
105
105
}
106
106
}
107
107
108
- //VerifyHeaderKV returns a handler that verifies the request contains a header matching the passed in key and values
109
- //(recall that a `http.Header` is a mapping from string (key) to []string (values))
110
- //It is a convenience wrapper around `VerifyHeader` that allows you to avoid having to create an `http.Header` object.
108
+ // VerifyHeaderKV returns a handler that verifies the request contains a header matching the passed in key and values
109
+ // (recall that a `http.Header` is a mapping from string (key) to []string (values))
110
+ // It is a convenience wrapper around `VerifyHeader` that allows you to avoid having to create an `http.Header` object.
111
111
func (g GHTTPWithGomega ) VerifyHeaderKV (key string , values ... string ) http.HandlerFunc {
112
112
return g .VerifyHeader (http.Header {key : values })
113
113
}
@@ -127,8 +127,8 @@ func (g GHTTPWithGomega) VerifyHost(host interface{}) http.HandlerFunc {
127
127
}
128
128
}
129
129
130
- //VerifyBody returns a handler that verifies that the body of the request matches the passed in byte array.
131
- //It does this using Equal().
130
+ // VerifyBody returns a handler that verifies that the body of the request matches the passed in byte array.
131
+ // It does this using Equal().
132
132
func (g GHTTPWithGomega ) VerifyBody (expectedBody []byte ) http.HandlerFunc {
133
133
return CombineHandlers (
134
134
func (w http.ResponseWriter , req * http.Request ) {
@@ -140,10 +140,10 @@ func (g GHTTPWithGomega) VerifyBody(expectedBody []byte) http.HandlerFunc {
140
140
)
141
141
}
142
142
143
- //VerifyJSON returns a handler that verifies that the body of the request is a valid JSON representation
144
- //matching the passed in JSON string. It does this using Gomega's MatchJSON method
143
+ // VerifyJSON returns a handler that verifies that the body of the request is a valid JSON representation
144
+ // matching the passed in JSON string. It does this using Gomega's MatchJSON method
145
145
//
146
- //VerifyJSON also verifies that the request's content type is application/json
146
+ // VerifyJSON also verifies that the request's content type is application/json
147
147
func (g GHTTPWithGomega ) VerifyJSON (expectedJSON string ) http.HandlerFunc {
148
148
return CombineHandlers (
149
149
g .VerifyMimeType ("application/json" ),
@@ -156,9 +156,9 @@ func (g GHTTPWithGomega) VerifyJSON(expectedJSON string) http.HandlerFunc {
156
156
)
157
157
}
158
158
159
- //VerifyJSONRepresenting is similar to VerifyJSON. Instead of taking a JSON string, however, it
160
- //takes an arbitrary JSON-encodable object and verifies that the requests's body is a JSON representation
161
- //that matches the object
159
+ // VerifyJSONRepresenting is similar to VerifyJSON. Instead of taking a JSON string, however, it
160
+ // takes an arbitrary JSON-encodable object and verifies that the requests's body is a JSON representation
161
+ // that matches the object
162
162
func (g GHTTPWithGomega ) VerifyJSONRepresenting (object interface {}) http.HandlerFunc {
163
163
data , err := json .Marshal (object )
164
164
g .gomega .Expect (err ).ShouldNot (HaveOccurred ())
@@ -168,10 +168,10 @@ func (g GHTTPWithGomega) VerifyJSONRepresenting(object interface{}) http.Handler
168
168
)
169
169
}
170
170
171
- //VerifyForm returns a handler that verifies a request contains the specified form values.
171
+ // VerifyForm returns a handler that verifies a request contains the specified form values.
172
172
//
173
- //The request must contain *all* of the specified values, but it is allowed to have additional
174
- //form values beyond the passed in set.
173
+ // The request must contain *all* of the specified values, but it is allowed to have additional
174
+ // form values beyond the passed in set.
175
175
func (g GHTTPWithGomega ) VerifyForm (values url.Values ) http.HandlerFunc {
176
176
return func (w http.ResponseWriter , r * http.Request ) {
177
177
err := r .ParseForm ()
@@ -182,17 +182,17 @@ func (g GHTTPWithGomega) VerifyForm(values url.Values) http.HandlerFunc {
182
182
}
183
183
}
184
184
185
- //VerifyFormKV returns a handler that verifies a request contains a form key with the specified values.
185
+ // VerifyFormKV returns a handler that verifies a request contains a form key with the specified values.
186
186
//
187
- //It is a convenience wrapper around `VerifyForm` that lets you avoid having to create a `url.Values` object.
187
+ // It is a convenience wrapper around `VerifyForm` that lets you avoid having to create a `url.Values` object.
188
188
func (g GHTTPWithGomega ) VerifyFormKV (key string , values ... string ) http.HandlerFunc {
189
189
return g .VerifyForm (url.Values {key : values })
190
190
}
191
191
192
- //VerifyProtoRepresenting returns a handler that verifies that the body of the request is a valid protobuf
193
- //representation of the passed message.
192
+ // VerifyProtoRepresenting returns a handler that verifies that the body of the request is a valid protobuf
193
+ // representation of the passed message.
194
194
//
195
- //VerifyProtoRepresenting also verifies that the request's content type is application/x-protobuf
195
+ // VerifyProtoRepresenting also verifies that the request's content type is application/x-protobuf
196
196
func (g GHTTPWithGomega ) VerifyProtoRepresenting (expected proto.Message ) http.HandlerFunc {
197
197
return CombineHandlers (
198
198
g .VerifyContentType ("application/x-protobuf" ),
@@ -205,7 +205,7 @@ func (g GHTTPWithGomega) VerifyProtoRepresenting(expected proto.Message) http.Ha
205
205
actualValuePtr := reflect .New (expectedType .Elem ())
206
206
207
207
actual , ok := actualValuePtr .Interface ().(proto.Message )
208
- g .gomega .Expect (ok ).Should (BeTrue (), "Message value is not a proto.Message" )
208
+ g .gomega .Expect (ok ).Should (BeTrueBecause ( "Message value should be a proto.Message" ) )
209
209
210
210
err = proto .Unmarshal (body , actual )
211
211
g .gomega .Expect (err ).ShouldNot (HaveOccurred (), "Failed to unmarshal protobuf" )
@@ -324,10 +324,10 @@ func (g GHTTPWithGomega) RespondWithJSONEncodedPtr(statusCode *int, object inter
324
324
}
325
325
}
326
326
327
- //RespondWithProto returns a handler that responds to a request with the specified status code and a body
328
- //containing the protobuf serialization of the provided message.
327
+ // RespondWithProto returns a handler that responds to a request with the specified status code and a body
328
+ // containing the protobuf serialization of the provided message.
329
329
//
330
- //Also, RespondWithProto can be given an optional http.Header. The headers defined therein will be added to the response headers.
330
+ // Also, RespondWithProto can be given an optional http.Header. The headers defined therein will be added to the response headers.
331
331
func (g GHTTPWithGomega ) RespondWithProto (statusCode int , message proto.Message , optionalHeader ... http.Header ) http.HandlerFunc {
332
332
return func (w http.ResponseWriter , req * http.Request ) {
333
333
data , err := proto .Marshal (message )
0 commit comments