-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
24a1135
commit 2e0c9cf
Showing
2 changed files
with
138 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,16 @@ | ||
extern crate dirs; | ||
extern crate tempfile; | ||
extern crate notmuch; | ||
extern crate gethostname; | ||
extern crate maildir; | ||
extern crate lettre; | ||
extern crate lettre_email; | ||
extern crate maildir; | ||
extern crate notmuch; | ||
extern crate tempfile; | ||
|
||
mod fixtures; | ||
#[cfg(feature = "v0_32")] | ||
mod test_config; | ||
mod test_database; | ||
mod test_query; | ||
mod test_thread; | ||
mod test_message; | ||
mod test_query; | ||
mod test_tags; | ||
|
||
mod test_thread; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
use notmuch::ConfigKey; | ||
|
||
use crate::fixtures::{MailBox, NotmuchCommand}; | ||
|
||
struct ConfigFixture { | ||
// Return a read-write Database. | ||
// The database will have 3 messages, 2 threads. | ||
pub mailbox: MailBox, | ||
pub database: notmuch::Database, | ||
} | ||
|
||
impl ConfigFixture { | ||
pub fn new() -> Self { | ||
let mailbox = MailBox::new(); | ||
|
||
let cmd = NotmuchCommand::new(&mailbox.path()); | ||
cmd.run(vec!["new"]).unwrap(); | ||
|
||
let database = notmuch::Database::open_with_config( | ||
Some(&mailbox.path()), | ||
notmuch::DatabaseMode::ReadWrite, | ||
Some(mailbox.path().join("notmuch-config")), | ||
None, | ||
) | ||
.unwrap(); | ||
|
||
Self { mailbox, database } | ||
} | ||
} | ||
|
||
mod config { | ||
use super::*; | ||
|
||
#[test] | ||
fn test_config() { | ||
let db = ConfigFixture::new(); | ||
|
||
assert_eq!( | ||
db.database.config(ConfigKey::UserName).unwrap(), | ||
"Some Hacker" | ||
); | ||
|
||
assert_eq!( | ||
db.database.config(ConfigKey::MailRoot).unwrap(), | ||
db.mailbox.path().to_str().unwrap() | ||
); | ||
} | ||
|
||
#[test] | ||
fn test_config_set() { | ||
let db = ConfigFixture::new(); | ||
|
||
const USER_NAME: &str = "Hideo Kojima"; | ||
|
||
db.database | ||
.config_set(ConfigKey::UserName, USER_NAME) | ||
.unwrap(); | ||
|
||
assert_eq!(db.database.config(ConfigKey::UserName).unwrap(), USER_NAME); | ||
} | ||
|
||
#[test] | ||
fn test_config_values() { | ||
let db = ConfigFixture::new(); | ||
|
||
let tags: Vec<_> = db | ||
.database | ||
.config_values(ConfigKey::NewTags) | ||
.unwrap() | ||
.collect(); | ||
|
||
assert_eq!(tags.len(), 2); | ||
assert!(tags.iter().any(|x| x == "unread")); | ||
assert!(tags.iter().any(|x| x == "inbox")); | ||
} | ||
|
||
#[test] | ||
fn test_config_values_string() { | ||
let db = ConfigFixture::new(); | ||
|
||
let tags: Vec<_> = db | ||
.database | ||
.config_values_string("search.exclude_tags") | ||
.unwrap() | ||
.collect(); | ||
|
||
assert_eq!(tags.len(), 2); | ||
assert!(tags.iter().any(|x| x == "deleted")); | ||
assert!(tags.iter().any(|x| x == "spam")); | ||
} | ||
|
||
#[test] | ||
fn test_config_pairs() { | ||
let db = ConfigFixture::new(); | ||
|
||
let pairs: Vec<(_, _)> = db.database.config_pairs("user").unwrap().collect(); | ||
|
||
println!("{pairs:?}"); | ||
|
||
assert_eq!(pairs.len(), 3); | ||
assert!(pairs | ||
.iter() | ||
.any(|(k, v)| k == "user.name" && v.as_deref() == Some("Some Hacker"))); | ||
assert!(pairs | ||
.iter() | ||
.any(|(k, v)| k == "user.primary_email" && v.as_deref() == Some("dst@example.com"))); | ||
assert!(pairs | ||
.iter() | ||
.any(|(k, v)| k == "user.other_email" && *v == None)); | ||
} | ||
|
||
#[test] | ||
fn test_config_bool() { | ||
let db = ConfigFixture::new(); | ||
|
||
assert_eq!( | ||
db.database.config_bool(ConfigKey::MaildirFlags).unwrap(), | ||
true | ||
); | ||
} | ||
|
||
#[test] | ||
fn test_config_path() { | ||
let db = ConfigFixture::new(); | ||
|
||
assert_eq!( | ||
db.database.config_path().unwrap(), | ||
db.mailbox.path().join("notmuch-config"), | ||
); | ||
} | ||
} |