Integration tests
Gil Poiares-Oliveira gil@poiares-oliveira.com
Tue, 02 May 2023 18:25:40 +0100
2 files changed,
113 insertions(+),
75 deletions(-)
M
src/lib.rs
→
src/lib.rs
@@ -22,87 +22,46 @@ pub mod structures;
pub use client::OmglolClient; -#[cfg(test)] -mod tests { - use super::*; - use std::env; +// #[cfg(test)] +// mod tests { +// use super::*; +// use std::env; - // These tests are just for debugging, no proper test-driven development here - // don't use this for anything +// // These tests are just for debugging, no proper test-driven development here +// // don't use this for anything - fn init_client() -> (OmglolClient, String) { - use dotenv::dotenv; - dotenv().ok(); - let address = env::var("OMGLOL_ADDRESS").unwrap_or("foobar".to_string()); - let api_key = env::var("OMGLOL_API_KEY").unwrap_or("".to_string()); - let client = OmglolClient::new(Some(api_key)); - println!("Using account {} for testing", &address); +// fn init_client() -> (OmglolClient, String) { +// use dotenv::dotenv; +// dotenv().ok(); +// let address = env::var("OMGLOL_ADDRESS").unwrap_or("foobar".to_string()); +// let api_key = env::var("OMGLOL_API_KEY").unwrap_or("".to_string()); +// let client = OmglolClient::new(Some(api_key)); +// println!("Using account {} for testing", &address); - return (client, address); - } +// return (client, address); +// } - #[tokio::test] - async fn main() { - // If you're learning Rust best practices, maybe you should ignore the next - // 2 lines. This is a test function so does anyone *actually* care? +// #[tokio::test] +// async fn main() { +// If you're learning Rust best practices, maybe you should ignore the next +// 2 lines. This is a test function so does anyone *actually* care? - //let info = client.get_profile_themes().await; +//let info = client.get_profile_themes().await; - //println!("{:#?}", info); +//println!("{:#?}", info); - //let info = requests::dns::get_dns_records(&address, &api_key).await; - // let info = requests::themes::get_profile_themes().await; - // let info = get_statuslog_status(&address, "63a8a6b3cbdc5").await; - // let info = get_all_statuslog_statuses(&address).await; +//let info = requests::dns::get_dns_records(&address, &api_key).await; +// let info = requests::themes::get_profile_themes().await; +// let info = get_statuslog_status(&address, "63a8a6b3cbdc5").await; +// let info = get_all_statuslog_statuses(&address).await; - //let my_client = OmglolClient::new(address, api_key=api_key); +//let my_client = OmglolClient::new(address, api_key=api_key); - // let destinations = vec![ - // EmailAddress::from_str("foo@example.net").unwrap(), - // EmailAddress::from_str("bar@example.net").unwrap(), - // ]; - // let info = - // requests::email::set_forwarding_addresses(&address, &destinations, &api_key).await; - //println!("response = {:#?}", info); - } - - #[tokio::test] - async fn get_service_status() { - let (client, _) = init_client(); - let service_status = client.service_status().await; - println!("{:#?}", service_status); - } - - #[tokio::test] - async fn get_profile_themes() { - let (client, _) = init_client(); - let info = client.get_profile_themes().await; - println!("{:#?}", info); - } - - #[tokio::test] - async fn get_dns_records() { - let (client, address) = init_client(); - let response = client.get_dns_records(&address).await; - println!("{:#?}", response); - } - - #[tokio::test] - async fn get_web_page() { - let (client, address) = init_client(); - let response = client.get_web_page(&address).await; - println!("{:#?}", response); - } - - #[tokio::test] - async fn query_unauthorized_endpoint() { - let (client, _) = init_client(); - let response = client.get_web_page("foobar").await; - println!("{:#?}", response); - } - - #[test] - fn dns_display() { - assert!(format!("{}", structures::DNStype::A) == "A"); - } -} +// let destinations = vec![ +// EmailAddress::from_str("foo@example.net").unwrap(), +// EmailAddress::from_str("bar@example.net").unwrap(), +// ]; +// let info = +// requests::email::set_forwarding_addresses(&address, &destinations, &api_key).await; +//println!("response = {:#?}", info); +//}
A
tests/integration_tests.rs
@@ -0,0 +1,79 @@
+use omglol::{OmglolClient, structures::{DNStype, RequestError}}; + +use dotenv::dotenv; +use std::env; + +fn init_client() -> (OmglolClient, String) { + dotenv().ok(); + let address = env::var("OMGLOL_ADDRESS").unwrap_or("foobar".to_string()); + let api_key = env::var("OMGLOL_API_KEY").unwrap_or("".to_string()); + let client = OmglolClient::new(Some(api_key)); + println!("Using account {} for testing", &address); + + return (client, address); +} + +#[tokio::test] +async fn get_all_statuses() { + let (client, address) = init_client(); + let response = client.get_all_statuses(&address) + .await + .unwrap() + .response; + println!("{:#?}", response); +} + +#[test] +fn dns_display () { + assert!(format!("{}", DNStype::A) == "A"); +} + +#[tokio::test] +async fn get_service_status() { + let (client, _) = init_client(); + let service_status = client.service_status() + .await + .unwrap() + .response; + println!("{:#?}", service_status); +} + +#[tokio::test] +async fn get_profile_themes() { + let (client, _) = init_client(); + let info = client.get_profile_themes() + .await + .unwrap() + .response; + println!("{:#?}", info); +} + +#[tokio::test] +async fn get_dns_records() { + let (client, address) = init_client(); + let response = client.get_dns_records(&address) + .await + .unwrap() + .response; + println!("{:#?}", response); +} + +#[tokio::test] +async fn get_web_page() { + let (client, address) = init_client(); + let response = client.get_web_page(&address) + .await + .unwrap() + .response; + println!("{:#?}", response); +} + +#[tokio::test] +async fn query_unauthorized_endpoint() { + let (client, _) = init_client(); + let response_result = client.get_web_page("foobar") + .await; + let raised_error = *&dyn response_result.err().unwrap(); + assert_eq!(*raised_error.status_code, 401); + println!("{:#?}", response_result); +}