use mineral_config_macros::config_section;
use mineral_config::de;
#[config_section]
pub struct CacheConfig {
#[serde(deserialize_with = "de::u64_lossy")]
audio_capacity: u64,
}
#[cfg(test)]
mod tests {
use super::CacheConfig;
#[test]
fn accepts_integer_and_float_bytes() -> color_eyre::Result<()> {
let c: CacheConfig = serde_json::from_value(serde_json::json!({
"audio_capacity": 1024_u64,
}))?;
assert_eq!(*c.audio_capacity(), 1024);
let c: CacheConfig = serde_json::from_value(serde_json::json!({
"audio_capacity": 10737418240.0_f64,
}))?;
assert_eq!(*c.audio_capacity(), 10 * 1024 * 1024 * 1024);
Ok(())
}
#[test]
fn rejects_negative() {
assert!(
serde_json::from_value::<CacheConfig>(serde_json::json!({
"audio_capacity": -1.0_f64,
}))
.is_err(),
"负容量应报错"
);
}
}