cargo fmt

pull/9/head
prplV 2024-11-01 16:55:23 +03:00
parent 32e182682f
commit 27c21e5cd9
11 changed files with 56 additions and 72 deletions

View File

@ -1,13 +1,13 @@
use crate::options::structs::*;
use log::{error, info, warn};
use redis::{Client, Commands, Connection, RedisResult};
use std::fs::OpenOptions;
use std::io::Write;
use std::os::unix::process::CommandExt;
use std::process::Command;
use std::sync::Arc;
use std::{env, fs};
use tokio::time::Duration;
use std::fs::OpenOptions;
use std::io::Write;
const CONFIG_PATH: &str = "settings.json";
@ -269,10 +269,10 @@ fn save_new_config(config: &Processes, config_file: &str) -> Result<(), CustomEr
Ok(_) => Ok(()),
Err(_) => Err(CustomError::Fatal),
}
},
Err(_) => return Err(CustomError::Fatal)
}
Err(_) => return Err(CustomError::Fatal),
}
},
}
Err(_) => Err(CustomError::Fatal),
}
}
@ -284,12 +284,9 @@ fn parse_extern_config(json_string: &str) -> Option<Processes> {
None
}
// unit tests
#[cfg(test)]
mod config_unittests {
mod config_unittests {
use super::*;
#[test]
fn parsing_valid_conf() {
@ -340,4 +337,4 @@ fn parse_extern_config(json_string: &str) -> Option<Processes> {
};
assert!(save_new_config(&a, "tests/examples/none.json").is_ok());
}
}
}

View File

@ -45,7 +45,6 @@ pub fn setup_logger() -> Result<(), crate::options::structs::CustomError> {
Ok(())
}
#[cfg(test)]
mod logger_tests {
use super::*;

View File

@ -76,7 +76,6 @@ impl SigPostProcessing for Sig {
}
}
#[cfg(test)]
mod signals_unittest {
use super::*;

View File

@ -3,7 +3,6 @@ use serde::{Deserialize, Serialize};
/// # an Error enum (next will be deleted and replaced)
pub enum CustomError {
Fatal,
}
#[derive(Debug, PartialEq)]
pub enum ConfigActuality {

View File

@ -1,8 +1,8 @@
pub mod files;
pub mod prcs;
pub mod services;
pub mod hagent;
pub mod metrics;
pub mod prcs;
pub mod services;
use crate::options::structs::TrackingProcess;
use files::create_watcher;
@ -35,8 +35,7 @@ pub async fn run_daemons(
for file in proc.dependencies.files.clone().into_iter() {
if let Ok(watcher) = create_watcher(&file.filename, &file.src).await {
watchers.push(watcher);
}
else {
} else {
let _ = tx.send(121).await;
}
// watchers.push(create_watcher(&file.filename, &file.src).await.unwrap());
@ -141,7 +140,7 @@ pub async fn run_daemons(
//
// 121 - Cannot create valid watcher for file dependency
121 => {
error!("Cannot create valid watcher for {}'s file dependency. Terminating...", proc.name);
error!("Cannot create valid watcher for {}'s file dependency. Terminating thread...", proc.name);
let _ = terminate_process("runner-rs").await;
break;
},
@ -212,13 +211,10 @@ pub fn get_container_id() -> Option<String> {
}
Some(String::from_utf8_lossy(&output.stdout).to_string())
}
Err(_) => {
None
}
Err(_) => None,
}
}
#[cfg(test)]
mod utils_unittests {
use super::get_container_id;

View File

@ -115,8 +115,6 @@ pub async fn check_file(filename: &str, path: &str) -> Result<(), CustomError> {
})
}
#[cfg(test)]
mod files_unittests {
use super::*;

View File

@ -1,6 +1,6 @@
// module needed to check host-agent health condition and to communicate with it
use tokio::net::UnixStream;
use crate::options::structs::CustomError;
use tokio::net::UnixStream;
//
// code will be here
//
@ -9,7 +9,6 @@ async fn open_unix_socket() -> Result<UnixStream, std::io::Error> {
Ok(socket)
}
#[cfg(test)]
mod hagent_unittets {
use super::*;

View File

@ -5,7 +5,6 @@
// code will be here
//
#[cfg(test)]
mod metrics_unittets {
#[tokio::test]
@ -29,7 +28,7 @@ mod metrics_unittets {
#[tokio::test]
// can't be tested this way because of 0-0 loop of checking buffer
// async func with loop inside
async fn get_net_stat(){
async fn get_net_stat() {
assert!(true);
}
#[tokio::test]

View File

@ -7,12 +7,8 @@ use tokio::time::Duration;
pub async fn get_pid(name: &str) -> Result<Output, std::io::Error> {
let name = Arc::new(name.to_string());
let res= tokio::task::spawn_blocking(move || {
Command::new("pidof")
.arg(&*name)
.output()
})
.await?;
let res =
tokio::task::spawn_blocking(move || Command::new("pidof").arg(&*name).output()).await?;
if let Ok(output) = res {
if output.stderr.is_empty() && output.stdout.is_empty() {
return Err(io::ErrorKind::NotFound.into());
@ -43,7 +39,7 @@ pub async fn is_active(name: &str) -> bool {
// T is for stopped processes
pub async fn is_frozen(name: &str) -> bool {
let temp: Output ;
let temp: Output;
if let Ok(output) = get_pid(name).await {
temp = output;
} else {
@ -113,11 +109,13 @@ pub async fn start_process(name: &str, path: &str) -> Result<(), CustomError> {
warn!("Process {} is running now!", name);
Ok(())
}
Err(er) => {println!("{:?}", er); Err(CustomError::Fatal)},
Err(er) => {
println!("{:?}", er);
Err(CustomError::Fatal)
}
}
}
#[cfg(test)]
mod process_unittests {
use super::*;
@ -133,7 +131,8 @@ mod process_unittests {
assert!(true);
let res1 = start_process("temp-process", "/home/user/monitor/runner-rs/temp-process").await;
assert!(res1.is_ok());
let res2 = restart_process("temp-process", "/home/user/monitor/runner-rs/temp-process").await;
let res2 =
restart_process("temp-process", "/home/user/monitor/runner-rs/temp-process").await;
assert!(res2.is_ok());
let _ = terminate_process("temp-process").await;
let res3 = is_active("temp-process").await;

View File

@ -120,7 +120,6 @@ async fn check_service(hostname: &str, port: &u32) -> Result<(), CustomError> {
}
}
#[cfg(test)]
mod service_unittests {
use super::check_service;