test all resp.into_xxx()
This commit is contained in:
@@ -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");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user