mirror of
https://github.com/pimalaya/himalaya.git
synced 2026-06-17 13:17:55 +08:00
remove obsolete unit tests
This commit is contained in:
@@ -236,495 +236,3 @@ pub fn path_parser(path: &str) -> Result<PathBuf, String> {
|
||||
.map(canonicalize::path)
|
||||
.map_err(|err| err.to_string())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use email::{
|
||||
account::config::passwd::PasswdConfig, maildir::config::MaildirConfig,
|
||||
sendmail::config::SendmailConfig,
|
||||
};
|
||||
use secret::Secret;
|
||||
|
||||
#[cfg(feature = "notmuch")]
|
||||
use email::backend::NotmuchConfig;
|
||||
#[cfg(feature = "imap")]
|
||||
use email::imap::config::{ImapAuthConfig, ImapConfig};
|
||||
#[cfg(feature = "smtp")]
|
||||
use email::smtp::config::{SmtpAuthConfig, SmtpConfig};
|
||||
|
||||
use std::io::Write;
|
||||
use tempfile::NamedTempFile;
|
||||
|
||||
use super::*;
|
||||
|
||||
async fn make_config(config: &str) -> Result<TomlConfig> {
|
||||
let mut file = NamedTempFile::new().unwrap();
|
||||
write!(file, "{}", config).unwrap();
|
||||
TomlConfig::from_some_path_or_default(file.into_temp_path().to_str()).await
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn empty_config() {
|
||||
let config = make_config("").await;
|
||||
|
||||
assert_eq!(
|
||||
config.unwrap_err().root_cause().to_string(),
|
||||
"config file must contain at least one account"
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn account_missing_email_field() {
|
||||
let config = make_config("[account]").await;
|
||||
|
||||
assert!(config
|
||||
.unwrap_err()
|
||||
.root_cause()
|
||||
.to_string()
|
||||
.contains("missing field `email`"));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn account_missing_backend_field() {
|
||||
let config = make_config(
|
||||
"[account]
|
||||
email = \"test@localhost\"",
|
||||
)
|
||||
.await;
|
||||
|
||||
assert!(config
|
||||
.unwrap_err()
|
||||
.root_cause()
|
||||
.to_string()
|
||||
.contains("missing field `backend`"));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn account_invalid_backend_field() {
|
||||
let config = make_config(
|
||||
"[account]
|
||||
email = \"test@localhost\"
|
||||
backend = \"bad\"",
|
||||
)
|
||||
.await;
|
||||
|
||||
assert!(config
|
||||
.unwrap_err()
|
||||
.root_cause()
|
||||
.to_string()
|
||||
.contains("unknown variant `bad`"));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn imap_account_missing_host_field() {
|
||||
let config = make_config(
|
||||
"[account]
|
||||
email = \"test@localhost\"
|
||||
sender = \"none\"
|
||||
backend = \"imap\"",
|
||||
)
|
||||
.await;
|
||||
|
||||
assert!(config
|
||||
.unwrap_err()
|
||||
.root_cause()
|
||||
.to_string()
|
||||
.contains("missing field `imap-host`"));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn account_backend_imap_missing_port_field() {
|
||||
let config = make_config(
|
||||
"[account]
|
||||
email = \"test@localhost\"
|
||||
sender = \"none\"
|
||||
backend = \"imap\"
|
||||
imap-host = \"localhost\"",
|
||||
)
|
||||
.await;
|
||||
|
||||
assert!(config
|
||||
.unwrap_err()
|
||||
.root_cause()
|
||||
.to_string()
|
||||
.contains("missing field `imap-port`"));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn account_backend_imap_missing_login_field() {
|
||||
let config = make_config(
|
||||
"[account]
|
||||
email = \"test@localhost\"
|
||||
sender = \"none\"
|
||||
backend = \"imap\"
|
||||
imap-host = \"localhost\"
|
||||
imap-port = 993",
|
||||
)
|
||||
.await;
|
||||
|
||||
assert!(config
|
||||
.unwrap_err()
|
||||
.root_cause()
|
||||
.to_string()
|
||||
.contains("missing field `imap-login`"));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn account_backend_imap_missing_passwd_cmd_field() {
|
||||
let config = make_config(
|
||||
"[account]
|
||||
email = \"test@localhost\"
|
||||
sender = \"none\"
|
||||
backend = \"imap\"
|
||||
imap-host = \"localhost\"
|
||||
imap-port = 993
|
||||
imap-login = \"login\"",
|
||||
)
|
||||
.await;
|
||||
|
||||
assert!(config
|
||||
.unwrap_err()
|
||||
.root_cause()
|
||||
.to_string()
|
||||
.contains("missing field `imap-auth`"));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn account_backend_maildir_missing_root_dir_field() {
|
||||
let config = make_config(
|
||||
"[account]
|
||||
email = \"test@localhost\"
|
||||
sender = \"none\"
|
||||
backend = \"maildir\"",
|
||||
)
|
||||
.await;
|
||||
|
||||
assert!(config
|
||||
.unwrap_err()
|
||||
.root_cause()
|
||||
.to_string()
|
||||
.contains("missing field `maildir-root-dir`"));
|
||||
}
|
||||
|
||||
#[cfg(feature = "notmuch")]
|
||||
#[tokio::test]
|
||||
async fn account_backend_notmuch_missing_db_path_field() {
|
||||
let config = make_config(
|
||||
"[account]
|
||||
email = \"test@localhost\"
|
||||
sender = \"none\"
|
||||
backend = \"notmuch\"",
|
||||
)
|
||||
.await;
|
||||
|
||||
assert!(config
|
||||
.unwrap_err()
|
||||
.root_cause()
|
||||
.to_string()
|
||||
.contains("missing field `notmuch-db-path`"));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn account_missing_sender_field() {
|
||||
let config = make_config(
|
||||
"[account]
|
||||
email = \"test@localhost\"
|
||||
backend = \"none\"",
|
||||
)
|
||||
.await;
|
||||
|
||||
assert!(config
|
||||
.unwrap_err()
|
||||
.root_cause()
|
||||
.to_string()
|
||||
.contains("missing field `sender`"));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn account_invalid_sender_field() {
|
||||
let config = make_config(
|
||||
"[account]
|
||||
email = \"test@localhost\"
|
||||
backend = \"none\"
|
||||
sender = \"bad\"",
|
||||
)
|
||||
.await;
|
||||
|
||||
assert!(config
|
||||
.unwrap_err()
|
||||
.root_cause()
|
||||
.to_string()
|
||||
.contains("unknown variant `bad`, expected one of `none`, `smtp`, `sendmail`"),);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn account_smtp_sender_missing_host_field() {
|
||||
let config = make_config(
|
||||
"[account]
|
||||
email = \"test@localhost\"
|
||||
backend = \"none\"
|
||||
sender = \"smtp\"",
|
||||
)
|
||||
.await;
|
||||
|
||||
assert!(config
|
||||
.unwrap_err()
|
||||
.root_cause()
|
||||
.to_string()
|
||||
.contains("missing field `smtp-host`"));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn account_smtp_sender_missing_port_field() {
|
||||
let config = make_config(
|
||||
"[account]
|
||||
email = \"test@localhost\"
|
||||
backend = \"none\"
|
||||
sender = \"smtp\"
|
||||
smtp-host = \"localhost\"",
|
||||
)
|
||||
.await;
|
||||
|
||||
assert!(config
|
||||
.unwrap_err()
|
||||
.root_cause()
|
||||
.to_string()
|
||||
.contains("missing field `smtp-port`"));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn account_smtp_sender_missing_login_field() {
|
||||
let config = make_config(
|
||||
"[account]
|
||||
email = \"test@localhost\"
|
||||
backend = \"none\"
|
||||
sender = \"smtp\"
|
||||
smtp-host = \"localhost\"
|
||||
smtp-port = 25",
|
||||
)
|
||||
.await;
|
||||
|
||||
assert!(config
|
||||
.unwrap_err()
|
||||
.root_cause()
|
||||
.to_string()
|
||||
.contains("missing field `smtp-login`"));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn account_smtp_sender_missing_auth_field() {
|
||||
let config = make_config(
|
||||
"[account]
|
||||
email = \"test@localhost\"
|
||||
backend = \"none\"
|
||||
sender = \"smtp\"
|
||||
smtp-host = \"localhost\"
|
||||
smtp-port = 25
|
||||
smtp-login = \"login\"",
|
||||
)
|
||||
.await;
|
||||
|
||||
assert!(config
|
||||
.unwrap_err()
|
||||
.root_cause()
|
||||
.to_string()
|
||||
.contains("missing field `smtp-auth`"));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn account_sendmail_sender_missing_cmd_field() {
|
||||
let config = make_config(
|
||||
"[account]
|
||||
email = \"test@localhost\"
|
||||
backend = \"none\"
|
||||
sender = \"sendmail\"",
|
||||
)
|
||||
.await;
|
||||
|
||||
assert_eq!(
|
||||
config.unwrap(),
|
||||
TomlConfig {
|
||||
accounts: HashMap::from_iter([(
|
||||
"account".into(),
|
||||
TomlAccountConfig {
|
||||
email: "test@localhost".into(),
|
||||
sender: SenderConfig::Sendmail(SendmailConfig {
|
||||
cmd: "/usr/sbin/sendmail".into()
|
||||
}),
|
||||
..TomlAccountConfig::default()
|
||||
}
|
||||
)]),
|
||||
..TomlConfig::default()
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
#[cfg(feature = "smtp")]
|
||||
#[tokio::test]
|
||||
async fn account_smtp_sender_minimum_config() {
|
||||
use email::sender::SenderConfig;
|
||||
|
||||
let config = make_config(
|
||||
"[account]
|
||||
email = \"test@localhost\"
|
||||
backend = \"none\"
|
||||
sender = \"smtp\"
|
||||
smtp-host = \"localhost\"
|
||||
smtp-port = 25
|
||||
smtp-login = \"login\"
|
||||
smtp-auth = \"passwd\"
|
||||
smtp-passwd = { cmd = \"echo password\" }",
|
||||
)
|
||||
.await;
|
||||
|
||||
assert_eq!(
|
||||
config.unwrap(),
|
||||
TomlConfig {
|
||||
accounts: HashMap::from_iter([(
|
||||
"account".into(),
|
||||
TomlAccountConfig {
|
||||
email: "test@localhost".into(),
|
||||
sender: SenderConfig::Smtp(SmtpConfig {
|
||||
host: "localhost".into(),
|
||||
port: 25,
|
||||
login: "login".into(),
|
||||
auth: SmtpAuthConfig::Passwd(PasswdConfig {
|
||||
passwd: Secret::new_cmd(String::from("echo password"))
|
||||
}),
|
||||
..SmtpConfig::default()
|
||||
}),
|
||||
..TomlAccountConfig::default()
|
||||
}
|
||||
)]),
|
||||
..TomlConfig::default()
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn account_sendmail_sender_minimum_config() {
|
||||
let config = make_config(
|
||||
"[account]
|
||||
email = \"test@localhost\"
|
||||
backend = \"none\"
|
||||
sender = \"sendmail\"
|
||||
sendmail-cmd = \"echo send\"",
|
||||
)
|
||||
.await;
|
||||
|
||||
assert_eq!(
|
||||
config.unwrap(),
|
||||
TomlConfig {
|
||||
accounts: HashMap::from_iter([(
|
||||
"account".into(),
|
||||
TomlAccountConfig {
|
||||
email: "test@localhost".into(),
|
||||
sender: SenderConfig::Sendmail(SendmailConfig {
|
||||
cmd: Cmd::from("echo send")
|
||||
}),
|
||||
..TomlAccountConfig::default()
|
||||
}
|
||||
)]),
|
||||
..TomlConfig::default()
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn account_backend_imap_minimum_config() {
|
||||
let config = make_config(
|
||||
"[account]
|
||||
email = \"test@localhost\"
|
||||
sender = \"none\"
|
||||
backend = \"imap\"
|
||||
imap-host = \"localhost\"
|
||||
imap-port = 993
|
||||
imap-login = \"login\"
|
||||
imap-auth = \"passwd\"
|
||||
imap-passwd = { cmd = \"echo password\" }",
|
||||
)
|
||||
.await;
|
||||
|
||||
assert_eq!(
|
||||
config.unwrap(),
|
||||
TomlConfig {
|
||||
accounts: HashMap::from_iter([(
|
||||
"account".into(),
|
||||
TomlAccountConfig {
|
||||
email: "test@localhost".into(),
|
||||
backend: BackendConfig::Imap(ImapConfig {
|
||||
host: "localhost".into(),
|
||||
port: 993,
|
||||
login: "login".into(),
|
||||
auth: ImapAuthConfig::Passwd(PasswdConfig {
|
||||
passwd: Secret::new_cmd(String::from("echo password"))
|
||||
}),
|
||||
..ImapConfig::default()
|
||||
}),
|
||||
..TomlAccountConfig::default()
|
||||
}
|
||||
)]),
|
||||
..TomlConfig::default()
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn account_backend_maildir_minimum_config() {
|
||||
let config = make_config(
|
||||
"[account]
|
||||
email = \"test@localhost\"
|
||||
sender = \"none\"
|
||||
backend = \"maildir\"
|
||||
maildir-root-dir = \"/tmp/maildir\"",
|
||||
)
|
||||
.await;
|
||||
|
||||
assert_eq!(
|
||||
config.unwrap(),
|
||||
TomlConfig {
|
||||
accounts: HashMap::from_iter([(
|
||||
"account".into(),
|
||||
TomlAccountConfig {
|
||||
email: "test@localhost".into(),
|
||||
backend: BackendConfig::Maildir(MaildirConfig {
|
||||
root_dir: "/tmp/maildir".into(),
|
||||
}),
|
||||
..TomlAccountConfig::default()
|
||||
}
|
||||
)]),
|
||||
..TomlConfig::default()
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
#[cfg(feature = "notmuch")]
|
||||
#[tokio::test]
|
||||
async fn account_backend_notmuch_minimum_config() {
|
||||
let config = make_config(
|
||||
"[account]
|
||||
email = \"test@localhost\"
|
||||
sender = \"none\"
|
||||
backend = \"notmuch\"
|
||||
notmuch-db-path = \"/tmp/notmuch.db\"",
|
||||
)
|
||||
.await;
|
||||
|
||||
assert_eq!(
|
||||
config.unwrap(),
|
||||
TomlConfig {
|
||||
accounts: HashMap::from_iter([(
|
||||
"account".into(),
|
||||
TomlAccountConfig {
|
||||
email: "test@localhost".into(),
|
||||
backend: BackendConfig::Notmuch(NotmuchConfig {
|
||||
db_path: "/tmp/notmuch.db".into(),
|
||||
}),
|
||||
..TomlAccountConfig::default()
|
||||
}
|
||||
)]),
|
||||
..TomlConfig::default()
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user