override config only ones

This commit is contained in:
jb-alvarado 2022-05-10 17:45:09 +02:00
parent dda7abfa23
commit 6c9eb99d80
3 changed files with 42 additions and 25 deletions

View File

@ -1,5 +1,4 @@
use std::{
process,
thread::{self, sleep},
time::Duration,
};
@ -17,8 +16,6 @@ fn timed_kill(sec: u64, mut proc_ctl: ProcessControl) {
sleep(Duration::from_secs(sec));
proc_ctl.kill_all();
process::exit(0);
}
#[test]
@ -49,30 +46,30 @@ fn playlist_change_at_midnight() {
player(play_control, playout_stat, proc_control);
}
#[test]
#[ignore]
fn playlist_change_at_six() {
let config = TestConfig {
mode: "playlist".into(),
start: "06:00:00".into(),
length: "24:00:00".into(),
log_to_file: false,
mail_recipient: "".into(),
};
// #[test]
// #[ignore]
// fn playlist_change_at_six() {
// let config = TestConfig {
// mode: "playlist".into(),
// start: "06:00:00".into(),
// length: "24:00:00".into(),
// log_to_file: false,
// mail_recipient: "".into(),
// };
init_config(Some(config));
// init_config(Some(config));
let play_control = PlayerControl::new();
let playout_stat = PlayoutStatus::new();
let proc_control = ProcessControl::new();
let proc_ctl = proc_control.clone();
// let play_control = PlayerControl::new();
// let playout_stat = PlayoutStatus::new();
// let proc_control = ProcessControl::new();
// let proc_ctl = proc_control.clone();
let logging = init_logging();
CombinedLogger::init(logging).unwrap();
// let logging = init_logging();
// CombinedLogger::init(logging).unwrap();
mock_time::set_mock_time("2022-05-09T05:59:45");
// mock_time::set_mock_time("2022-05-09T05:59:45");
thread::spawn(move || timed_kill(30, proc_ctl));
// thread::spawn(move || timed_kill(30, proc_ctl));
player(play_control, playout_stat, proc_control);
}
// player(play_control, playout_stat, proc_control);
// }

View File

@ -35,3 +35,20 @@ fn get_date_tomorrow() {
assert_eq!("2022-05-21".to_string(), date);
}
#[test]
fn test_delta() {
let config = TestConfig {
mode: "playlist".into(),
start: "00:00:00".into(),
length: "24:00:00".into(),
log_to_file: false,
mail_recipient: "".into(),
};
init_config(Some(config));
mock_time::set_mock_time("2022-05-09T23:59:59");
let (delta, _) = get_delta(&86401.0);
assert!(delta < 2.0);
}

View File

@ -223,6 +223,9 @@ impl GlobalConfig {
}
if let Some(log_path) = args.log {
if Path::new(&log_path).is_dir() {
config.logging.log_to_file = true;
}
config.logging.log_path = log_path;
}
@ -269,7 +272,7 @@ impl GlobalConfig {
}
pub fn global() -> &'static GlobalConfig {
INSTANCE.get().expect("Config is not initialized")
INSTANCE.get_or_init(GlobalConfig::new)
}
}