Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 5520c76

Browse filesBrowse files
committed
Merge pull request revel#610 from thereallisa/master
Added MakeMultipartRequest() to the TestSuite
2 parents 1a28d0c + 3aefe7a commit 5520c76
Copy full SHA for 5520c76

File tree

Expand file treeCollapse file tree

1 file changed

+21
-0
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+21
-0
lines changed

‎tests.go

Copy file name to clipboardExpand all lines: tests.go
+21Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"fmt"
77
"io"
88
"io/ioutil"
9+
"mime/multipart"
910
"net/http"
1011
"net/http/cookiejar"
1112
"net/url"
@@ -92,6 +93,26 @@ func (t *TestSuite) PostForm(path string, data url.Values) {
9293
t.Post(path, "application/x-www-form-urlencoded", strings.NewReader(data.Encode()))
9394
}
9495

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+
95116
// Issue any request and read the response. If successful, the caller may
96117
// examine the Response and ResponseBody properties. Session data will be
97118
// added to the request cookies for you.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.