use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Debug)]
pub struct CliConfiguration {
pub log: String,
pub site: String,
pub parent_hsm_group: String,
pub manta_server_url: String,
pub socks5_proxy: Option<String>,
#[serde(default)]
pub request_timeout_secs: Option<u64>,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn cli_configuration_roundtrip_toml_minimal() {
let cfg = CliConfiguration {
log: "info".to_string(),
site: "alps".to_string(),
parent_hsm_group: "nodes_free".to_string(),
manta_server_url: "https://manta-server.cscs.ch:8443".to_string(),
socks5_proxy: Some("socks5h://127.0.0.1:1080".to_string()),
request_timeout_secs: None,
};
let toml_str = toml::to_string(&cfg).unwrap();
let parsed: CliConfiguration = toml::from_str(&toml_str).unwrap();
assert_eq!(parsed.site, "alps");
assert_eq!(parsed.parent_hsm_group, "nodes_free");
assert_eq!(parsed.manta_server_url, "https://manta-server.cscs.ch:8443");
assert_eq!(
parsed.socks5_proxy.as_deref(),
Some("socks5h://127.0.0.1:1080")
);
}
#[test]
fn cli_configuration_socks5_proxy_optional() {
let toml_str = r#"
log = "info"
site = "alps"
parent_hsm_group = ""
manta_server_url = "https://manta-server.cscs.ch:8443"
"#;
let parsed: CliConfiguration = toml::from_str(toml_str).unwrap();
assert!(parsed.socks5_proxy.is_none());
}
#[test]
fn cli_configuration_missing_manta_server_url_fails() {
let bad_toml = r#"
log = "info"
site = "alps"
parent_hsm_group = ""
# missing manta_server_url
"#;
let result = toml::from_str::<CliConfiguration>(bad_toml);
assert!(result.is_err());
}
}