asterust_junos/system/
configuration.rs1use crate::{child_block, has_leaf};
9use asterust::config::ConfigLine;
10
11#[derive(Clone, Debug, PartialEq, Eq)]
13#[non_exhaustive]
14pub struct ConfigurationInput {
15 pub json_reorder_list_keys: bool,
17}
18
19pub(super) fn parse_configuration(configuration: &ConfigLine) -> ConfigurationInput {
20 let json = child_block(configuration, "input")
21 .and_then(|input| child_block(input, "format"))
22 .and_then(|format| child_block(format, "json"));
23 ConfigurationInput {
24 json_reorder_list_keys: json.is_some_and(|json| has_leaf(json, "reorder-list-keys")),
25 }
26}
27
28#[cfg(test)]
29mod tests {
30 use crate::system::system;
31 use asterust::config::juniper;
32
33 #[test]
35 fn extracts_the_json_input_format() {
36 let configuration = system(&juniper::parse_braces(
37 "system {\n configuration {\n input {\n format {\n json {\n reorder-list-keys;\n }\n }\n }\n }\n}\n",
38 ))
39 .unwrap()
40 .configuration
41 .unwrap();
42 assert!(configuration.json_reorder_list_keys);
43 }
44
45 #[test]
46 fn no_configuration_is_none() {
47 let system = system(&juniper::parse_braces("system {\n host-name pe1;\n}\n")).unwrap();
48 assert!(system.configuration.is_none());
49 }
50}