From 15a85275efbb9b2d8811e59454a1a9cbca262e37 Mon Sep 17 00:00:00 2001 From: Joseph LaFreniere Date: Sat, 24 Dec 2022 15:44:13 -0600 Subject: [PATCH] Pin `postproc_prefix`'s `StreamReader` and add unit test --- src/adapters/postproc.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/adapters/postproc.rs b/src/adapters/postproc.rs index 68bb3d5..d6db7d9 100644 --- a/src/adapters/postproc.rs +++ b/src/adapters/postproc.rs @@ -140,7 +140,7 @@ pub fn postproc_prefix(line_prefix: &str, inp: impl AsyncRead + Send) -> impl As } } }; - StreamReader::new(oup_stream) + Box::pin(StreamReader::new(oup_stream)) } /// Adds the prefix "Page N:" to each line, @@ -196,6 +196,18 @@ mod tests { ); } + #[tokio::test] + async fn test_postproc_prefix() { + let mut output: Vec = Vec::new(); + let mock: Mock = Builder::new().read(b"Hello\nWorld").build(); + let res = postproc_prefix("prefix: ", mock) + .read_to_end(&mut output) + .await; + println!("{}", String::from_utf8_lossy(&output)); + assert!(matches!(res, Ok(_))); + assert_eq!(output, b"prefix: Hello\nprefix: World"); + } + async fn test_from_strs( pagebreaks: bool, line_prefix: &str,