#![expect(
clippy::unwrap_used,
reason = "fixtures unwrap known-valid text; a panic is the intended failure signal"
)]
use std::collections::BTreeMap;
use crate::error::Result;
use crate::ports::Host;
use crate::types::{EnvName, EnvValue, MachineFolders, Platform};
#[derive(Debug, Clone)]
pub(crate) struct TwoMachines {
values: BTreeMap<EnvName, EnvValue>,
}
impl TwoMachines {
pub(crate) fn first() -> Self {
Self::of(&[
("HOME", "/home/alice"),
("PATH", "/usr/bin"),
("RUSTFLAGS", "-Cdebuginfo=0"),
])
}
pub(crate) fn second() -> Self {
Self::of(&[
("HOME", "/Users/bob"),
("PATH", "/opt/bin:/usr/bin"),
("RUSTFLAGS", "-Cdebuginfo=0"),
])
}
pub(crate) fn with(mut self, name: &str, value: &str) -> Self {
self.values.insert(
EnvName::parse(name).unwrap(),
EnvValue::parse(value).unwrap(),
);
self
}
pub(crate) fn without(mut self, name: &str) -> Self {
self.values.remove(&EnvName::parse(name).unwrap());
self
}
fn of(pairs: &[(&str, &str)]) -> Self {
let machine = Self {
values: BTreeMap::new(),
};
pairs
.iter()
.fold(machine, |machine, (name, value)| machine.with(name, value))
}
}
impl Host for TwoMachines {
fn platform(&self) -> Platform {
Platform::parse("linux/x86_64").unwrap()
}
fn env(&self, name: &EnvName) -> Result<Option<EnvValue>> {
Ok(self.values.get(name).cloned())
}
fn machine_folders(&self) -> MachineFolders {
MachineFolders::default()
}
}