Skip to content

Commit

Permalink
Merge pull request #43 from elizagamedev/isolated-tests
Browse files Browse the repository at this point in the history
Fix test environment leakage
  • Loading branch information
vhdirk authored May 16, 2022
2 parents a27f3e8 + a135f12 commit 8225f23
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 8225f23

Please sign in to comment.