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