Skip to content

Commit

Permalink
Fix test environment leakage
Browse files Browse the repository at this point in the history
The generated config files for the test maildirs did not contain the
`hook_dir` option, and notmuch surprisingly defaulted to using
my *actual* hooks when running the test suite. This patch fixes this by
adding the `hook_dir` option to the generated config file, and also
removes a number of other environment variables that the `notmuch`
command could potentially pick up on certain systems.
  • Loading branch information
elizagamedev committed May 16, 2022
1 parent a27f3e8 commit a135f12
Showing 1 changed file with 32 additions and 23 deletions.
55 changes: 32 additions & 23 deletions tests/fixtures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,30 +41,35 @@ impl MailBox {

let cfg_fname = root_path.join("notmuch-config");
let mut cfg_file = File::create(cfg_fname).unwrap();
write!(cfg_file, r#"
[database]
path={tmppath}
[user]
name=Some Hacker
primary_email=dst@example.com
[new]
tags=unread;inbox;
ignore=
[search]
exclude_tags=deleted;spam;
[maildir]
synchronize_flags=true
[crypto]
gpg_path=gpg
"#, tmppath=root_path.to_string_lossy()).unwrap();
write!(
cfg_file,
r#"
[database]
path={tmppath}
hook_dir={tmppath}/hooks
[user]
name=Some Hacker
primary_email=dst@example.com
[new]
tags=unread;inbox;
ignore=
[search]
exclude_tags=deleted;spam;
[maildir]
synchronize_flags=true
[crypto]
gpg_path=gpg
"#,
tmppath = root_path.to_string_lossy()
)
.unwrap();

let maildir = Maildir::from(root_path.to_path_buf());
maildir.create_dirs().unwrap();

Self {
root_dir,
maildir
}
std::fs::create_dir(root_path.join("hooks")).unwrap();

Self { root_dir, maildir }
}

/// Return a new unique message ID
Expand Down Expand Up @@ -187,9 +192,13 @@ impl NotmuchCommand {
{
let cfg_fname = self.maildir_path.join("notmuch-config");

Command::new("notmuch").env("NOTMUCH_CONFIG", &cfg_fname)
.args(args)
.status()?;
Command::new("notmuch")
.env("NOTMUCH_CONFIG", &cfg_fname)
.env_remove("NOTMUCH_DATABASE")
.env_remove("NOTMUCH_PROFILE")
.env_remove("MAILDIR")
.args(args)
.status()?;
Ok(())
}

Expand Down

0 comments on commit a135f12

Please sign in to comment.