Skip to main content

isoloom_render/
checks.rs

1//! What the backends' check runners share: where a probe reaches its host.
2
3use isoloom_plan::Environment;
4use isoloom_plan::checks::Host;
5
6/// A probe's host at its address: a machine where a probe reaches it on the network
7/// ([`Environment::probe_address`]), a literal as written. For the targets that keep the
8/// plan's addresses; one that hands addresses out itself (Kubernetes) reaches machines by name.
9#[must_use]
10pub fn address_of(env: &Environment, host: &Host) -> String {
11    match host {
12        Host::Machine { name, network } => env.probe_address(name, network),
13        Host::Literal(literal) => literal.clone(),
14    }
15}
16
17#[cfg(test)]
18mod tests {
19    use isoloom_plan::Environment;
20    use isoloom_plan::checks::Host;
21    use isoloom_spec::model::Target;
22
23    #[test]
24    fn a_machine_is_reached_at_its_address_and_a_literal_as_written() {
25        let lab = isoloom_plan::Lab::parse(
26            "version: 1\nname: t\nnetworks: { lan: { cidr: 10.9.0.0/24 } }\nmachines:\n  web: { networks: { lan: 10 }, os: debian@12 }\n",
27        )
28        .expect("parses");
29        let env = Environment::build(&lab.for_target(Target::Vagrant), Target::Vagrant, None);
30        let web = Host::Machine {
31            name: "web".into(),
32            network: "lan".into(),
33        };
34        assert_eq!(super::address_of(&env, &web), "10.9.0.10");
35        assert_eq!(super::address_of(&env, &Host::Literal("example.com".into())), "example.com");
36    }
37}