Add tests for is_iface_up
@@ -18,3 +18,69 @@ impl KernelInterface {
}
}
}
+
+#[test]
+fn test_is_interface_up() {
+ use KI;
+
+ use std::os::unix::process::ExitStatusExt;
+ use std::process::ExitStatus;
+ use std::process::Output;
+
+ KI.set_mock(Box::new(move |program, args| {
+ assert_eq!(program, "ip");
+ assert_eq!(args, &["addr", "show", "dev", "eth0"]);
+
+ Ok(Output {
+ stdout: b"2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
+ link/ether 74:df:bf:30:37:f3 brd ff:ff:ff:ff:ff:ff
+ inet6 fe80::96:3add:69d9:906a/64 scope link
+ valid_lft forever preferred_lft forever"
+ .to_vec(),
+ stderr: b"".to_vec(),
+ status: ExitStatus::from_raw(0),
+ })
+ }));
+
+ let val = KI.is_iface_up("eth0");
+
+ assert_eq!(Some(true), val);
+
+ KI.set_mock(Box::new(move |program, args| {
+ assert_eq!(program, "ip");
+ assert_eq!(args, &["addr", "show", "dev", "eth0"]);
+
+ Ok(Output {
+ stdout: b"2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state DOWN group default qlen 1000
+ link/ether 74:df:bf:30:37:f3 brd ff:ff:ff:ff:ff:ff
+ inet6 fe80::96:3add:69d9:906a/64 scope link
+ valid_lft forever preferred_lft forever"
+ .to_vec(),
+ stderr: b"".to_vec(),
+ status: ExitStatus::from_raw(0),
+ })
+ }));
+
+ let val = KI.is_iface_up("eth0");
+
+ assert_eq!(Some(false), val);
+
+ KI.set_mock(Box::new(move |program, args| {
+ assert_eq!(program, "ip");
+ assert_eq!(args, &["addr", "show", "dev", "eth0"]);
+
+ Ok(Output {
+ stdout: b"2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state group default qlen 1000
+ link/ether 74:df:bf:30:37:f3 brd ff:ff:ff:ff:ff:ff
+ inet6 fe80::96:3add:69d9:906a/64 scope link
+ valid_lft forever preferred_lft forever"
+ .to_vec(),
+ stderr: b"".to_vec(),
+ status: ExitStatus::from_raw(0),
+ })
+ }));
+
+ let val = KI.is_iface_up("eth0");
+
+ assert_eq!(Some(false), val);
+}
