Skip to content

Commit

Permalink
Integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
GilOliveira committed May 2, 2023
1 parent 98ced36 commit 915a549
Show file tree
Hide file tree
Showing 2 changed files with 122 additions and 84 deletions.
127 changes: 43 additions & 84 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,87 +22,46 @@ pub mod structures;

pub use client::OmglolClient;

#[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

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);
}

#[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;

//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 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");
}
}
// #[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

// 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);
// }

// #[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;

//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 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);
//}
79 changes: 79 additions & 0 deletions tests/integration_tests.rs
Original file line number Diff line number Diff line change
@@ -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);
}

0 comments on commit 915a549

Please sign in to comment.