From 019f201dbfddb31344e94a9ac914c39e13d71fc7 Mon Sep 17 00:00:00 2001 From: Jeongkyu Shin Date: Mon, 3 Aug 2026 20:01:47 +0900 Subject: [PATCH] fix: repair merged host-port integration Restore the &[SocketAddr] host_port implementation that was auto-merged into the test module when PR #260 and PR #258 landed together. Keep the first-address hostname tests from #243 and the host-port parsing tests from #257 in one valid test module so both behaviors remain covered. Validation: cargo fmt --check; CARGO_TARGET_DIR=/home/inureyes/Development/backend.ai/bssh/target cargo test --lib to_socket_addrs_with_hostname; CARGO_TARGET_DIR=/home/inureyes/Development/backend.ai/bssh/target cargo check --lib --tests; CARGO_TARGET_DIR=/home/inureyes/Development/backend.ai/bssh/target cargo clippy --lib --tests -- -D warnings. --- .../to_socket_addrs_with_hostname.rs | 40 +++++++++---------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/src/ssh/tokio_client/to_socket_addrs_with_hostname.rs b/src/ssh/tokio_client/to_socket_addrs_with_hostname.rs index c0b9a72c..b86f559b 100644 --- a/src/ssh/tokio_client/to_socket_addrs_with_hostname.rs +++ b/src/ssh/tokio_client/to_socket_addrs_with_hostname.rs @@ -139,29 +139,7 @@ impl ToSocketAddrsWithHostname for &[SocketAddr] { .map(|addr| addr.ip().to_string()) .unwrap_or_default() } -} - -#[cfg(test)] -mod tests { - use super::ToSocketAddrsWithHostname; - use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr}; - - #[test] - fn socket_addr_slice_hostname_uses_first_address_only() { - let addrs = [ - SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 22), - SocketAddr::new(IpAddr::V6(Ipv6Addr::LOCALHOST), 22), - ]; - - assert_eq!(addrs.as_slice().hostname(), "127.0.0.1"); - } - #[test] - fn empty_socket_addr_slice_hostname_is_empty() { - let addrs: [SocketAddr; 0] = []; - - assert_eq!(addrs.as_slice().hostname(), ""); - } fn host_port(&self) -> io::Result<(String, u16)> { self.first() .map(|addr| (addr.ip().to_string(), addr.port())) @@ -200,6 +178,24 @@ fn parse_host_port(target: &str) -> io::Result<(String, u16)> { #[cfg(test)] mod tests { use super::{ToSocketAddrsWithHostname, parse_host_port}; + use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr}; + + #[test] + fn socket_addr_slice_hostname_uses_first_address_only() { + let addrs = [ + SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 22), + SocketAddr::new(IpAddr::V6(Ipv6Addr::LOCALHOST), 22), + ]; + + assert_eq!(addrs.as_slice().hostname(), "127.0.0.1"); + } + + #[test] + fn empty_socket_addr_slice_hostname_is_empty() { + let addrs: [SocketAddr; 0] = []; + + assert_eq!(addrs.as_slice().hostname(), ""); + } #[test] fn host_port_parses_domain_without_resolution() {