test all resp.into_xxx()

This commit is contained in:
Martin Algesten
2018-06-11 21:21:44 +02:00
parent d548b3ef4f
commit 5be3aef553
2 changed files with 31 additions and 2 deletions

View File

@@ -9,7 +9,7 @@
- [x] Header handling
- [x] Transfer-Encoding: chunked
- [x] Ergonomic JSON handling
- [ ] Test harness for end-to-end tests
- [x] Test harness for end-to-end tests
- [ ] Limit read length on Content-Size
- [ ] Auth headers
- [ ] Cookie jar in agent

View File

@@ -1,6 +1,8 @@
use super::super::*;
use std::io::Read;
use test;
use super::super::*;
#[test]
fn header_passing() {
test::set_handler("/header_passing", |req, _url| {
@@ -23,3 +25,30 @@ fn body_as_text() {
let text = resp.into_string().unwrap();
assert_eq!(text, "Hello World!");
}
#[test]
fn body_as_json() {
test::set_handler("/body_as_json", |_req, _url| {
test::make_stream(
200,
"OK",
vec![],
"{\"hello\":\"world\"}".to_string().into_bytes(),
)
});
let resp = get("test://host/body_as_json").call();
let json = resp.into_json().unwrap();
assert_eq!(json["hello"], "world");
}
#[test]
fn body_as_reader() {
test::set_handler("/body_as_reader", |_req, _url| {
test::make_stream(200, "OK", vec![], "abcdefgh".to_string().into_bytes())
});
let resp = get("test://host/body_as_reader").call();
let mut reader = resp.into_reader();
let mut text = String::new();
reader.read_to_string(&mut text).unwrap();
assert_eq!(text, "abcdefgh");
}