Skip to content

Commit d93c6fd

Browse files
committed
Add a test for Body::chain on Body instances after calling read
1 parent 3760693 commit d93c6fd

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/body.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -839,4 +839,30 @@ mod test {
839839

840840
Ok(())
841841
}
842+
843+
#[async_std::test]
844+
async fn chain_skip_start() -> crate::Result<()> {
845+
for buf_len in 1..26 {
846+
let mut body1 = Body::from_reader(Cursor::new("1234 hello xyz"), Some(11));
847+
let mut buf = vec![0; 5];
848+
body1.read(&mut buf).await?;
849+
assert_eq!(buf, b"1234 ");
850+
851+
let mut body2 = Body::from_reader(Cursor::new("321 world abc"), Some(9));
852+
let mut buf = vec![0; 4];
853+
body2.read(&mut buf).await?;
854+
assert_eq!(buf, b"321 ");
855+
856+
let mut body = body1.chain(body2);
857+
assert_eq!(body.len(), Some(11));
858+
assert_eq!(body.mime(), &mime::BYTE_STREAM);
859+
assert_eq!(
860+
read_with_buffers_of_size(&mut body, buf_len).await?,
861+
"hello world"
862+
);
863+
assert_eq!(body.bytes_read, 11);
864+
}
865+
866+
Ok(())
867+
}
842868
}

0 commit comments

Comments
 (0)