use super::super::types::ServicesConfig;
#[test]
fn self_stream_bounds_default_and_override() -> Result<(), Box<dyn std::error::Error>> {
let defaults: ServicesConfig = toml::from_str("")?;
assert_eq!(defaults.self_streams.cost_rows, 10_000);
assert_eq!(defaults.self_streams.events_rows, 100_000);
let configured: ServicesConfig =
toml::from_str("[self_streams]\ncost_rows = 3\nevents_rows = 5\n")?;
assert_eq!(configured.self_streams.cost_rows, 3);
assert_eq!(configured.self_streams.events_rows, 5);
configured.profile()?;
Ok(())
}
#[test]
fn self_stream_bounds_validate_without_participant_and_independently_of_profile()
-> Result<(), Box<dyn std::error::Error>> {
let mut config: super::ServerConfig = toml::from_str(
"listen_address = '127.0.0.1:8080'\nhealth_listen_address = '127.0.0.1:8081'\ndrain_timeout_ms = 0\nchannels = []\nrouting_rules = []\n[services.self_streams]\ncost_rows = 0\nevents_rows = 0\n",
)?;
assert!(config.participant.is_none());
assert_eq!(
config.services.profile()?,
crate::config::ServiceProfile::Full
);
let error = super::validate(&mut config, None)
.err()
.ok_or("disabled self streams accepted invalid bounds")?;
let message = error.to_string();
assert!(message.contains("services.self_streams.cost_rows"));
assert!(message.contains("services.self_streams.events_rows"));
config.services.profile = "invalid".to_owned();
let error = super::validate(&mut config, None)
.err()
.ok_or("invalid profile and bounds were accepted")?;
let message = error.to_string();
assert!(message.contains("services.profile"));
assert!(message.contains("services.self_streams.cost_rows"));
assert!(message.contains("services.self_streams.events_rows"));
Ok(())
}
#[test]
fn zero_self_stream_bounds_are_named() -> Result<(), Box<dyn std::error::Error>> {
let configured: ServicesConfig =
toml::from_str("[self_streams]\ncost_rows = 0\nevents_rows = 0\n")?;
let Err(error) = configured.self_streams.validate() else {
return Err("zero row bounds must be refused".into());
};
let message = error.to_string();
assert!(message.contains("services.self_streams.cost_rows"));
assert!(message.contains("services.self_streams.events_rows"));
Ok(())
}