diff --git a/lading/src/generator/common.rs b/lading/src/generator/common.rs index eeee3d86c..95829e729 100644 --- a/lading/src/generator/common.rs +++ b/lading/src/generator/common.rs @@ -296,4 +296,64 @@ mod tests { let pooled = ConcurrencyStrategy::new(None, false); assert_eq!(pooled.connection_count(), 1); } + + mod throttle_config_parsing { + use crate::generator::common::BytesThrottleConfig; + use serde_yaml::with::singleton_map_recursive; + + /// Helper to deserialize ThrottleConfig using singleton_map_recursive + /// (matches how the main config deserializes it) + fn parse_throttle_config(yaml: &str) -> BytesThrottleConfig { + let value: serde_yaml::Value = serde_yaml::from_str(yaml).unwrap(); + singleton_map_recursive::deserialize(value).unwrap() + } + + #[test] + fn parse_all_out() { + let yaml = r#"all_out"#; + let config = parse_throttle_config(yaml); + assert!(matches!(config, BytesThrottleConfig::AllOut)); + } + + #[test] + fn parse_stable_bytes_per_second() { + let yaml = r#" + stable: + bytes_per_second: "10 MiB" + timeout_millis: 100 + "#; + let config = parse_throttle_config(yaml); + assert!(matches!(config, BytesThrottleConfig::Stable { .. })); + if let BytesThrottleConfig::Stable { + bytes_per_second, + timeout_millis, + } = config + { + assert_eq!(timeout_millis, 100); + assert_eq!(bytes_per_second.as_u64(), 10 * 1024 * 1024); + } + } + + #[test] + fn parse_linear_bytes_per_second() { + let yaml = r#" + linear: + initial_bytes_per_second: "10 MiB" + maximum_bytes_per_second: "100 MiB" + rate_of_change: "1 MiB" + "#; + let config = parse_throttle_config(yaml); + assert!(matches!(config, BytesThrottleConfig::Linear { .. })); + if let BytesThrottleConfig::Linear { + initial_bytes_per_second, + maximum_bytes_per_second, + rate_of_change, + } = config + { + assert_eq!(initial_bytes_per_second.as_u64(), 10 * 1024 * 1024); + assert_eq!(maximum_bytes_per_second.as_u64(), 100 * 1024 * 1024); + assert_eq!(rate_of_change.as_u64(), 1 * 1024 * 1024); + } + } + } } diff --git a/lading/src/generator/file_gen/logrotate_fs.rs b/lading/src/generator/file_gen/logrotate_fs.rs index c07d58ffc..a885ecd93 100644 --- a/lading/src/generator/file_gen/logrotate_fs.rs +++ b/lading/src/generator/file_gen/logrotate_fs.rs @@ -477,3 +477,56 @@ impl Filesystem for LogrotateFS { } } } + +#[cfg(test)] +mod tests { + use super::LoadProfile; + use serde::Deserialize; + use serde_yaml::with::singleton_map_recursive; + + #[derive(Debug, Deserialize)] + #[serde(deny_unknown_fields)] + struct Wrapper { + load_profile: LoadProfile, + } + /// Helper to deserialize Wrapper using singleton_map_recursive + /// (matches how the main config deserializes nested enums) + fn parse_wrapper(yaml: &str) -> Wrapper { + let value: serde_yaml::Value = serde_yaml::from_str(yaml).unwrap(); + singleton_map_recursive::deserialize(value).unwrap() + } + + #[test] + fn load_profile_constant_bytes() { + let yaml = r#" + load_profile: + constant: "5 MiB" + "#; + let w = parse_wrapper(yaml); + assert!(matches!(w.load_profile, LoadProfile::Constant(..))); + if let LoadProfile::Constant(bytes) = w.load_profile { + assert_eq!(bytes.as_u64(), 5 * 1024 * 1024); + } + } + + #[test] + fn load_profile_linear_bytes_per_second() { + let yaml = r#" + load_profile: + linear: + initial_bytes_per_second: "10 MiB" + rate: "1 MiB" + "#; + + let w = parse_wrapper(yaml); + assert!(matches!(w.load_profile, LoadProfile::Linear { .. })); + if let LoadProfile::Linear { + initial_bytes_per_second, + rate, + } = w.load_profile + { + assert_eq!(initial_bytes_per_second.as_u64(), 10 * 1024 * 1024); + assert_eq!(rate.as_u64(), 1 * 1024 * 1024); + } + } +}