add form-urlencoded unit test
This commit is contained in:
		| @@ -43,6 +43,10 @@ matrix: | |||||||
| sudo: false | sudo: false | ||||||
| dist: trusty | dist: trusty | ||||||
|  |  | ||||||
|  | env: | ||||||
|  |   global: | ||||||
|  |     - REQWEST_TEST_BODY_FULL=1 | ||||||
|  |  | ||||||
| script: | script: | ||||||
|   - cargo build $FEATURES |   - cargo build $FEATURES | ||||||
|   - cargo test -v $FEATURES |   - cargo test -v $FEATURES | ||||||
|   | |||||||
| @@ -172,6 +172,41 @@ fn test_post() { | |||||||
|     assert_eq!(n, 0) |     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 | /// Calling `Response::error_for_status`` on a response with status in 4xx | ||||||
| /// returns a error. | /// returns a error. | ||||||
| #[test] | #[test] | ||||||
|   | |||||||
| @@ -99,13 +99,15 @@ pub fn spawn(txns: Vec<Txn>) -> Server { | |||||||
|  |  | ||||||
|             match (::std::str::from_utf8(&expected), ::std::str::from_utf8(&buf[..n])) { |             match (::std::str::from_utf8(&expected), ::std::str::from_utf8(&buf[..n])) { | ||||||
|                 (Ok(expected), Ok(received)) => { |                 (Ok(expected), Ok(received)) => { | ||||||
|                     assert_eq!( |                     if expected.len() > 300 && ::std::env::var("REQWEST_TEST_BODY_FULL").is_err() { | ||||||
|                         expected.len(), |                         assert_eq!( | ||||||
|                         received.len(), |                             expected.len(), | ||||||
|                         "expected len = {}, received len = {}", |                             received.len(), | ||||||
|                         expected.len(), |                             "expected len = {}, received len = {}; to skip length check and see exact contents, re-run with REQWEST_TEST_BODY_FULL=1", | ||||||
|                         received.len(), |                             expected.len(), | ||||||
|                     ); |                             received.len(), | ||||||
|  |                         ); | ||||||
|  |                     } | ||||||
|                     assert_eq!(expected, received) |                     assert_eq!(expected, received) | ||||||
|                 }, |                 }, | ||||||
|                 _ => { |                 _ => { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user