test all resp.into_xxx()
This commit is contained in:
@@ -9,7 +9,7 @@
|
|||||||
- [x] Header handling
|
- [x] Header handling
|
||||||
- [x] Transfer-Encoding: chunked
|
- [x] Transfer-Encoding: chunked
|
||||||
- [x] Ergonomic JSON handling
|
- [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
|
- [ ] Limit read length on Content-Size
|
||||||
- [ ] Auth headers
|
- [ ] Auth headers
|
||||||
- [ ] Cookie jar in agent
|
- [ ] Cookie jar in agent
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
use super::super::*;
|
use std::io::Read;
|
||||||
use test;
|
use test;
|
||||||
|
|
||||||
|
use super::super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn header_passing() {
|
fn header_passing() {
|
||||||
test::set_handler("/header_passing", |req, _url| {
|
test::set_handler("/header_passing", |req, _url| {
|
||||||
@@ -23,3 +25,30 @@ fn body_as_text() {
|
|||||||
let text = resp.into_string().unwrap();
|
let text = resp.into_string().unwrap();
|
||||||
assert_eq!(text, "Hello World!");
|
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