notmuch: simple unit test.

This commit is contained in:
Bill Thiede 2021-10-25 19:14:19 -07:00
parent 4f27171920
commit c1eeb38e24

View File

@ -206,7 +206,12 @@
//! }
//! ```
use std::{ffi::OsStr, process::Command};
use std::{
ffi::OsStr,
io::Result,
path::{Path, PathBuf},
process::Command,
};
use serde::Deserialize;
@ -378,14 +383,54 @@ pub struct ThreadSummary {
// TODO(wathiede): notmuch reply schema
pub fn run_notmuch<I, S>(args: I) -> std::io::Result<Vec<u8>>
where
I: IntoIterator<Item = S>,
S: AsRef<OsStr>,
{
let mut cmd = Command::new("notmuch");
let cmd = cmd.args(args);
dbg!(&cmd);
let out = cmd.output()?;
Ok(out.stdout)
struct Notmuch {
config_path: PathBuf,
}
impl Notmuch {
pub fn with_config<P: AsRef<Path>>(config_path: P) -> Notmuch {
Notmuch {
config_path: config_path.as_ref().into(),
}
}
pub fn new(&self) -> Result<Vec<u8>> {
self.run_notmuch(["new"])
}
pub fn no_args(&self) -> Result<Vec<u8>> {
self.run_notmuch(std::iter::empty::<&str>())
}
fn run_notmuch<I, S>(&self, args: I) -> Result<Vec<u8>>
where
I: IntoIterator<Item = S>,
S: AsRef<OsStr>,
{
let mut cmd = Command::new("notmuch");
let cmd = cmd.arg("--config").arg(&self.config_path);
let cmd = cmd.args(args);
dbg!(&cmd);
let out = cmd.output()?;
Ok(out.stdout)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn new() -> Result<()> {
let nm = Notmuch::with_config("testdata/notmuch.config");
nm.new()?;
let output = nm.no_args()?;
let s = String::from_utf8_lossy(&output);
assert!(
s.contains("Notmuch is configured and appears to have a database. Excellent!"),
"output:\n```\n{}```",
s
);
Ok(())
}
}