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

nordisk/edda

crates/estate-clock/tests/env_alias.rs

//! **GUNNAR_CLOCK* read as ESTATE_CLOCK*** in the real process environment
//! (lane G3b): a Gunnar medium baked with `korp.env.GUNNAR_CLOCK=` and
//! `korp.env.GUNNAR_CLOCK_KEY=` keeps its clock on estate-clock. Its own test
//! binary, ONE test: it sets the process environment, which no other test sees.

use std::collections::BTreeMap;

use estate_clock::config::{Config, Role, Source};

const KEY: &str = "AAAAC3NzaC1lZDI1NTE5AAAAIG6bqWQf0Qb2cKq5qfV2F2mA0w9o5nXx8m1kq3m0Zb3F";

#[test]
fn a_gunnar_medium_keeps_its_clock_on_estate_clock() {
    std::env::remove_var("ESTATE_CLOCK");
    std::env::remove_var("ESTATE_CLOCK_KEY");
    std::env::set_var("GUNNAR_CLOCK", "peer://10.13.8.99:50123");
    std::env::set_var("GUNNAR_CLOCK_KEY", KEY);
    let want = Config::Sources { sources: vec![Source::Peer("10.13.8.99:50123".parse().unwrap())], peer_key: Some(format!("ssh-ed25519 {KEY}")) };
    assert_eq!(Config::from_env(Role::Appliance), Ok(want.clone()), "the box's own read");
    assert_eq!(estate_clock::offer::box_config(&BTreeMap::new()), Ok(want), "the box's read with its feed");

    // A front told by Gunnar's name that chrony keeps its clock.
    std::env::set_var("GUNNAR_CLOCK_TRUST_SYSTEM", "1");
    assert_eq!(estate_clock::config::var(estate_clock::offer::TRUST_SYSTEM_ENV).as_deref(), Some("1"));

    // The estate name, once set, wins.
    std::env::set_var("ESTATE_CLOCK", "off");
    assert_eq!(Config::from_env(Role::Appliance), Ok(Config::Off));
}