use std::time::Duration;
#[derive(Debug, Clone)]
pub struct SimulationConfig {
pub max_registrations_per_key: usize,
pub default_ttl: Duration,
pub verify_attestations: bool,
pub simulated_delay: Option<Duration>,
pub auto_expire: bool,
}
impl Default for SimulationConfig {
fn default() -> Self {
Self {
max_registrations_per_key: 1000,
default_ttl: Duration::from_secs(3600),
verify_attestations: false,
simulated_delay: None,
auto_expire: true,
}
}
}
impl SimulationConfig {
#[must_use]
pub fn new() -> Self {
Self::default()
}
#[must_use]
pub const fn with_max_registrations_per_key(mut self, max: usize) -> Self {
self.max_registrations_per_key = max;
self
}
#[must_use]
pub const fn with_default_ttl(mut self, ttl: Duration) -> Self {
self.default_ttl = ttl;
self
}
#[must_use]
pub const fn with_verify_attestations(mut self, verify: bool) -> Self {
self.verify_attestations = verify;
self
}
#[must_use]
pub const fn with_simulated_delay(mut self, delay: Duration) -> Self {
self.simulated_delay = Some(delay);
self
}
#[must_use]
pub const fn with_auto_expire(mut self, auto_expire: bool) -> Self {
self.auto_expire = auto_expire;
self
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn default_config() {
let config = SimulationConfig::default();
assert_eq!(config.max_registrations_per_key, 1000);
assert_eq!(config.default_ttl, Duration::from_secs(3600));
assert!(!config.verify_attestations);
assert!(config.simulated_delay.is_none());
assert!(config.auto_expire);
}
#[test]
fn builder_pattern() {
let config = SimulationConfig::new()
.with_max_registrations_per_key(10)
.with_default_ttl(Duration::from_secs(1800))
.with_verify_attestations(true)
.with_simulated_delay(Duration::from_millis(50))
.with_auto_expire(false);
assert_eq!(config.max_registrations_per_key, 10);
assert_eq!(config.default_ttl, Duration::from_secs(1800));
assert!(config.verify_attestations);
assert_eq!(config.simulated_delay, Some(Duration::from_millis(50)));
assert!(!config.auto_expire);
}
}