asterust_junos/interfaces/
hold_time.rs1use crate::{statement_words, value_after};
9use asterust::config::ConfigLine;
10
11#[derive(Clone, Debug, PartialEq, Eq)]
13#[non_exhaustive]
14pub struct HoldTime {
15 pub up: Option<String>,
16 pub down: Option<String>,
17}
18
19pub(super) fn parse_hold_time(interface: &ConfigLine) -> Option<HoldTime> {
21 let words = statement_words(interface, "hold-time")?;
22 Some(HoldTime {
23 up: value_after(&words, "up"),
24 down: value_after(&words, "down"),
25 })
26}
27
28#[cfg(test)]
29mod tests {
30 use crate::interfaces::interfaces;
31 use asterust::config::juniper;
32
33 #[test]
35 fn extracts_hold_time_on_one_line() {
36 let interfaces = interfaces(&juniper::parse_braces(
37 "interfaces {\n xe-0/0/0 {\n hold-time up 5000 down 100;\n }\n}\n",
38 ));
39 let hold_time = interfaces[0].hold_time.as_ref().unwrap();
40 assert_eq!(hold_time.up.as_deref(), Some("5000"));
41 assert_eq!(hold_time.down.as_deref(), Some("100"));
42 }
43
44 #[test]
45 fn extracts_hold_time_block() {
46 let interfaces = interfaces(&juniper::parse_braces(
47 "interfaces {\n xe-0/0/0 {\n hold-time {\n up 2000;\n }\n }\n}\n",
48 ));
49 let hold_time = interfaces[0].hold_time.as_ref().unwrap();
50 assert_eq!(hold_time.up.as_deref(), Some("2000"));
51 assert_eq!(hold_time.down, None);
52 }
53
54 #[test]
55 fn hold_time_is_optional() {
56 let interfaces = interfaces(&juniper::parse_braces(
57 "interfaces {\n xe-0/0/0 {\n disable;\n }\n}\n",
58 ));
59 assert!(interfaces[0].hold_time.is_none());
60 }
61}