88 lines
2.8 KiB
Rust
88 lines
2.8 KiB
Rust
use rpki::rtr::config::{AppConfig, RuntimeConfigPatch, RuntimeTimingConfigPatch, parse_timezone};
|
|
|
|
#[test]
|
|
fn parse_timezone_accepts_iana_names_and_common_aliases() {
|
|
assert_eq!(
|
|
parse_timezone("Asia/Shanghai", "TEST").unwrap(),
|
|
chrono_tz::Asia::Shanghai
|
|
);
|
|
assert_eq!(
|
|
parse_timezone("shanghai", "TEST").unwrap(),
|
|
chrono_tz::Asia::Shanghai
|
|
);
|
|
assert_eq!(
|
|
parse_timezone("Europe/London", "TEST").unwrap(),
|
|
chrono_tz::Europe::London
|
|
);
|
|
assert_eq!(
|
|
parse_timezone("America/New_York", "TEST").unwrap(),
|
|
chrono_tz::America::New_York
|
|
);
|
|
assert_eq!(parse_timezone("UTC", "TEST").unwrap(), chrono_tz::UTC);
|
|
assert_eq!(parse_timezone("Z", "TEST").unwrap(), chrono_tz::UTC);
|
|
}
|
|
|
|
#[test]
|
|
fn parse_timezone_rejects_offset_and_invalid_values() {
|
|
assert!(parse_timezone("+08:00", "TEST").is_err());
|
|
assert!(parse_timezone("+0800", "TEST").is_err());
|
|
assert!(parse_timezone("Mars/Base", "TEST").is_err());
|
|
}
|
|
|
|
#[test]
|
|
fn runtime_config_patch_validates_and_preserves_unspecified_values() {
|
|
let current = AppConfig::default().runtime_config();
|
|
let next = current
|
|
.apply_patch(RuntimeConfigPatch {
|
|
max_delta: Some(8),
|
|
prune_delta_by_snapshot_size: Some(true),
|
|
source_refresh_interval_seconds: Some(60),
|
|
runtime_report_interval_seconds: Some(120),
|
|
report_history_limit: Some(20),
|
|
strict_ccr_validation: Some(true),
|
|
timezone: Some("UTC".to_string()),
|
|
timing: Some(RuntimeTimingConfigPatch {
|
|
refresh: Some(1800),
|
|
retry: None,
|
|
expire: Some(7200),
|
|
}),
|
|
})
|
|
.unwrap();
|
|
|
|
assert_eq!(next.max_delta, 8);
|
|
assert!(next.prune_delta_by_snapshot_size);
|
|
assert_eq!(next.source_refresh_interval_seconds, 60);
|
|
assert_eq!(next.runtime_report_interval_seconds, 120);
|
|
assert_eq!(next.report_history_limit, 20);
|
|
assert!(next.strict_ccr_validation);
|
|
assert_eq!(next.timezone, "UTC");
|
|
assert_eq!(next.timing.refresh, 1800);
|
|
assert_eq!(next.timing.retry, current.timing.retry);
|
|
assert_eq!(next.timing.expire, 7200);
|
|
|
|
assert!(
|
|
current
|
|
.apply_patch(RuntimeConfigPatch {
|
|
max_delta: Some(0),
|
|
..RuntimeConfigPatch::default()
|
|
})
|
|
.is_err()
|
|
);
|
|
assert!(
|
|
current
|
|
.apply_patch(RuntimeConfigPatch {
|
|
runtime_report_interval_seconds: Some(0),
|
|
..RuntimeConfigPatch::default()
|
|
})
|
|
.is_err()
|
|
);
|
|
assert!(
|
|
current
|
|
.apply_patch(RuntimeConfigPatch {
|
|
timezone: Some("+08:00".to_string()),
|
|
..RuntimeConfigPatch::default()
|
|
})
|
|
.is_err()
|
|
);
|
|
}
|