Compare commits
No commits in common. "ae0c47df353debee64f0dfd44ace682fd8f60348" and "572fbcd3eb7cca1981e821ea32e0874063284bed" have entirely different histories.
ae0c47df35
...
572fbcd3eb
|
|
@ -2,4 +2,4 @@
|
||||||
.idea
|
.idea
|
||||||
Dockerfile
|
Dockerfile
|
||||||
Cargo.lock
|
Cargo.lock
|
||||||
settings.json
|
settings.json
|
||||||
|
|
|
||||||
|
|
@ -6,8 +6,6 @@ use std::process::Command;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::{env, fs};
|
use std::{env, fs};
|
||||||
use tokio::time::Duration;
|
use tokio::time::Duration;
|
||||||
use std::fs::OpenOptions;
|
|
||||||
use std::io::{self, Write};
|
|
||||||
|
|
||||||
const CONFIG_PATH: &str = "settings.json";
|
const CONFIG_PATH: &str = "settings.json";
|
||||||
|
|
||||||
|
|
@ -251,27 +249,9 @@ fn config_comparing(local: &Processes, remote: &Processes) -> ConfigActuality {
|
||||||
|
|
||||||
fn save_new_config(config: &Processes, config_file: &str) -> Result<(), CustomError> {
|
fn save_new_config(config: &Processes, config_file: &str) -> Result<(), CustomError> {
|
||||||
match serde_json::to_string_pretty(&config) {
|
match serde_json::to_string_pretty(&config) {
|
||||||
// Ok(st) => match fs::write(config_file, st) {
|
Ok(st) => match fs::write(config_file, st) {
|
||||||
// Ok(_) => Ok(()),
|
Ok(_) => Ok(()),
|
||||||
// Err(_) => Err(CustomError::Fatal),
|
Err(_) => Err(CustomError::Fatal),
|
||||||
// },
|
|
||||||
Ok(st) => {
|
|
||||||
let file = OpenOptions::new()
|
|
||||||
.read(true)
|
|
||||||
.write(true)
|
|
||||||
.create(true)
|
|
||||||
.truncate(false)
|
|
||||||
.open(config_file);
|
|
||||||
match file {
|
|
||||||
Ok(fs) => {
|
|
||||||
let mut writer = fs;
|
|
||||||
match writeln!(writer, "{}", st) {
|
|
||||||
Ok(_) => Ok(()),
|
|
||||||
Err(_) => Err(CustomError::Fatal),
|
|
||||||
}
|
|
||||||
},
|
|
||||||
Err(_) => return Err(CustomError::Fatal)
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
Err(_) => Err(CustomError::Fatal),
|
Err(_) => Err(CustomError::Fatal),
|
||||||
}
|
}
|
||||||
|
|
@ -283,60 +263,3 @@ fn parse_extern_config(json_string: &str) -> Option<Processes> {
|
||||||
}
|
}
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// unit tests
|
|
||||||
#[cfg(test)]
|
|
||||||
mod config_unittests {
|
|
||||||
use super::*;
|
|
||||||
#[test]
|
|
||||||
fn parsing_valid_conf() {
|
|
||||||
assert!(load_processes("tests/examples/settings.json").is_some());
|
|
||||||
}
|
|
||||||
#[test]
|
|
||||||
fn parsing_invalid_conf() {
|
|
||||||
assert!(load_processes("tests/examples/invalid_config.json").is_none());
|
|
||||||
}
|
|
||||||
#[test]
|
|
||||||
fn configuration_comparing() {
|
|
||||||
// old one (kinda local)
|
|
||||||
let a = Processes {
|
|
||||||
date_of_creation: String::from("1"),
|
|
||||||
config_server: String::new(),
|
|
||||||
processes: vec![],
|
|
||||||
};
|
|
||||||
// new one (kinda remote)
|
|
||||||
let b = Processes {
|
|
||||||
date_of_creation: String::from("2"),
|
|
||||||
config_server: String::new(),
|
|
||||||
processes: vec![],
|
|
||||||
};
|
|
||||||
|
|
||||||
assert_eq!(config_comparing(&a, &b), ConfigActuality::Remote);
|
|
||||||
}
|
|
||||||
#[test]
|
|
||||||
fn get_actual_config_mechanism() {
|
|
||||||
assert!(get_actual_config().is_some())
|
|
||||||
}
|
|
||||||
#[test]
|
|
||||||
fn save_config() {
|
|
||||||
let a = Processes {
|
|
||||||
date_of_creation: String::from("1"),
|
|
||||||
config_server: String::new(),
|
|
||||||
processes: vec![],
|
|
||||||
};
|
|
||||||
assert!(save_new_config(&a, "tests/examples/save-conf.json").is_ok());
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn save_to_zero_file() {
|
|
||||||
let a = Processes {
|
|
||||||
date_of_creation: String::from("1"),
|
|
||||||
config_server: String::new(),
|
|
||||||
processes: vec![],
|
|
||||||
};
|
|
||||||
assert!(save_new_config(&a, "tests/examples/none.json").is_ok());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -3,9 +3,7 @@ use serde::{Deserialize, Serialize};
|
||||||
/// # an Error enum (next will be deleted and replaced)
|
/// # an Error enum (next will be deleted and replaced)
|
||||||
pub enum CustomError {
|
pub enum CustomError {
|
||||||
Fatal,
|
Fatal,
|
||||||
|
|
||||||
}
|
}
|
||||||
#[derive(Debug, PartialEq)]
|
|
||||||
pub enum ConfigActuality {
|
pub enum ConfigActuality {
|
||||||
Local,
|
Local,
|
||||||
Remote,
|
Remote,
|
||||||
|
|
|
||||||
|
|
@ -1,33 +0,0 @@
|
||||||
{
|
|
||||||
"configServer" : "localhost",
|
|
||||||
"processes": [
|
|
||||||
{
|
|
||||||
"name": "temp-process",
|
|
||||||
"path": "/home/user/monitor/runner-rs/temp-process",
|
|
||||||
"dependencies": {
|
|
||||||
"files": [
|
|
||||||
{
|
|
||||||
"filename": "dep-file",
|
|
||||||
"src": "/home/user/monitor/runner-rs/tests/examples/",
|
|
||||||
"triggers": {
|
|
||||||
"onDelete": "stop",
|
|
||||||
"onChange": "stay"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"services": [
|
|
||||||
{
|
|
||||||
"hostname": "ya.ru",
|
|
||||||
"port": 443,
|
|
||||||
"triggers": {
|
|
||||||
"wait": 10,
|
|
||||||
"delay": 2,
|
|
||||||
"onLost": "hold"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
@ -1,5 +0,0 @@
|
||||||
{
|
|
||||||
"dateOfCreation": "1",
|
|
||||||
"configServer": "",
|
|
||||||
"processes": []
|
|
||||||
}
|
|
||||||
|
|
@ -1,5 +0,0 @@
|
||||||
{
|
|
||||||
"dateOfCreation": "1",
|
|
||||||
"configServer": "",
|
|
||||||
"processes": []
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue