Tests that mutate environment variables interfere with one another. Build a
ConfigDiscovery with MapEnv instead. Each test owns its values and can run
in parallel:
use ortho_config::{ConfigDiscovery, MapEnv};
use std::sync::Arc;
fn main() {
let environment = Arc::new(
MapEnv::new()
.with_var("ACME_CONFIG", "/srv/acme/server.toml")
.with_var("HOME", "/home/tester"),
);
let discovery = ConfigDiscovery::builder("acme")
.env_var("ACME_CONFIG")
.env_source(environment)
.clear_project_roots()
.build();
assert_eq!(
discovery.candidates().first().map(|path| path.as_path()),
Some(std::path::Path::new("/srv/acme/server.toml"))
);
println!("candidate=/srv/acme/server.toml");
}
ProcessEnv remains the default, so production applications do not need to
change. EnvSource deliberately supports lookup by name but not enumeration;
discovery cannot accidentally scan or log unrelated environment values.