net unitests

pull/3/head
prplV 2025-01-17 13:37:41 +03:00
parent ced107c5b3
commit 16cb6a5de3
1 changed files with 51 additions and 3 deletions

View File

@ -94,8 +94,56 @@ pub async fn init_api_grub_mechanism(config: ApiConfig, rx: &mut Receiver<ApiCon
// Ok(())
}
#[cfg(test)]
mod net_unittests {
use super::*;
use tokio::test;
use integr_structs::api::{ApiConfig, ApiEndpoint};
#[test]
async fn check_str_to_rest_method() {
assert_eq!(RestMethod::from_str("get").await, Method::GET);
assert_eq!(RestMethod::from_str("post").await, Method::POST);
assert_eq!(RestMethod::from_str("patch").await, Method::PATCH);
assert_eq!(RestMethod::from_str("put").await, Method::PUT);
assert_eq!(RestMethod::from_str("delete").await, Method::DELETE);
assert_eq!(RestMethod::from_str("invalid_method").await, Method::GET);
}
#[test]
async fn check_api_poll_change_config() {
let mut conf1 = ApiConfig::default();
let conf2 = ApiConfig { endpoints : vec![], delay : 10, };
let mut poll = ApiPoll::new(&mut conf1).await;
poll.change_config(conf2).await;
assert_eq!(poll.config.delay, 10)
}
#[test]
async fn check_api_poll_is_default() {
let mut conf1 = ApiConfig::default();
let poll = ApiPoll::new(&mut conf1).await;
assert!(poll.is_default().await)
}
// one-time exec func to send request, deserialize it and return object
#[allow(dead_code)]
async fn send_api_request() -> Result<()> {Ok(())}
#[test]
async fn check_api_grubbing_mechanism_on_public_one() {
use log::{set_max_level, LevelFilter};
set_max_level(LevelFilter::Off);
let mut conf1 = ApiConfig {
endpoints : vec![
ApiEndpoint {
url : String::from("https://dummy-json.mock.beeceptor.com/countries"),
method: String::from("get"),
}],
delay : 10,
};
let conf2 = ApiConfig::default();
let mut poll = ApiPoll::new(&mut conf1).await;
assert!(poll.process_polling().await.is_ok());
poll.change_config(conf2).await;
assert!(poll.process_polling().await.is_err());
}
}