#![cfg(test)]
use wakezilla::scanner::{scan_network_with_interface, DiscoveredDevice};
#[test]
fn discovered_device_serialize() {
let device = DiscoveredDevice {
ip: "192.168.1.1".to_string(),
mac: "AA:BB:CC:DD:EE:FF".to_string(),
hostname: Some("example.com".to_string()),
};
let json = serde_json::to_string(&device).unwrap();
assert!(json.contains("\"ip\":\"192.168.1.1\""));
}
#[tokio::test]
async fn test_scan_network_basic() {
let result = scan_network_with_interface(None).await;
match &result {
Ok(devices) => println!("Unexpectedly succeeded: found {} devices", devices.len()),
Err(e) => println!("Expected failure: {}", e),
}
assert!(result.is_ok() || result.is_err());
}
#[tokio::test]
async fn hostname_lookup_integration() {
let devices = vec![DiscoveredDevice {
ip: "127.0.0.1".to_string(), mac: "00:00:00:00:00:00".to_string(),
hostname: None,
}];
let lookups = devices.into_iter().map(|mut device| {
tokio::spawn(async move {
if let Ok(ip_addr) = device.ip.parse::<std::net::IpAddr>() {
device.hostname = dns_lookup::lookup_addr(&ip_addr).ok();
}
device
})
});
let results = futures_util::future::join_all(lookups)
.await
.into_iter()
.filter_map(|r| r.ok())
.collect::<Vec<_>>();
assert!(!results.is_empty());
let device = &results[0];
assert_eq!(device.ip, "127.0.0.1");
}