aboutsummaryrefslogtreecommitdiff
path: root/tests/common.rs
diff options
context:
space:
mode:
authorQuentin Dufour <quentin@deuxfleurs.fr>2024-01-03 10:28:10 +0100
committerQuentin Dufour <quentin@deuxfleurs.fr>2024-01-03 10:28:10 +0100
commita059585cb423d527763ef0131773d6620ebcafd5 (patch)
tree199e2b9108db7104908a5ac6f3138100e4d33095 /tests/common.rs
parent9ce8e18fb81c4ef0bf146c5d28981d8f2a6fddd9 (diff)
downloadaerogramme-a059585cb423d527763ef0131773d6620ebcafd5.tar.gz
aerogramme-a059585cb423d527763ef0131773d6620ebcafd5.zip
add test for the unselect extension
Diffstat (limited to 'tests/common.rs')
-rw-r--r--tests/common.rs29
1 files changed, 27 insertions, 2 deletions
diff --git a/tests/common.rs b/tests/common.rs
index 0d99ce8..f89f26c 100644
--- a/tests/common.rs
+++ b/tests/common.rs
@@ -1,11 +1,14 @@
use anyhow::{bail, Context, Result};
+use std::io::Read;
use std::net::{Shutdown, TcpStream};
use std::process::Command;
use std::{thread, time};
static SMALL_DELAY: time::Duration = time::Duration::from_millis(200);
-pub fn aerogramme_provider_daemon_dev(mut fx: impl FnMut(&mut TcpStream, &mut TcpStream) -> Result<()>) -> Result<()> {
+pub fn aerogramme_provider_daemon_dev(
+ mut fx: impl FnMut(&mut TcpStream, &mut TcpStream) -> Result<()>,
+) -> Result<()> {
let mut daemon = Command::new(env!("CARGO_BIN_EXE_aerogramme"))
.arg("--dev")
.arg("provider")
@@ -25,7 +28,8 @@ pub fn aerogramme_provider_daemon_dev(mut fx: impl FnMut(&mut TcpStream, &mut Tc
thread::sleep(SMALL_DELAY);
};
- let mut lmtp_socket = TcpStream::connect("[::1]:1025").context("lmtp socket must be connected")?;
+ let mut lmtp_socket =
+ TcpStream::connect("[::1]:1025").context("lmtp socket must be connected")?;
println!("-- ready to test imap features --");
let result = fx(&mut imap_socket, &mut lmtp_socket);
@@ -41,3 +45,24 @@ pub fn aerogramme_provider_daemon_dev(mut fx: impl FnMut(&mut TcpStream, &mut Tc
result.context("all tests passed")
}
+
+pub fn read_lines<'a, F: Read>(
+ reader: &mut F,
+ buffer: &'a mut [u8],
+ stop_marker: Option<&[u8]>,
+) -> Result<&'a [u8]> {
+ let mut nbytes = 0;
+ loop {
+ nbytes += reader.read(&mut buffer[nbytes..])?;
+ //println!("partial read: {}", std::str::from_utf8(&buffer[..nbytes])?);
+ let pre_condition = match stop_marker {
+ None => true,
+ Some(mark) => buffer[..nbytes].windows(mark.len()).any(|w| w == mark),
+ };
+ if pre_condition && &buffer[nbytes - 2..nbytes] == &b"\r\n"[..] {
+ break;
+ }
+ }
+ println!("read: {}", std::str::from_utf8(&buffer[..nbytes])?);
+ Ok(&buffer[..nbytes])
+}