net unitests
parent
ced107c5b3
commit
16cb6a5de3
|
|
@ -94,8 +94,56 @@ pub async fn init_api_grub_mechanism(config: ApiConfig, rx: &mut Receiver<ApiCon
|
||||||
// Ok(())
|
// 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)
|
||||||
|
}
|
||||||
|
|
||||||
// one-time exec func to send request, deserialize it and return object
|
#[test]
|
||||||
#[allow(dead_code)]
|
async fn check_api_poll_is_default() {
|
||||||
async fn send_api_request() -> Result<()> {Ok(())}
|
let mut conf1 = ApiConfig::default();
|
||||||
|
let poll = ApiPoll::new(&mut conf1).await;
|
||||||
|
assert!(poll.is_default().await)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[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());
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue