Skip to main content

asterust_junos/system/
pixel_tracing.rs

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