#[cfg(test)]
mod config_tests {
use ntp_timer::Config;
#[test]
fn test_default_config_values() {
let config = Config::default();
assert_eq!(config.sync_interval_secs, 600);
assert_eq!(config.clock_jump_threshold_secs, 5);
assert_eq!(config.max_retries, 3);
assert_eq!(config.socket_timeout_secs, 5);
}
#[test]
fn test_builder_chain() {
let config = Config::default()
.with_sync_interval(300)
.with_jump_threshold(3)
.with_max_retries(5);
assert_eq!(config.sync_interval_secs, 300);
assert_eq!(config.clock_jump_threshold_secs, 3);
assert_eq!(config.max_retries, 5);
}
#[test]
fn test_ntp_servers_configuration() {
let config = Config::default();
assert!(!config.ntp_servers.is_empty(), "应该至少有一个 NTP 服务器");
println!("配置的 NTP 服务器: {:?}", config.ntp_servers);
}
#[test]
fn test_config_validation() {
let config = Config::default()
.with_sync_interval(10)
.with_jump_threshold(1)
.with_max_retries(1);
assert!(config.validate().is_ok(), "有效的配置应该验证成功");
}
#[test]
fn test_config_cloning() {
let config1 = Config::default().with_sync_interval(300);
let config2 = config1.clone();
assert_eq!(config1.sync_interval_secs, config2.sync_interval_secs);
}
}