use isoloom_plan::checks::Position;
use isoloom_spec::model::Arch;
pub(crate) const STAND_IN: &str = "isoloom-access";
pub(crate) fn probe_service(arch: Arch) -> String {
format!("isoloom-probe-{}", arch.id())
}
pub(crate) fn routes_service(machine: &str) -> String {
format!("{machine}-routes")
}
pub(crate) fn check_runner_service(pos: &Position, default: &Position) -> String {
if pos == default {
"isoloom-check".to_owned()
} else {
format!("isoloom-check-{}", pos.id())
}
}
pub(crate) fn tool_service(tool: &str) -> String {
format!("isoloom-tool-{tool}")
}
pub(crate) fn tool_of(service: &str) -> Option<&str> {
service.strip_prefix("isoloom-tool-")
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn the_runner_where_a_user_stands_has_the_short_name() {
let user = Position::Machine("user".into());
assert_eq!(check_runner_service(&user, &user), "isoloom-check");
assert_eq!(check_runner_service(&Position::Networks, &user), "isoloom-check-networks");
}
#[test]
fn a_tool_is_found_back_from_its_service() {
assert_eq!(tool_of(&tool_service("shell")), Some("shell"));
assert_eq!(tool_of("web"), None);
}
}