diff --git a/Cargo.toml b/Cargo.toml index d900a53..0a751e9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,7 +9,7 @@ edition = "2018" [dependencies] env_logger = "0.8" log = "0.4" -tokio = { version = "1.2", features = ["macros", "rt"]} +tokio = { version = "1.2", features = ["macros", "rt", "rt-multi-thread"]} reqwest = "0.11" minidom = "0.13" url = { version = "2.2", features = ["serde"] } diff --git a/src/bin/dummy.rs b/src/bin/dummy.rs new file mode 100644 index 0000000..eabd92e --- /dev/null +++ b/src/bin/dummy.rs @@ -0,0 +1,17 @@ +use my_tasks::client::Client; +use my_tasks::settings::URL; +use my_tasks::settings::USERNAME; +use my_tasks::settings::PASSWORD; + + +#[tokio::main] +async fn main() { + // This is just a function to silence "unused function" warning + + let mut client = Client::new(URL, USERNAME, PASSWORD).unwrap(); + let calendars = client.get_calendars().await.unwrap(); + let _ = calendars.iter() + .map(|cal| println!(" {}\t{}", cal.name(), cal.url().as_str())) + .collect::<()>(); + let _ = client.get_tasks(&calendars[3].url()).await; +} diff --git a/src/lib.rs b/src/lib.rs index 0b0eb21..1724ca4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -8,7 +8,7 @@ //! A `Provider` abstracts these two sources by merging them together into one virtual source. \ //! It also handles synchronisation between the local cache and the server. -mod calendar; +pub mod calendar; pub use calendar::Calendar; mod task; pub use task::Task; diff --git a/src/utils.rs b/src/utils.rs index fa80b76..b0e0a1b 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -46,7 +46,6 @@ pub fn print_xml(element: &Element) { std::io::stdout(), 0x20, 4 ); - element.to_writer(&mut xml_writer); - - writer.write(&[0x0a]); + let _ = element.to_writer(&mut xml_writer); + let _ = writer.write(&[0x0a]); } diff --git a/tests/caldav_client.rs b/tests/caldav_client.rs index 25f04ec..314fd0c 100644 --- a/tests/caldav_client.rs +++ b/tests/caldav_client.rs @@ -1,97 +1,94 @@ -//! Some tests of a CalDAV client. -//! Most of them are not really integration tests, but just development tests that should be cleaned up one day. - -use std::error::Error; -use std::convert::TryFrom; - -use reqwest::Method; -use reqwest::header::CONTENT_TYPE; -use minidom::Element; -use url::Url; - -use my_tasks::client::Client; -use my_tasks::settings::URL; -use my_tasks::settings::USERNAME; -use my_tasks::settings::PASSWORD; -use my_tasks::settings::EXAMPLE_TASK_URL; -use my_tasks::settings::EXAMPLE_CALENDAR_URL; - -static EXAMPLE_TASKS_BODY_LAST_MODIFIED: &str = r#" - - - - - - - - - - - - - - - -"#; - -#[tokio::test] -async fn test_client() { - let _ = env_logger::builder().is_test(true).try_init(); - - let mut client = Client::new(URL, USERNAME, PASSWORD).unwrap(); - let calendars = client.get_calendars().await.unwrap(); - - println!("Calendars:"); - calendars.iter() - .map(|cal| println!(" {}\t{}", cal.name(), cal.url().as_str())) - .collect::<()>(); - - client.get_tasks(&calendars[3].url()).await; -} - -#[tokio::test] -async fn profind() { - let _ = env_logger::builder().is_test(true).try_init(); - - let url: Url = EXAMPLE_TASK_URL.parse().unwrap(); - - let method = Method::from_bytes(b"PROPFIND") - .expect("cannot create PROPFIND method."); - - let res = reqwest::Client::new() - .request(method, url.as_str()) - .header("Depth", 0) - .header(CONTENT_TYPE, "application/xml") - .basic_auth(USERNAME, Some(PASSWORD)) - //.body(body) - .send() - .await - .unwrap(); - - println!("{:?}", res.text().await); -} - -#[tokio::test] -async fn last_modified() { - let _ = env_logger::builder().is_test(true).try_init(); - - let url: Url = EXAMPLE_CALENDAR_URL.parse().unwrap(); - - let method = Method::from_bytes(b"REPORT") - .expect("cannot create REPORT method."); - - let res = reqwest::Client::new() - .request(method, url.as_str()) - .header("Depth", 1) - .header(CONTENT_TYPE, "application/xml") - .basic_auth(USERNAME, Some(PASSWORD)) - .body(EXAMPLE_TASKS_BODY_LAST_MODIFIED) - .send() - .await - .unwrap(); - - let el: Element = res.text().await.unwrap().parse().unwrap(); - my_tasks::utils::print_xml(&el); -} +//! Some tests of a CalDAV client. +//! Most of them are not really integration tests, but just development tests that should be cleaned up one day. + +use reqwest::Method; +use reqwest::header::CONTENT_TYPE; +use minidom::Element; +use url::Url; + +use my_tasks::client::Client; +use my_tasks::settings::URL; +use my_tasks::settings::USERNAME; +use my_tasks::settings::PASSWORD; +use my_tasks::settings::EXAMPLE_TASK_URL; +use my_tasks::settings::EXAMPLE_CALENDAR_URL; + +static EXAMPLE_TASKS_BODY_LAST_MODIFIED: &str = r#" + + + + + + + + + + + + + + + +"#; + +#[tokio::test] +async fn test_client() { + let _ = env_logger::builder().is_test(true).try_init(); + + let mut client = Client::new(URL, USERNAME, PASSWORD).unwrap(); + let calendars = client.get_calendars().await.unwrap(); + + println!("Calendars:"); + let _ = calendars.iter() + .map(|cal| println!(" {}\t{}", cal.name(), cal.url().as_str())) + .collect::<()>(); + + let _ = client.get_tasks(&calendars[3].url()).await; +} + +#[tokio::test] +async fn profind() { + let _ = env_logger::builder().is_test(true).try_init(); + + let url: Url = EXAMPLE_TASK_URL.parse().unwrap(); + + let method = Method::from_bytes(b"PROPFIND") + .expect("cannot create PROPFIND method."); + + let res = reqwest::Client::new() + .request(method, url.as_str()) + .header("Depth", 0) + .header(CONTENT_TYPE, "application/xml") + .basic_auth(USERNAME, Some(PASSWORD)) + //.body(body) + .send() + .await + .unwrap(); + + println!("{:?}", res.text().await); +} + +#[tokio::test] +async fn last_modified() { + let _ = env_logger::builder().is_test(true).try_init(); + + let url: Url = EXAMPLE_CALENDAR_URL.parse().unwrap(); + + let method = Method::from_bytes(b"REPORT") + .expect("cannot create REPORT method."); + + let res = reqwest::Client::new() + .request(method, url.as_str()) + .header("Depth", 1) + .header(CONTENT_TYPE, "application/xml") + .basic_auth(USERNAME, Some(PASSWORD)) + .body(EXAMPLE_TASKS_BODY_LAST_MODIFIED) + .send() + .await + .unwrap(); + + let el: Element = res.text().await.unwrap().parse().unwrap(); + my_tasks::utils::print_xml(&el); +}