config unitests
parent
8acf1230d2
commit
ced107c5b3
|
|
@ -78,3 +78,53 @@ 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())
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue