mirror of https://github.com/fafhrd91/actix-web
Fix tests to fail on previous implementation
This commit is contained in:
parent
a39910fec7
commit
cd70e67e79
|
@ -451,7 +451,6 @@ where
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use bytes::BufMut;
|
|
||||||
use futures::stream;
|
use futures::stream;
|
||||||
use futures_util::future::poll_fn;
|
use futures_util::future::poll_fn;
|
||||||
|
|
||||||
|
@ -613,12 +612,19 @@ mod tests {
|
||||||
|
|
||||||
#[actix_rt::test]
|
#[actix_rt::test]
|
||||||
async fn skips_empty_chunks() {
|
async fn skips_empty_chunks() {
|
||||||
let body = BodyStream::new(stream::iter(
|
let mut body = BodyStream::new(stream::iter(
|
||||||
["1", "", "2"]
|
["1", "", "2"]
|
||||||
.iter()
|
.iter()
|
||||||
.map(|&v| Ok(Bytes::from(v)) as Result<Bytes, ()>),
|
.map(|&v| Ok(Bytes::from(v)) as Result<Bytes, ()>),
|
||||||
));
|
));
|
||||||
assert_eq!(read_all(body).await.unwrap(), Bytes::from("12"));
|
assert_eq!(
|
||||||
|
poll_fn(|cx| body.poll_next(cx)).await.unwrap().ok(),
|
||||||
|
Some(Bytes::from("1")),
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
poll_fn(|cx| body.poll_next(cx)).await.unwrap().ok(),
|
||||||
|
Some(Bytes::from("2")),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -627,25 +633,18 @@ mod tests {
|
||||||
|
|
||||||
#[actix_rt::test]
|
#[actix_rt::test]
|
||||||
async fn skips_empty_chunks() {
|
async fn skips_empty_chunks() {
|
||||||
let body = SizedStream::new(
|
let mut body = SizedStream::new(
|
||||||
2,
|
2,
|
||||||
stream::iter(
|
stream::iter(["1", "", "2"].iter().map(|&v| Ok(Bytes::from(v)))),
|
||||||
["1", "", "2"]
|
);
|
||||||
.iter()
|
assert_eq!(
|
||||||
.map(|&v| Ok(Bytes::from(v))),
|
poll_fn(|cx| body.poll_next(cx)).await.unwrap().ok(),
|
||||||
),
|
Some(Bytes::from("1")),
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
poll_fn(|cx| body.poll_next(cx)).await.unwrap().ok(),
|
||||||
|
Some(Bytes::from("2")),
|
||||||
);
|
);
|
||||||
assert_eq!(read_all(body).await.unwrap(), Bytes::from("12"));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn read_all<B: MessageBody>(mut body: B) -> Result<Bytes, Error> {
|
|
||||||
use futures::StreamExt as _;
|
|
||||||
|
|
||||||
let mut bytes = BytesMut::new();
|
|
||||||
while let Some(b) = stream::poll_fn(|cx| body.poll_next(cx)).next().await {
|
|
||||||
bytes.put(b?);
|
|
||||||
}
|
|
||||||
Ok(bytes.freeze())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue