use crate::{statement_words, value_after};
use asterust::config::ConfigLine;
#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub struct Tracing {
pub destination_override_syslog_host: Option<String>,
}
pub(super) fn parse_tracing(tracing: &ConfigLine) -> Tracing {
Tracing {
destination_override_syslog_host: statement_words(tracing, "destination-override")
.and_then(|words| value_after(&words, "host")),
}
}
#[cfg(test)]
mod tests {
use crate::system::system;
use asterust::config::juniper;
#[test]
fn extracts_the_destination_override_in_block_form() {
let tracing = system(&juniper::parse_braces(
"system {\n tracing {\n destination-override {\n syslog host 192.0.2.9;\n }\n }\n}\n",
))
.unwrap()
.tracing
.unwrap();
assert_eq!(tracing.destination_override_syslog_host.as_deref(), Some("192.0.2.9"));
}
#[test]
fn extracts_the_destination_override_in_line_form() {
let tracing = system(&juniper::parse_braces(
"system {\n tracing {\n destination-override syslog host 192.0.2.9;\n }\n}\n",
))
.unwrap()
.tracing
.unwrap();
assert_eq!(tracing.destination_override_syslog_host.as_deref(), Some("192.0.2.9"));
}
#[test]
fn no_tracing_is_none() {
let system = system(&juniper::parse_braces("system {\n host-name pe1;\n}\n")).unwrap();
assert!(system.tracing.is_none());
}
}