File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed
Filter options
Expand file tree Collapse file tree 1 file changed +21
-0
lines changed
Original file line number Diff line number Diff line change 6
6
"fmt"
7
7
"io"
8
8
"io/ioutil"
9
+ "mime/multipart"
9
10
"net/http"
10
11
"net/http/cookiejar"
11
12
"net/url"
@@ -92,6 +93,26 @@ func (t *TestSuite) PostForm(path string, data url.Values) {
92
93
t .Post (path , "application/x-www-form-urlencoded" , strings .NewReader (data .Encode ()))
93
94
}
94
95
96
+ // Issue a multipart request for the method & fields given and read the response.
97
+ // If successful, the caller may examine the Response and ResponseBody properties.
98
+ func (t * TestSuite ) MakeMultipartRequest (method string , path string , fields map [string ]string ) {
99
+ var b bytes.Buffer
100
+ w := multipart .NewWriter (& b )
101
+
102
+ for key , value := range fields {
103
+ w .WriteField (key , value )
104
+ }
105
+ w .Close () //adds the terminating boundary
106
+
107
+ req , err := http .NewRequest (method , t .BaseUrl ()+ path , & b )
108
+ if err != nil {
109
+ panic (err )
110
+ }
111
+ req .Header .Set ("Content-Type" , w .FormDataContentType ())
112
+
113
+ t .MakeRequest (req )
114
+ }
115
+
95
116
// Issue any request and read the response. If successful, the caller may
96
117
// examine the Response and ResponseBody properties. Session data will be
97
118
// added to the request cookies for you.
You can’t perform that action at this time.
0 commit comments