use super::*;
#[test]
fn a_stale_daemon_is_replaced_rather_than_reused() {
let steps = start_steps(true, true);
assert!(steps.shutdown_first);
assert!(steps.spawn);
}
#[test]
fn a_current_daemon_is_left_alone() {
assert_eq!(start_steps(true, false), StartSteps::SATISFIED);
}
#[test]
fn nothing_running_spawns_without_a_shutdown() {
for stale in [true, false] {
let steps = start_steps(false, stale);
assert!(!steps.shutdown_first, "stale={stale}");
assert!(steps.spawn, "stale={stale}");
}
}
#[test]
fn a_shutdown_is_never_ordered_without_a_spawn() {
for running in [true, false] {
for stale in [true, false] {
let steps = start_steps(running, stale);
assert!(
!steps.shutdown_first || steps.spawn,
"running={running} stale={stale} would stop without starting"
);
}
}
}
#[test]
fn a_recorded_pid_is_signalled_and_a_missing_one_propagates() {
assert_eq!(stop_fallback(Some(4321)), StopFallback::Signal(4321));
assert_eq!(stop_fallback(None), StopFallback::Propagate);
}
#[test]
fn status_omits_supervision_when_there_is_none_to_report() {
assert_eq!(status_lines(true, 3, None).len(), 1);
let with = status_lines(true, 3, Some("supervised".to_string()));
assert_eq!(with.len(), 2);
assert_eq!(with[1], "supervised");
}
#[test]
fn not_running_is_a_success_and_not_stopping_is_not() {
assert_eq!(stop_outcome(false, false), Ok("daemon not running"));
assert_eq!(stop_outcome(false, true), Ok("daemon not running"));
assert_eq!(stop_outcome(true, true), Ok("daemon stopped"));
assert!(stop_outcome(true, false).is_err());
}