use std::time::Duration;
pub const FEED_REPAIR_AUTO: &str = "repair_auto";
pub const LOOK_EVERY: Duration = Duration::from_secs(20);
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub struct Awaits<'a> {
pub fresh: bool,
pub restoring: bool,
pub recharge_from: &'a str,
}
pub fn auto_on(auto: Option<&str>) -> bool {
auto.map(str::trim) == Some("true")
}
pub fn due(auto: Option<&str>, main: &Awaits<'_>) -> bool {
auto_on(auto) && !main.recharge_from.trim().is_empty() && (main.fresh || main.restoring)
}
#[cfg(test)]
mod tests {
use super::*;
const TWIN: &str = "10.44.0.3:50051";
#[test]
fn the_front_fills_only_an_awaiting_main_with_auto_fix_fed() {
let awaiting = Awaits { fresh: true, restoring: false, recharge_from: TWIN };
assert!(due(Some("true"), &awaiting));
assert!(due(Some(" true\n"), &awaiting), "the word is trimmed");
assert!(!due(None, &awaiting) && !due(Some("yes"), &awaiting) && !due(Some("TRUE"), &awaiting), "auto-fix not fed");
let restoring = Awaits { fresh: false, restoring: true, ..awaiting };
assert!(due(Some("true"), &restoring), "a restore it began is resumed");
let whole = Awaits { fresh: false, restoring: false, ..awaiting };
assert!(!due(Some("true"), &whole), "a main with data is never streamed into");
let first_install = Awaits { fresh: true, restoring: false, recharge_from: " " };
assert!(!due(Some("true"), &first_install), "a fresh main nobody re-admitted as a recharge is not filled");
}
}