Compare commits
No commits in common. "de727de2001b3477463ff8915b9e41e84ca1bf5e" and "c00fb883c91c425d50492f4157aefdb07be5a8db" have entirely different histories.
de727de200
...
c00fb883c9
|
|
@ -9,7 +9,7 @@
|
||||||
|
|
||||||
| Crate (submodule) | Progress |
|
| Crate (submodule) | Progress |
|
||||||
|---|---|
|
|---|---|
|
||||||
|`api-grub` | ✅✅✅✅✅✅✅🔲🔲🔲 |
|
|`api-grub` | ✅✅✅✅🔲🔲🔲🔲🔲🔲 |
|
||||||
|`config-delivery` | 🔲🔲🔲🔲🔲🔲🔲🔲🔲🔲 |
|
|`config-delivery` | 🔲🔲🔲🔲🔲🔲🔲🔲🔲🔲 |
|
||||||
|`integrs-structs` | ✅✅✅✅✅✅🔲🔲🔲🔲 |
|
|`integrs-structs` | ✅✅✅✅✅✅🔲🔲🔲🔲 |
|
||||||
|`preproc` | 🔲🔲🔲🔲🔲🔲🔲🔲🔲🔲 |
|
|`preproc` | 🔲🔲🔲🔲🔲🔲🔲🔲🔲🔲 |
|
||||||
|
|
|
||||||
|
|
@ -78,53 +78,3 @@ async fn init_unix_listener() -> Result<UnixListener> {
|
||||||
let _ = fs::remove_file(SOCKET_PATH);
|
let _ = fs::remove_file(SOCKET_PATH);
|
||||||
Ok(UnixListener::bind(SOCKET_PATH)?)
|
Ok(UnixListener::bind(SOCKET_PATH)?)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod config_unittests {
|
|
||||||
use super::*;
|
|
||||||
use tokio::test;
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
async fn check_init_unix_listener() {
|
|
||||||
let res = init_unix_listener().await;
|
|
||||||
if res.is_ok() {
|
|
||||||
assert!(fs::remove_file(SOCKET_PATH).is_ok())
|
|
||||||
} else {
|
|
||||||
assert!(false)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#[test]
|
|
||||||
async fn check_save_new_config() {
|
|
||||||
use std::fs;
|
|
||||||
use integr_structs::api::ApiConfig;
|
|
||||||
use serde_json::to_string;
|
|
||||||
|
|
||||||
let test_config_path = "test_config_api.json";
|
|
||||||
|
|
||||||
// config gen
|
|
||||||
let config = to_string::<ApiConfig>(&ApiConfig::default());
|
|
||||||
assert!(config.is_ok());
|
|
||||||
let config = config.unwrap();
|
|
||||||
|
|
||||||
// config file gen and write
|
|
||||||
assert!(fs::File::create(test_config_path).is_ok());
|
|
||||||
assert!(fs::write(test_config_path, config).is_ok());
|
|
||||||
|
|
||||||
// config file reading and checking content
|
|
||||||
let file = fs::read_to_string(test_config_path);
|
|
||||||
assert!(file.is_ok());
|
|
||||||
let file = file.unwrap();
|
|
||||||
assert_ne!(file.len(), 0);
|
|
||||||
|
|
||||||
// deleting test config file
|
|
||||||
assert!(fs::remove_file(test_config_path).is_ok())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
async fn check_pull_local_config() {
|
|
||||||
use std::path::Path;
|
|
||||||
let local_config = Path::new(CONFIG_PATH);
|
|
||||||
assert_eq!(local_config.is_file() && local_config.exists(), pull_local_config().await.is_ok())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -24,27 +24,3 @@ pub async fn setup_logger() -> Result<()> {
|
||||||
info!("Logger configured");
|
info!("Logger configured");
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod logger_unittests {
|
|
||||||
use tokio::test;
|
|
||||||
use super::*;
|
|
||||||
#[test]
|
|
||||||
async fn check_logger_builder() {
|
|
||||||
Builder::new()
|
|
||||||
.format(move |buf, record| {
|
|
||||||
writeln!(
|
|
||||||
buf,
|
|
||||||
"|{}| {} [{}] - {}",
|
|
||||||
"api-grubber",
|
|
||||||
Local::now().format("%d-%m-%Y %H:%M:%S"),
|
|
||||||
record.level(),
|
|
||||||
record.args(),
|
|
||||||
)
|
|
||||||
})
|
|
||||||
.filter(None, LevelFilter::Info)
|
|
||||||
.target(env_logger::Target::Stdout)
|
|
||||||
.init();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -94,56 +94,8 @@ 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)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
// one-time exec func to send request, deserialize it and return object
|
||||||
async fn check_api_poll_is_default() {
|
#[allow(dead_code)]
|
||||||
let mut conf1 = ApiConfig::default();
|
async fn send_api_request() -> Result<()> {Ok(())}
|
||||||
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