query string test

This commit is contained in:
Martin Algesten
2018-06-17 00:25:40 +02:00
parent 6b63aab605
commit 9514bd2743
8 changed files with 76 additions and 41 deletions

View File

@@ -14,6 +14,19 @@ fn content_length_on_str() {
assert!(s.contains("\r\nContent-Length: 14\r\n"));
}
#[test]
fn user_set_content_length_on_str() {
test::set_handler("/user_set_content_length_on_str", |_req, _url| {
test::make_response(200, "OK", vec![], vec![])
});
let resp = get("test://host/user_set_content_length_on_str")
.set("Content-Length", "12345")
.send_str("Hello World!!!");
let vec = resp.to_write_vec();
let s = String::from_utf8_lossy(&vec);
assert!(s.contains("\r\nContent-Length: 12345\r\n"));
}
#[test]
fn content_length_on_json() {
test::set_handler("/content_length_on_json", |_req, _url| {

View File

@@ -12,6 +12,7 @@ mod agent_test;
mod auth;
mod body_read;
mod body_send;
mod query_string;
mod simple;
type RequestHandler = Fn(&Request, &Url) -> Result<Stream, Error> + Send + 'static;

29
src/test/query_string.rs Normal file
View File

@@ -0,0 +1,29 @@
use test;
use super::super::*;
#[test]
fn no_query_string() {
test::set_handler("/no_query_string", |_req, _url| {
test::make_response(200, "OK", vec![], vec![])
});
let resp = get("test://host/no_query_string")
.call();
let vec = resp.to_write_vec();
let s = String::from_utf8_lossy(&vec);
assert!(s.contains("GET /no_query_string HTTP/1.1"))
}
#[test]
fn escaped_query_string() {
test::set_handler("/escaped_query_string", |_req, _url| {
test::make_response(200, "OK", vec![], vec![])
});
let resp = get("test://host/escaped_query_string")
.query("foo", "bar")
.query("baz", "yo lo")
.call();
let vec = resp.to_write_vec();
let s = String::from_utf8_lossy(&vec);
assert!(s.contains("GET /escaped_query_string?foo=bar&baz=yo%20lo HTTP/1.1"))
}