From 364654e1cea4652ede61a6454635dd26b62716f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20DOUIN?= Date: Sun, 2 May 2021 23:49:20 +0200 Subject: [PATCH] init integration tests --- src/config/mod.rs | 2 +- src/imap/mod.rs | 2 +- src/lib.rs | 11 ++++++++ src/msg/mod.rs | 2 +- tests/imap_test.rs | 69 ++++++++++++++++++++++++++++++++++++++++++++++ wiki | 2 +- 6 files changed, 84 insertions(+), 4 deletions(-) create mode 100644 src/lib.rs create mode 100644 tests/imap_test.rs diff --git a/src/config/mod.rs b/src/config/mod.rs index f7a32e1..5cd17ed 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -1,2 +1,2 @@ pub(crate) mod cli; -pub(crate) mod model; +pub mod model; diff --git a/src/imap/mod.rs b/src/imap/mod.rs index f7a32e1..5cd17ed 100644 --- a/src/imap/mod.rs +++ b/src/imap/mod.rs @@ -1,2 +1,2 @@ pub(crate) mod cli; -pub(crate) mod model; +pub mod model; diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..e52835d --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,11 @@ +pub mod app; +pub mod comp; +pub mod config; +pub mod flag; +pub mod imap; +pub mod input; +pub mod mbox; +pub mod msg; +pub mod output; +pub mod smtp; +pub mod table; diff --git a/src/msg/mod.rs b/src/msg/mod.rs index f7a32e1..5cd17ed 100644 --- a/src/msg/mod.rs +++ b/src/msg/mod.rs @@ -1,2 +1,2 @@ pub(crate) mod cli; -pub(crate) mod model; +pub mod model; diff --git a/tests/imap_test.rs b/tests/imap_test.rs new file mode 100644 index 0000000..e4b0947 --- /dev/null +++ b/tests/imap_test.rs @@ -0,0 +1,69 @@ +extern crate himalaya; + +use himalaya::{config::model::Account, imap::model::ImapConnector, msg::model::Msgs, smtp}; + +fn get_account(addr: &str) -> Account { + Account { + name: None, + downloads_dir: None, + signature: None, + default_page_size: None, + default: Some(true), + email: addr.into(), + imap_host: String::from("localhost"), + imap_port: 3993, + imap_starttls: Some(false), + imap_insecure: Some(true), + imap_login: addr.into(), + imap_passwd_cmd: String::from("echo 'password'"), + smtp_host: String::from("localhost"), + smtp_port: 3465, + smtp_starttls: Some(false), + smtp_insecure: Some(true), + smtp_login: addr.into(), + smtp_passwd_cmd: String::from("echo 'password'"), + } +} + +#[test] +fn mbox() { + let account = get_account("inbox@localhost"); + let mut imap_conn = ImapConnector::new(&account).unwrap(); + let mboxes: Vec = imap_conn + .list_mboxes() + .unwrap() + .0 + .into_iter() + .map(|mbox| mbox.name) + .collect(); + assert_eq!(mboxes, vec![String::from("INBOX")]); + imap_conn.logout(); +} + +#[test] +fn msg() { + let account = get_account("inbox@localhost"); + + // Let's add message + smtp::send( + &account, + &lettre::Message::builder() + .from("sender@localhost".parse().unwrap()) + .to("inbox@localhost".parse().unwrap()) + .subject("Very important message") + .singlepart( + lettre::message::SinglePart::builder().body("Hello, world!".as_bytes().to_vec()), + ) + .unwrap(), + ) + .unwrap(); + + // We should see the message + let mut imap_conn = ImapConnector::new(&account).unwrap(); + let msgs = imap_conn.list_msgs("INBOX", &10, &0).unwrap(); + let msgs = Msgs::from(&msgs); + assert_eq!(msgs.0.len(), 1); + let msg = msgs.0.first().unwrap(); + assert_eq!("Very important message", msg.subject.as_str()); + imap_conn.logout(); +} diff --git a/wiki b/wiki index 8cc2376..9de3cae 160000 --- a/wiki +++ b/wiki @@ -1 +1 @@ -Subproject commit 8cc2376ccbf69fe256935c186ec7140359b845e0 +Subproject commit 9de3caecf8c003285a97f499676c1f28a557876b