Skip to content
This repository has been archived by the owner on Nov 15, 2019. It is now read-only.

interface test #11

Merged
merged 9 commits into from
Jan 25, 2016
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -537,12 +537,20 @@ pub fn get_if_addrs() -> io::Result<Vec<Interface>> {
#[cfg(test)]
mod test {
use super::get_if_addrs;
use ip::IpAddr;
use std::net::Ipv4Addr;

#[test]
fn test_get_if_addrs() {
let ifaces = get_if_addrs().unwrap();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be perhaps 2 tests, on for local_addr == 1 and another that compares what the OS believes is ifaddrs with what we believe, i.e. compare parsed output of ipconfig with our output or use /proc filesystem to get the interface addresses

println!("Local interfaces:");
println!("{:#?}", ifaces);
// at least one loop back address
assert!(1 <= ifaces.iter().filter(|interface| interface.is_loopback()).count());
// one address of IpV4(127.0.0.1)
assert!(1 == ifaces.iter().filter(|interface| {
interface.addr.ip() == IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1))
}).count());
}
}