asterust-junos 0.5.14

Typed Juniper JunOS config views (interfaces, protocols, routing instances and options, policy options, firewall filters, class of service, system, services) extracted from an asterust config tree.
Documentation
//! `tracing`
//! `system { tracing { destination-override { syslog host <address>; } } }`.
//!
//! # See also
//!
//! - [tracing](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/tracing-edit-system.html)
//! - [destination-override](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/destination-override-edit-system.html)

use crate::{statement_words, value_after};
use asterust::config::ConfigLine;

/// The `system tracing` options.
#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub struct Tracing {
    /// The host that remote tracing output is sent to, from `destination-override syslog host`.
    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;

    // Not from documentation: written from the CLI Reference syntax pages. See the README "Sources".
    #[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());
    }
}