rw-stream-sink: Add regression test. (#683)

Closes #679.
This commit is contained in:
Toralf Wittner
2018-11-26 13:36:47 +01:00
committed by GitHub
parent 9fe7d56410
commit f833c5d9ff

View File

@ -173,10 +173,9 @@ where
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use RwStreamSink;
use bytes::Bytes; use bytes::Bytes;
use futures::sync::mpsc::channel; use crate::RwStreamSink;
use futures::{Future, Poll, Sink, StartSend, Stream}; use futures::{prelude::*, stream, sync::mpsc::channel};
use std::io::Read; use std::io::Read;
// This struct merges a stream and a sink and is quite useful for tests. // This struct merges a stream and a sink and is quite useful for tests.
@ -232,4 +231,13 @@ mod tests {
wrapper.read_to_end(&mut data2).unwrap(); wrapper.read_to_end(&mut data2).unwrap();
assert_eq!(data2, b" world"); assert_eq!(data2, b" world");
} }
#[test]
fn skip_empty_stream_items() {
let data: Vec<&[u8]> = vec![b"", b"foo", b"", b"bar", b"", b"baz", b""];
let mut rws = RwStreamSink::new(stream::iter_ok::<_, std::io::Error>(data));
let mut buf = [0; 9];
assert_eq!(9, rws.read(&mut buf).unwrap());
assert_eq!(b"foobarbaz", &buf[..])
}
} }