Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions lading/src/generator/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
}
53 changes: 53 additions & 0 deletions lading/src/generator/file_gen/logrotate_fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Loading