use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Debug)]
pub struct CliConfiguration {
pub log: String,
pub site: Option<String>,
pub manta_server_url: String,
pub socks5_proxy: Option<String>,
#[serde(default)]
pub read_only: bool,
#[serde(default)]
pub request_timeout_secs: Option<u64>,
#[serde(default)]
pub power_poll_interval_secs: Option<u64>,
#[serde(default)]
pub power_max_poll_attempts: Option<u32>,
#[serde(default)]
pub sat_file_poll_interval_secs: Option<u64>,
#[serde(default)]
pub sat_file_poll_budget_secs: Option<u64>,
#[serde(default)]
pub sat_file_not_visible_budget_secs: Option<u64>,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn cli_configuration_roundtrip_toml_minimal() {
let cfg = CliConfiguration {
log: "info".to_string(),
site: Some("alps".to_string()),
manta_server_url: "https://manta-server.cscs.ch:8443".to_string(),
socks5_proxy: Some("socks5h://127.0.0.1:1080".to_string()),
read_only: false,
request_timeout_secs: None,
power_poll_interval_secs: None,
power_max_poll_attempts: None,
sat_file_poll_interval_secs: None,
sat_file_poll_budget_secs: None,
sat_file_not_visible_budget_secs: None,
};
let toml_str = toml::to_string(&cfg).unwrap();
let parsed: CliConfiguration = toml::from_str(&toml_str).unwrap();
assert_eq!(parsed.site.as_deref(), Some("alps"));
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_site_optional() {
let toml_str = r#"
log = "info"
manta_server_url = "https://manta-server.cscs.ch:8443"
"#;
let parsed: CliConfiguration = toml::from_str(toml_str).unwrap();
assert!(parsed.site.is_none());
}
#[test]
fn cli_configuration_socks5_proxy_optional() {
let toml_str = r#"
log = "info"
site = "alps"
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"
# missing manta_server_url
"#;
let result = toml::from_str::<CliConfiguration>(bad_toml);
assert!(result.is_err());
}
#[test]
fn read_only_defaults_to_false_when_absent() {
let toml_str = r#"
log = "info"
site = "alps"
manta_server_url = "https://manta-server.cscs.ch:8443"
"#;
let cfg: CliConfiguration = toml::from_str(toml_str).unwrap();
assert!(!cfg.read_only);
}
#[test]
fn read_only_parses_true_when_present() {
let toml_str = r#"
log = "info"
site = "alps"
manta_server_url = "https://manta-server.cscs.ch:8443"
read_only = true
"#;
let cfg: CliConfiguration = toml::from_str(toml_str).unwrap();
assert!(cfg.read_only);
}
#[test]
fn read_only_parses_false_when_explicitly_false() {
let toml_str = r#"
log = "info"
site = "alps"
manta_server_url = "https://manta-server.cscs.ch:8443"
read_only = false
"#;
let cfg: CliConfiguration = toml::from_str(toml_str).unwrap();
assert!(!cfg.read_only);
}
}