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

nordisk/holger

holger-recipe/tests/the_live_switch.rs

//! **The per-estate live-update switch reaches the cmdline** (lane M5, the pattern's
//! `live_app`): every Holger medium declares `live_app`, and `--param live_app=off` puts
//! `korp.live_update=off` on the booted cmdline, which korp-start and `holger-live` read.
//! Absent, nothing is baked: the box takes live apps, as before.

use std::collections::BTreeMap;

use holger_recipe::declared;
use holger_recipe::packaging::{LIVE_UPDATE_BOOT, LIVE_UPDATE_PARAM};
use nornir_build_thing::params::apply_params;

#[test]
fn every_holger_medium_declares_the_live_switch() {
    let set = declared();
    assert_eq!(
        set.installers.len(),
        7,
        "the open, metered, front and two keep media, and a downstream's two (one-way, fetching)"
    );
    for i in &set.installers {
        let p = i
            .params
            .iter()
            .find(|p| p.name == LIVE_UPDATE_PARAM)
            .unwrap_or_else(|| panic!("{} declares no `{LIVE_UPDATE_PARAM}`", i.name));
        assert_eq!(p.boot_param, LIVE_UPDATE_BOOT, "{}", i.name);
        assert!(
            !p.required,
            "{}: absent = on, never a required word",
            i.name
        );
        assert!(
            !i.boot_params
                .iter()
                .any(|b| b.starts_with("korp.live_update")),
            "{}: the switch is never baked: {:?}",
            i.name,
            i.boot_params
        );
    }
    assert_eq!(
        (LIVE_UPDATE_PARAM, LIVE_UPDATE_BOOT),
        ("live_app", "korp.live_update")
    );
}

#[test]
fn live_app_off_puts_korp_live_update_off_on_the_cmdline() {
    let set = declared();
    for i in &set.installers {
        // Every required parameter supplied, so only the switch is under test.
        let mut supplied: BTreeMap<String, String> = i
            .params
            .iter()
            .filter(|p| p.required)
            .map(|p| (p.name.clone(), "x".to_string()))
            .collect();
        supplied.insert(LIVE_UPDATE_PARAM.into(), "off".into());
        let off =
            apply_params(&i.params, &supplied).unwrap_or_else(|e| panic!("{}: {e:#}", i.name));
        assert!(
            off.boot_params.iter().any(|t| t == "korp.live_update=off"),
            "{}: {:?}",
            i.name,
            off.boot_params
        );
        supplied.remove(LIVE_UPDATE_PARAM);
        let absent = apply_params(&i.params, &supplied).unwrap();
        assert!(
            !absent
                .boot_params
                .iter()
                .any(|t| t.starts_with("korp.live_update")),
            "{}: absent bakes nothing",
            i.name
        );
    }
}