Skip to main content

asterust_junos/system/
pixel_tracing.rs

1//! `pixel-tracing`
2//! `system { pixel-tracing { ... } }`.
3//!
4//! # See also
5//!
6//! - [pixel-tracing](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/pixel-tracing-edit-system.html)
7
8use crate::arg_of;
9use asterust::config::ConfigLine;
10
11/// The `system pixel-tracing` configuration.
12#[derive(Clone, Debug, PartialEq, Eq)]
13#[non_exhaustive]
14pub struct PixelTracing {
15    /// Maximum number of dump files.
16    pub files: Option<String>,
17    /// `any`, `critical`, `debug`, `info` or `none`.
18    pub level: Option<String>,
19}
20
21pub(super) fn parse_pixel_tracing(tracing: &ConfigLine) -> PixelTracing {
22    PixelTracing {
23        files: arg_of(tracing, "files").map(str::to_string),
24        level: arg_of(tracing, "level").map(str::to_string),
25    }
26}
27
28#[cfg(test)]
29mod tests {
30    use crate::system::system;
31    use asterust::config::juniper;
32
33    // Not from documentation: written from the CLI Reference syntax page. See the README "Sources".
34    #[test]
35    fn extracts_pixel_tracing() {
36        let tracing = system(&juniper::parse_braces(
37            "system {\n    pixel-tracing {\n        files 50;\n        level info;\n    }\n}\n",
38        ))
39        .unwrap()
40        .pixel_tracing
41        .unwrap();
42        assert_eq!(tracing.files.as_deref(), Some("50"));
43        assert_eq!(tracing.level.as_deref(), Some("info"));
44    }
45
46    #[test]
47    fn no_pixel_tracing_is_none() {
48        let system = system(&juniper::parse_braces("system {\n    host-name pe1;\n}\n")).unwrap();
49        assert!(system.pixel_tracing.is_none());
50    }
51}