@@ -94,6 +94,16 @@ func (tr *TestResponse) TestRequest(method, url string, postData *url.Values, he
94
94
return tr
95
95
}
96
96
97
+ // TestReaderRequest will execute a fiber.App().Test() on the given request data and return a TestResponse.
98
+ func (tr * TestResponse ) TestReaderRequest (method , url string , reader io.Reader , headers * http.Header ) * TestResponse {
99
+ req := createReaderRequest (method , tr .makeUrl (url ), reader , headers )
100
+ resp , _ := tr .suite .App ().Test (req , 15000 )
101
+
102
+ tr .response = resp
103
+ tr .request = req
104
+ return tr
105
+ }
106
+
97
107
// BodyReader returns the response body as io.ReadCloser.
98
108
//
99
109
// See: https://stackoverflow.com/a/60098300 for information about this issue.
@@ -376,6 +386,24 @@ func convertUrlValuesToJson(values *url.Values) string {
376
386
return jsonString
377
387
}
378
388
389
+ // createReaderRequest helper function to create httptest requests
390
+ func createReaderRequest (method , url string , reader io.Reader , headers * http.Header ) * http.Request {
391
+ req := httptest .NewRequest (method , url , reader )
392
+
393
+ if headers != nil {
394
+ // add the parameter headers into the requests headers
395
+ for key , value := range * headers {
396
+ req .Header .Add (key , value [0 ])
397
+ }
398
+ }
399
+
400
+ if req .Header .Get (fiber .HeaderContentType ) == "" {
401
+ req .Header .Set (fiber .HeaderContentType , fiber .MIMEApplicationForm )
402
+ }
403
+
404
+ return req
405
+ }
406
+
379
407
// createRequest helper function to create httptest requests
380
408
func createRequest (method , url string , postData * url.Values , headers * http.Header ) * http.Request {
381
409
var req * http.Request
0 commit comments