Add unit test for bind interface IP address parsing

Co-authored-by: rustdesk <71636191+rustdesk@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2026-02-05 03:52:03 +00:00
parent 780f99bd32
commit 16dde51e23

View File

@@ -935,3 +935,28 @@ async fn udp_nat_listen(
})?;
Ok(())
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_bind_interface_parsing() {
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
// Test valid IPv4 addresses
assert!("192.168.1.100".parse::<IpAddr>().is_ok());
assert!("10.0.0.1".parse::<IpAddr>().is_ok());
assert!("127.0.0.1".parse::<IpAddr>().is_ok());
// Test valid IPv6 addresses
assert!("::1".parse::<IpAddr>().is_ok());
assert!("fe80::1".parse::<IpAddr>().is_ok());
assert!("2001:db8::1".parse::<IpAddr>().is_ok());
// Test invalid addresses
assert!("invalid".parse::<IpAddr>().is_err());
assert!("999.999.999.999".parse::<IpAddr>().is_err());
assert!("".parse::<IpAddr>().is_err());
}
}