use crate::{statement_words, value_after};
use asterust::config::ConfigLine;
#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub struct MaximumPaths {
pub path_limit: Option<String>,
pub log_interval: Option<String>,
pub log_only: bool,
pub threshold: Option<String>,
}
pub(super) fn parse_maximum_paths(root: &ConfigLine) -> Option<MaximumPaths> {
let words = statement_words(root, "maximum-paths")?;
Some(MaximumPaths {
path_limit: words.first().map(|word| word.to_string()),
log_interval: value_after(&words, "log-interval"),
log_only: words.contains(&"log-only"),
threshold: value_after(&words, "threshold"),
})
}
#[cfg(test)]
mod tests {
use crate::routing_options::routing_options;
use asterust::config::juniper;
#[test]
fn extracts_limit_threshold_and_interval() {
let options = routing_options(&juniper::parse_braces(
"routing-options {\n maximum-paths 1000 threshold 80 log-interval 60;\n}\n",
))
.unwrap();
let paths = options.maximum_paths.unwrap();
assert_eq!(paths.path_limit.as_deref(), Some("1000"));
assert_eq!(paths.threshold.as_deref(), Some("80"));
assert_eq!(paths.log_interval.as_deref(), Some("60"));
assert!(!paths.log_only);
}
#[test]
fn extracts_log_only() {
let options = routing_options(&juniper::parse_braces(
"routing-options {\n maximum-paths 500 log-only;\n}\n",
))
.unwrap();
let paths = options.maximum_paths.unwrap();
assert_eq!(paths.path_limit.as_deref(), Some("500"));
assert!(paths.log_only);
assert_eq!(paths.threshold, None);
}
#[test]
fn no_maximum_paths_is_none() {
let options = routing_options(&juniper::parse_braces(
"routing-options {\n router-id 192.0.2.1;\n}\n",
))
.unwrap();
assert!(options.maximum_paths.is_none());
}
}