Skip to content

Commit

Permalink
Add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
mmynk committed Nov 6, 2023
1 parent 563f6e1 commit 52879b2
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions below/procfs/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1190,6 +1190,26 @@ fn test_read_net_stat() {
verify_interfaces(&netstat);
}

#[test]
fn test_read_with_errors() {
let netsysfs = TestProcfs::new();
write_net_map(&netsysfs);
let netstat = netsysfs
.get_net_reader()
.read_netstat()
.expect("Fail to get NetStat");
verify_interfaces(&netstat);
assert_eq!(netstat.tcp, None);
assert_eq!(netstat.tcp_ext, None);
assert_eq!(netstat.ip, None);
assert_eq!(netstat.ip_ext, None);
assert_eq!(netstat.ip6, None);
assert_eq!(netstat.icmp, None);
assert_eq!(netstat.icmp6, None);
assert_eq!(netstat.udp, None);
assert_eq!(netstat.udp6, None);
}

fn verify_tcp(netstat: &NetStat) {
let tcp = netstat.tcp.as_ref().expect("Fail to collect tcp stats");
assert_eq!(tcp.active_opens, Some(54_858_563));
Expand Down

0 comments on commit 52879b2

Please sign in to comment.