Skip to content

Commit cf2d888

Browse files
committed
config tests
1 parent 891a604 commit cf2d888

File tree

2 files changed

+113
-0
lines changed

2 files changed

+113
-0
lines changed

lading/src/generator/common.rs

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,4 +296,64 @@ mod tests {
296296
let pooled = ConcurrencyStrategy::new(None, false);
297297
assert_eq!(pooled.connection_count(), 1);
298298
}
299+
300+
mod throttle_config_parsing {
301+
use crate::generator::common::BytesThrottleConfig;
302+
use serde_yaml::with::singleton_map_recursive;
303+
304+
/// Helper to deserialize ThrottleConfig using singleton_map_recursive
305+
/// (matches how the main config deserializes it)
306+
fn parse_throttle_config(yaml: &str) -> BytesThrottleConfig {
307+
let value: serde_yaml::Value = serde_yaml::from_str(yaml).unwrap();
308+
singleton_map_recursive::deserialize(value).unwrap()
309+
}
310+
311+
#[test]
312+
fn parse_all_out() {
313+
let yaml = r#"all_out"#;
314+
let config = parse_throttle_config(yaml);
315+
assert!(matches!(config, BytesThrottleConfig::AllOut));
316+
}
317+
318+
#[test]
319+
fn parse_stable_bytes_per_second() {
320+
let yaml = r#"
321+
stable:
322+
bytes_per_second: "10 MiB"
323+
timeout_millis: 100
324+
"#;
325+
let config = parse_throttle_config(yaml);
326+
assert!(matches!(config, BytesThrottleConfig::Stable { .. }));
327+
if let BytesThrottleConfig::Stable {
328+
bytes_per_second,
329+
timeout_millis,
330+
} = config
331+
{
332+
assert_eq!(timeout_millis, 100);
333+
assert_eq!(bytes_per_second.as_u64(), 10 * 1024 * 1024);
334+
}
335+
}
336+
337+
#[test]
338+
fn parse_linear_bytes_per_second() {
339+
let yaml = r#"
340+
linear:
341+
initial_bytes_per_second: "10 MiB"
342+
maximum_bytes_per_second: "100 MiB"
343+
rate_of_change: "1 MiB"
344+
"#;
345+
let config = parse_throttle_config(yaml);
346+
assert!(matches!(config, BytesThrottleConfig::Linear { .. }));
347+
if let BytesThrottleConfig::Linear {
348+
initial_bytes_per_second,
349+
maximum_bytes_per_second,
350+
rate_of_change,
351+
} = config
352+
{
353+
assert_eq!(initial_bytes_per_second.as_u64(), 10 * 1024 * 1024);
354+
assert_eq!(maximum_bytes_per_second.as_u64(), 100 * 1024 * 1024);
355+
assert_eq!(rate_of_change.as_u64(), 1 * 1024 * 1024);
356+
}
357+
}
358+
}
299359
}

lading/src/generator/file_gen/logrotate_fs.rs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,3 +477,56 @@ impl Filesystem for LogrotateFS {
477477
}
478478
}
479479
}
480+
481+
#[cfg(test)]
482+
mod tests {
483+
use super::LoadProfile;
484+
use serde::Deserialize;
485+
use serde_yaml::with::singleton_map_recursive;
486+
487+
#[derive(Debug, Deserialize)]
488+
#[serde(deny_unknown_fields)]
489+
struct Wrapper {
490+
load_profile: LoadProfile,
491+
}
492+
/// Helper to deserialize Wrapper using singleton_map_recursive
493+
/// (matches how the main config deserializes nested enums)
494+
fn parse_wrapper(yaml: &str) -> Wrapper {
495+
let value: serde_yaml::Value = serde_yaml::from_str(yaml).unwrap();
496+
singleton_map_recursive::deserialize(value).unwrap()
497+
}
498+
499+
#[test]
500+
fn load_profile_constant_bytes() {
501+
let yaml = r#"
502+
load_profile:
503+
constant: "5 MiB"
504+
"#;
505+
let w = parse_wrapper(yaml);
506+
assert!(matches!(w.load_profile, LoadProfile::Constant(..)));
507+
if let LoadProfile::Constant(bytes) = w.load_profile {
508+
assert_eq!(bytes.as_u64(), 5 * 1024 * 1024);
509+
}
510+
}
511+
512+
#[test]
513+
fn load_profile_linear_bytes_per_second() {
514+
let yaml = r#"
515+
load_profile:
516+
linear:
517+
initial_bytes_per_second: "10 MiB"
518+
rate: "1 MiB"
519+
"#;
520+
521+
let w = parse_wrapper(yaml);
522+
assert!(matches!(w.load_profile, LoadProfile::Linear { .. }));
523+
if let LoadProfile::Linear {
524+
initial_bytes_per_second,
525+
rate,
526+
} = w.load_profile
527+
{
528+
assert_eq!(initial_bytes_per_second.as_u64(), 10 * 1024 * 1024);
529+
assert_eq!(rate.as_u64(), 1 * 1024 * 1024);
530+
}
531+
}
532+
}

0 commit comments

Comments
 (0)