Your browser sucks, JavaScript disabled! Gunnar's console needs JavaScript and WebAssembly. Git over SSH on port 2222 does not.

nordisk/edda

crates/appliance-pid1/tests/resolver_without_dhcp.rs

//! **The resolver file and its proof need no DHCP client** (lane G6): Gunnar's dashboard
//! reads the published resolvers (`resolver::published`) in builds with `dhcp-client` off,
//! which is why gunnar-server kept its own `resolver.rs` (a copy of edda's). With the
//! module and the proof under `net`, that copy goes. The tests are Gunnar's
//! (gunnar-server `resolver`, 7e33c0f7), run from outside the crate on `net` alone.
#![cfg(feature = "net")]

use std::net::Ipv4Addr;

use appliance_pid1::resolver::{publish_under, published_under, render};

/// Gunnar's `the_published_set_is_read_back_from_the_file_and_absence_is_none`.
#[test]
fn the_published_set_is_read_back_from_the_file_and_absence_is_none() {
    let root = tempfile::tempdir().unwrap();
    assert_eq!(published_under(root.path()), None, "no file: None, never an invented resolver");
    let servers = [Ipv4Addr::new(94, 237, 127, 9), Ipv4Addr::new(94, 237, 40, 9)];
    publish_under(root.path(), &servers).unwrap();
    assert_eq!(published_under(root.path()), Some(servers.to_vec()));
}

/// Gunnar's `the_rendered_bytes_are_exact_for_one_and_for_two_servers`.
#[test]
fn the_rendered_bytes_are_exact_for_one_and_for_two_servers() {
    assert_eq!(render(&[Ipv4Addr::new(10, 0, 2, 3)]), "nameserver 10.0.2.3\noptions timeout:2 attempts:2\n");
    assert_eq!(
        render(&[Ipv4Addr::new(10, 0, 2, 3), Ipv4Addr::new(1, 1, 1, 1)]),
        "nameserver 10.0.2.3\nnameserver 1.1.1.1\noptions timeout:2 attempts:2\n"
    );
}

/// The proof runs without the DHCP feature: a name that cannot resolve is NOT proven
/// after the whole window, said as the `Err` side and never a panic.
#[test]
fn the_resolver_proof_is_reachable_on_net_alone() {
    let mut tries = 0;
    let r = appliance_pid1::net::prove_with(
        || {
            tries += 1;
            Err("Temporary failure in name resolution".into())
        },
        |_| {},
        appliance_pid1::net::RESOLVER_RETRY_WAITS,
    );
    assert!(r.is_err());
    let _: fn(&str) = appliance_pid1::net::prove_resolver;
}