add form-urlencoded unit test

This commit is contained in:
Sean McArthur
2019-02-13 11:46:12 -08:00
parent 4dc679d535
commit 7eae51f56e
3 changed files with 48 additions and 7 deletions

View File

@@ -172,6 +172,41 @@ fn test_post() {
assert_eq!(n, 0)
}
#[test]
fn test_post_form() {
let server = server! {
request: b"\
POST /form HTTP/1.1\r\n\
user-agent: $USERAGENT\r\n\
accept: */*\r\n\
content-type: application/x-www-form-urlencoded\r\n\
content-length: 24\r\n\
accept-encoding: gzip\r\n\
host: $HOST\r\n\
\r\n\
hello=world&sean=monstar\
",
response: b"\
HTTP/1.1 200 OK\r\n\
Server: post-form\r\n\
Content-Length: 0\r\n\
\r\n\
"
};
let form = &[("hello", "world"), ("sean", "monstar")];
let url = format!("http://{}/form", server.addr());
let res = reqwest::Client::new()
.post(&url)
.form(form)
.send()
.expect("request send");
assert_eq!(res.url().as_str(), &url);
assert_eq!(res.status(), reqwest::StatusCode::OK);
}
/// Calling `Response::error_for_status`` on a response with status in 4xx
/// returns a error.
#[test]