use super::Config;
use crate::errors::ProxyError;
pub const DEFAULT_CONFIG: &str = include_str!("default.yaml");
pub fn load_config(explicit_path: Option<&str>) -> Result<Config, ProxyError> {
Config::load(explicit_path, DEFAULT_CONFIG)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn default_config_parses_successfully() {
let config = Config::from_yaml(DEFAULT_CONFIG).expect("DEFAULT_CONFIG should parse");
assert!(
!config.listeners.is_empty(),
"default config should define at least one listener"
);
}
#[test]
fn load_config_nonexistent_explicit_path_returns_error() {
let result = Config::load(Some("/nonexistent/path/praxis.yaml"), DEFAULT_CONFIG);
assert!(
result.is_err(),
"loading a nonexistent explicit path should return an error"
);
}
#[test]
fn load_config_none_with_valid_fallback_succeeds() {
let config = Config::load(None, DEFAULT_CONFIG).expect("fallback YAML should parse successfully");
assert!(
!config.listeners.is_empty(),
"fallback config should define at least one listener"
);
assert_eq!(
config.listeners[0].name, "default",
"fallback config listener name should be 'default'"
);
}
}