mirror of
https://github.com/actix/actix-web.git
synced 2024-12-22 16:16:40 +00:00
update payload tests
This commit is contained in:
parent
c44e4ad100
commit
83862dfbb4
1 changed files with 22 additions and 66 deletions
|
@ -12,6 +12,7 @@ use error::PayloadError;
|
||||||
pub(crate) const DEFAULT_BUFFER_SIZE: usize = 65_536; // max buffer size 64k
|
pub(crate) const DEFAULT_BUFFER_SIZE: usize = 65_536; // max buffer size 64k
|
||||||
|
|
||||||
/// Just Bytes object
|
/// Just Bytes object
|
||||||
|
#[derive(PartialEq)]
|
||||||
pub struct PayloadItem(pub Bytes);
|
pub struct PayloadItem(pub Bytes);
|
||||||
|
|
||||||
impl ResponseType for PayloadItem {
|
impl ResponseType for PayloadItem {
|
||||||
|
@ -366,11 +367,7 @@ mod tests {
|
||||||
assert!(!payload.eof());
|
assert!(!payload.eof());
|
||||||
assert!(payload.is_empty());
|
assert!(payload.is_empty());
|
||||||
assert_eq!(payload.len(), 0);
|
assert_eq!(payload.len(), 0);
|
||||||
|
assert_eq!(Async::NotReady, payload.readany().ok().unwrap());
|
||||||
match payload.readany() {
|
|
||||||
Ok(Async::NotReady) => (),
|
|
||||||
_ => panic!("error"),
|
|
||||||
}
|
|
||||||
|
|
||||||
let res: Result<(), ()> = Ok(());
|
let res: Result<(), ()> = Ok(());
|
||||||
result(res)
|
result(res)
|
||||||
|
@ -382,11 +379,7 @@ mod tests {
|
||||||
Core::new().unwrap().run(lazy(|| {
|
Core::new().unwrap().run(lazy(|| {
|
||||||
let (mut sender, mut payload) = Payload::new(false);
|
let (mut sender, mut payload) = Payload::new(false);
|
||||||
|
|
||||||
match payload.readany() {
|
assert_eq!(Async::NotReady, payload.readany().ok().unwrap());
|
||||||
Ok(Async::NotReady) => (),
|
|
||||||
_ => panic!("error"),
|
|
||||||
}
|
|
||||||
|
|
||||||
assert!(!payload.eof());
|
assert!(!payload.eof());
|
||||||
|
|
||||||
sender.feed_data(Bytes::from("data"));
|
sender.feed_data(Bytes::from("data"));
|
||||||
|
@ -394,18 +387,13 @@ mod tests {
|
||||||
|
|
||||||
assert!(!payload.eof());
|
assert!(!payload.eof());
|
||||||
|
|
||||||
match payload.readany() {
|
assert_eq!(Async::Ready(Some(PayloadItem(Bytes::from("data")))),
|
||||||
Ok(Async::Ready(Some(data))) => assert_eq!(&data.0, "data"),
|
payload.readany().ok().unwrap());
|
||||||
_ => panic!("error"),
|
|
||||||
}
|
|
||||||
assert!(payload.is_empty());
|
assert!(payload.is_empty());
|
||||||
assert!(payload.eof());
|
assert!(payload.eof());
|
||||||
assert_eq!(payload.len(), 0);
|
assert_eq!(payload.len(), 0);
|
||||||
|
|
||||||
match payload.readany() {
|
assert_eq!(Async::Ready(None), payload.readany().ok().unwrap());
|
||||||
Ok(Async::Ready(None)) => (),
|
|
||||||
_ => panic!("error"),
|
|
||||||
}
|
|
||||||
let res: Result<(), ()> = Ok(());
|
let res: Result<(), ()> = Ok(());
|
||||||
result(res)
|
result(res)
|
||||||
})).unwrap();
|
})).unwrap();
|
||||||
|
@ -416,16 +404,10 @@ mod tests {
|
||||||
Core::new().unwrap().run(lazy(|| {
|
Core::new().unwrap().run(lazy(|| {
|
||||||
let (mut sender, mut payload) = Payload::new(false);
|
let (mut sender, mut payload) = Payload::new(false);
|
||||||
|
|
||||||
match payload.readany() {
|
assert_eq!(Async::NotReady, payload.readany().ok().unwrap());
|
||||||
Ok(Async::NotReady) => (),
|
|
||||||
_ => panic!("error"),
|
|
||||||
}
|
|
||||||
|
|
||||||
sender.set_error(PayloadError::Incomplete);
|
sender.set_error(PayloadError::Incomplete);
|
||||||
match payload.readany() {
|
payload.readany().err().unwrap();
|
||||||
Err(_) => (),
|
|
||||||
_ => panic!("error"),
|
|
||||||
}
|
|
||||||
let res: Result<(), ()> = Ok(());
|
let res: Result<(), ()> = Ok(());
|
||||||
result(res)
|
result(res)
|
||||||
})).unwrap();
|
})).unwrap();
|
||||||
|
@ -445,10 +427,8 @@ mod tests {
|
||||||
assert!(!payload.is_empty());
|
assert!(!payload.is_empty());
|
||||||
assert_eq!(payload.len(), 10);
|
assert_eq!(payload.len(), 10);
|
||||||
|
|
||||||
match payload.readany() {
|
assert_eq!(Async::Ready(Some(PayloadItem(Bytes::from("line1")))),
|
||||||
Ok(Async::Ready(Some(data))) => assert_eq!(&data.0, "line1"),
|
payload.readany().ok().unwrap());
|
||||||
_ => panic!("error"),
|
|
||||||
}
|
|
||||||
assert!(!payload.is_empty());
|
assert!(!payload.is_empty());
|
||||||
assert_eq!(payload.len(), 5);
|
assert_eq!(payload.len(), 5);
|
||||||
|
|
||||||
|
@ -462,32 +442,20 @@ mod tests {
|
||||||
Core::new().unwrap().run(lazy(|| {
|
Core::new().unwrap().run(lazy(|| {
|
||||||
let (mut sender, mut payload) = Payload::new(false);
|
let (mut sender, mut payload) = Payload::new(false);
|
||||||
|
|
||||||
match payload.readexactly(2) {
|
assert_eq!(Async::NotReady, payload.readexactly(2).ok().unwrap());
|
||||||
Ok(Async::NotReady) => (),
|
|
||||||
_ => panic!("error"),
|
|
||||||
}
|
|
||||||
|
|
||||||
sender.feed_data(Bytes::from("line1"));
|
sender.feed_data(Bytes::from("line1"));
|
||||||
sender.feed_data(Bytes::from("line2"));
|
sender.feed_data(Bytes::from("line2"));
|
||||||
assert_eq!(payload.len(), 10);
|
assert_eq!(payload.len(), 10);
|
||||||
|
|
||||||
match payload.readexactly(2) {
|
assert_eq!(Async::Ready(Bytes::from("li")), payload.readexactly(2).ok().unwrap());
|
||||||
Ok(Async::Ready(data)) => assert_eq!(&data, "li"),
|
|
||||||
_ => panic!("error"),
|
|
||||||
}
|
|
||||||
assert_eq!(payload.len(), 8);
|
assert_eq!(payload.len(), 8);
|
||||||
|
|
||||||
match payload.readexactly(4) {
|
assert_eq!(Async::Ready(Bytes::from("ne1l")), payload.readexactly(4).ok().unwrap());
|
||||||
Ok(Async::Ready(data)) => assert_eq!(&data, "ne1l"),
|
|
||||||
_ => panic!("error"),
|
|
||||||
}
|
|
||||||
assert_eq!(payload.len(), 4);
|
assert_eq!(payload.len(), 4);
|
||||||
|
|
||||||
sender.set_error(PayloadError::Incomplete);
|
sender.set_error(PayloadError::Incomplete);
|
||||||
match payload.readexactly(10) {
|
payload.readexactly(10).err().unwrap();
|
||||||
Err(_) => (),
|
|
||||||
_ => panic!("error"),
|
|
||||||
}
|
|
||||||
|
|
||||||
let res: Result<(), ()> = Ok(());
|
let res: Result<(), ()> = Ok(());
|
||||||
result(res)
|
result(res)
|
||||||
|
@ -499,32 +467,22 @@ mod tests {
|
||||||
Core::new().unwrap().run(lazy(|| {
|
Core::new().unwrap().run(lazy(|| {
|
||||||
let (mut sender, mut payload) = Payload::new(false);
|
let (mut sender, mut payload) = Payload::new(false);
|
||||||
|
|
||||||
match payload.readuntil(b"ne") {
|
assert_eq!(Async::NotReady, payload.readuntil(b"ne").ok().unwrap());
|
||||||
Ok(Async::NotReady) => (),
|
|
||||||
_ => panic!("error"),
|
|
||||||
}
|
|
||||||
|
|
||||||
sender.feed_data(Bytes::from("line1"));
|
sender.feed_data(Bytes::from("line1"));
|
||||||
sender.feed_data(Bytes::from("line2"));
|
sender.feed_data(Bytes::from("line2"));
|
||||||
assert_eq!(payload.len(), 10);
|
assert_eq!(payload.len(), 10);
|
||||||
|
|
||||||
match payload.readuntil(b"ne") {
|
assert_eq!(Async::Ready(Bytes::from("line")),
|
||||||
Ok(Async::Ready(data)) => assert_eq!(&data, "line"),
|
payload.readuntil(b"ne").ok().unwrap());
|
||||||
_ => panic!("error"),
|
|
||||||
}
|
|
||||||
assert_eq!(payload.len(), 6);
|
assert_eq!(payload.len(), 6);
|
||||||
|
|
||||||
match payload.readuntil(b"2") {
|
assert_eq!(Async::Ready(Bytes::from("1line2")),
|
||||||
Ok(Async::Ready(data)) => assert_eq!(&data, "1line2"),
|
payload.readuntil(b"2").ok().unwrap());
|
||||||
_ => panic!("error"),
|
|
||||||
}
|
|
||||||
assert_eq!(payload.len(), 0);
|
assert_eq!(payload.len(), 0);
|
||||||
|
|
||||||
sender.set_error(PayloadError::Incomplete);
|
sender.set_error(PayloadError::Incomplete);
|
||||||
match payload.readuntil(b"b") {
|
payload.readuntil(b"b").err().unwrap();
|
||||||
Err(_) => (),
|
|
||||||
_ => panic!("error"),
|
|
||||||
}
|
|
||||||
|
|
||||||
let res: Result<(), ()> = Ok(());
|
let res: Result<(), ()> = Ok(());
|
||||||
result(res)
|
result(res)
|
||||||
|
@ -540,10 +498,8 @@ mod tests {
|
||||||
assert!(!payload.is_empty());
|
assert!(!payload.is_empty());
|
||||||
assert_eq!(payload.len(), 4);
|
assert_eq!(payload.len(), 4);
|
||||||
|
|
||||||
match payload.readany() {
|
assert_eq!(Async::Ready(Some(PayloadItem(Bytes::from("data")))),
|
||||||
Ok(Async::Ready(Some(data))) => assert_eq!(&data.0, "data"),
|
payload.readany().ok().unwrap());
|
||||||
_ => panic!("error"),
|
|
||||||
}
|
|
||||||
|
|
||||||
let res: Result<(), ()> = Ok(());
|
let res: Result<(), ()> = Ok(());
|
||||||
result(res)
|
result(res)
|
||||||
|
|
Loading…
Reference in a new issue