Skip to content

Commit

Permalink
fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
soywod committed Feb 23, 2024
1 parent faeda95 commit 5cb2471
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 78 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed

- Removed account configurations flatten level in order to improve diagnostic errors, due to a [bug](https://github.com/toml-rs/toml/issues/589#issuecomment-1872345017) in clap. **This means that accounts need to be prefixed by `accounts`: `[my-account]` becomes `[accounts.my-account]`**. It also opens doors for interface-specific configurations.
- Rolled back cargo feature additions from the previous release. It was a mistake: the amount of features was too big, the code (both CLI and lib) was too hard to maintain. Cargo features kept: `imap`, `maildir`, `notmuch`, `account-sync`, `account-discovery`, `pgp-gpg`, `pgp-commands` and `pgp-native`.
- Rolled back cargo feature additions from the previous release. It was a mistake: the amount of features was too big, the code (both CLI and lib) was too hard to maintain. Cargo features kept: `imap`, `maildir`, `notmuch`, `smtp`, `sendmail`, `account-sync`, `account-discovery`, `pgp-gpg`, `pgp-commands` and `pgp-native`.
- Improved pre and post edit choices interaction [#58].
- Improved account synchronization performances, making it 50% faster than `mbsync` and 370% faster than `OfflineIMAP`.
- Changed `envelope.watch.{event}.{hook}`: hooks can now be cumulated. For example it is possible to send a system notification and execute a shell command when receiving a new envelope:
Expand Down
166 changes: 89 additions & 77 deletions src/config/wizard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,64 +106,66 @@ fn pretty_serialize(config: &TomlConfig) -> Result<String> {
let mut doc: Document = toml::to_string(&config)?.parse()?;

doc.iter_mut().for_each(|(_, item)| {
set_table_dotted(item, "folder");
if let Some(item) = get_table_mut(item, "folder") {
set_tables_dotted(item, ["alias", "add", "list", "expunge", "purge", "delete"]);
if let Some(item) = item.as_table_mut() {
item.iter_mut().for_each(|(_, item)| {
set_table_dotted(item, "folder");
if let Some(item) = get_table_mut(item, "folder") {
let keys = ["alias", "add", "list", "expunge", "purge", "delete", "sync"];
set_tables_dotted(item, keys);

if let Some(item) = get_table_mut(item, "sync") {
set_tables_dotted(item, ["filter", "permissions"]);
}
}

set_table_dotted(item, "envelope");
if let Some(item) = get_table_mut(item, "envelope") {
set_tables_dotted(item, ["list", "get"]);
}

set_table_dotted(item, "flag");
if let Some(item) = get_table_mut(item, "flag") {
set_tables_dotted(item, ["add", "set", "remove"]);
}

set_table_dotted(item, "message");
if let Some(item) = get_table_mut(item, "message") {
let keys = ["add", "send", "peek", "get", "copy", "move", "delete"];
set_tables_dotted(item, keys);
}

#[cfg(feature = "maildir")]
set_table_dotted(item, "maildir");

#[cfg(feature = "imap")]
{
set_table_dotted(item, "imap");
if let Some(item) = get_table_mut(item, "imap") {
set_tables_dotted(item, ["passwd", "oauth2"]);
}
}

#[cfg(feature = "notmuch")]
set_table_dotted(item, "notmuch");

#[cfg(feature = "smtp")]
{
set_table_dotted(item, "smtp");
if let Some(item) = get_table_mut(item, "smtp") {
set_tables_dotted(item, ["passwd", "oauth2"]);
}
}

#[cfg(feature = "sendmail")]
set_table_dotted(item, "sendmail");

#[cfg(feature = "account-sync")]
set_table_dotted(item, "sync");

#[cfg(feature = "pgp")]
set_table_dotted(item, "pgp");
})
}

set_table_dotted(item, "envelope");
if let Some(item) = get_table_mut(item, "envelope") {
set_tables_dotted(item, ["list", "get"]);
}

set_table_dotted(item, "flag");
if let Some(item) = get_table_mut(item, "flag") {
set_tables_dotted(item, ["add", "set", "remove"]);
}

set_table_dotted(item, "message");
if let Some(item) = get_table_mut(item, "message") {
set_tables_dotted(
item,
["add", "send", "peek", "get", "copy", "move", "delete"],
);
}

#[cfg(feature = "maildir")]
set_table_dotted(item, "maildir");

#[cfg(feature = "imap")]
{
set_table_dotted(item, "imap");
if let Some(item) = get_table_mut(item, "imap") {
set_tables_dotted(item, ["passwd", "oauth2"]);
}
}

#[cfg(feature = "notmuch")]
set_table_dotted(item, "notmuch");

#[cfg(feature = "smtp")]
{
set_table_dotted(item, "smtp");
if let Some(item) = get_table_mut(item, "smtp") {
set_tables_dotted(item, ["passwd", "oauth2"]);
}
}

#[cfg(feature = "sendmail")]
set_table_dotted(item, "sendmail");

#[cfg(feature = "account-sync")]
{
set_table_dotted(item, "sync");
if let Some(item) = get_table_mut(item, "sync") {
set_tables_dotted(item, ["strategy"]);
}
}

#[cfg(feature = "pgp")]
set_table_dotted(item, "pgp");
});

Ok(doc.to_string())
Expand Down Expand Up @@ -213,7 +215,7 @@ mod test {
email: "test@localhost".into(),
..Default::default()
},
r#"[test]
r#"[accounts.test]
email = "test@localhost"
"#,
)
Expand All @@ -222,51 +224,61 @@ email = "test@localhost"
#[cfg(feature = "account-sync")]
#[test]
fn pretty_serialize_sync_all() {
use email::{account::sync::config::SyncConfig, folder::sync::FolderSyncStrategy};
use email::account::sync::config::SyncConfig;

assert_eq(
TomlAccountConfig {
email: "test@localhost".into(),
sync: Some(SyncConfig {
enable: Some(false),
dir: Some("/tmp/test".into()),
strategy: Some(FolderSyncStrategy::All),
..Default::default()
}),
..Default::default()
},
r#"[test]
r#"[accounts.test]
email = "test@localhost"
sync.enable = false
sync.dir = "/tmp/test"
sync.strategy = "all"
"#,
);
}

#[cfg(feature = "account-sync")]
#[test]
fn pretty_serialize_sync_include() {
use std::collections::HashSet;
use email::{
account::sync::config::SyncConfig,
folder::sync::config::{FolderSyncConfig, FolderSyncStrategy},
};
use std::collections::BTreeSet;

use email::{account::sync::config::SyncConfig, folder::sync::FolderSyncStrategy};
use crate::folder::config::FolderConfig;

assert_eq(
TomlAccountConfig {
email: "test@localhost".into(),
sync: Some(SyncConfig {
enable: Some(true),
dir: Some("/tmp/test".into()),
strategy: Some(FolderSyncStrategy::Include(HashSet::from_iter([
"test".into()
]))),
..Default::default()
}),
folder: Some(FolderConfig {
sync: Some(FolderSyncConfig {
filter: FolderSyncStrategy::Include(BTreeSet::from_iter(["test".into()])),
..Default::default()
}),
..Default::default()
}),
..Default::default()
},
r#"[test]
r#"[accounts.test]
email = "test@localhost"
sync.enable = true
sync.dir = "/tmp/test"
sync.strategy.include = ["test"]
folder.sync.filter.include = ["test"]
folder.sync.permissions.create = true
folder.sync.permissions.delete = true
"#,
);
}
Expand All @@ -292,7 +304,7 @@ sync.strategy.include = ["test"]
}),
..Default::default()
},
r#"[test]
r#"[accounts.test]
email = "test@localhost"
imap.host = "localhost"
imap.port = 143
Expand Down Expand Up @@ -326,7 +338,7 @@ imap.passwd.cmd = "pass show test"
}),
..Default::default()
},
r#"[test]
r#"[accounts.test]
email = "test@localhost"
imap.host = "localhost"
imap.port = 143
Expand Down Expand Up @@ -361,7 +373,7 @@ imap.passwd.cmd = ["pass show test", "tr -d '[:blank:]'"]
}),
..Default::default()
},
r#"[test]
r#"[accounts.test]
email = "test@localhost"
imap.host = "localhost"
imap.port = 143
Expand Down Expand Up @@ -389,7 +401,7 @@ imap.oauth2.scopes = []
}),
..Default::default()
},
r#"[test]
r#"[accounts.test]
email = "test@localhost"
maildir.root-dir = "/tmp/test"
"#,
Expand Down Expand Up @@ -417,7 +429,7 @@ maildir.root-dir = "/tmp/test"
}),
..Default::default()
},
r#"[test]
r#"[accounts.test]
email = "test@localhost"
smtp.host = "localhost"
smtp.port = 143
Expand Down Expand Up @@ -451,7 +463,7 @@ smtp.passwd.cmd = "pass show test"
}),
..Default::default()
},
r#"[test]
r#"[accounts.test]
email = "test@localhost"
smtp.host = "localhost"
smtp.port = 143
Expand Down Expand Up @@ -486,7 +498,7 @@ smtp.passwd.cmd = ["pass show test", "tr -d '[:blank:]'"]
}),
..Default::default()
},
r#"[test]
r#"[accounts.test]
email = "test@localhost"
smtp.host = "localhost"
smtp.port = 143
Expand All @@ -512,7 +524,7 @@ smtp.oauth2.scopes = []
pgp: Some(PgpConfig::Cmds(Default::default())),
..Default::default()
},
r#"[test]
r#"[accounts.test]
email = "test@localhost"
pgp.backend = "cmds"
"#,
Expand Down

0 comments on commit 5cb2471

Please sign in to comment.