|
1 |
| -use std::{borrow::Cow, collections::HashMap, future::IntoFuture, net::Ipv6Addr, time::Duration}; |
| 1 | +use std::{ |
| 2 | + borrow::Cow, |
| 3 | + collections::HashMap, |
| 4 | + future::IntoFuture, |
| 5 | + net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr}, |
| 6 | + time::Duration, |
| 7 | +}; |
2 | 8 |
|
3 | 9 | use crate::bson::Document;
|
4 | 10 | use serde::{Deserialize, Serialize};
|
@@ -982,3 +988,34 @@ async fn ipv6_connect() {
|
982 | 988 | .unwrap();
|
983 | 989 | assert_eq!(result.get_f64("ok").unwrap(), 1.0);
|
984 | 990 | }
|
| 991 | + |
| 992 | +#[test] |
| 993 | +fn server_address_from_socket_addr_ipv4() { |
| 994 | + let socket_addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 27017); |
| 995 | + let server_address = ServerAddress::from(socket_addr); |
| 996 | + |
| 997 | + match server_address { |
| 998 | + ServerAddress::Tcp { host, port } => { |
| 999 | + assert_eq!(host, "127.0.0.1", "Host was not correctly converted"); |
| 1000 | + assert_eq!(port, Some(27017), "Port was not correctly converted"); |
| 1001 | + } |
| 1002 | + _ => panic!("ServerAddress should have been Tcp variant"), |
| 1003 | + } |
| 1004 | +} |
| 1005 | + |
| 1006 | +#[test] |
| 1007 | +fn server_address_from_socket_addr_ipv6() { |
| 1008 | + let socket_addr = SocketAddr::new( |
| 1009 | + IpAddr::V6(Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 1)), |
| 1010 | + 27017, |
| 1011 | + ); |
| 1012 | + let server_address = ServerAddress::from(socket_addr); |
| 1013 | + |
| 1014 | + match server_address { |
| 1015 | + ServerAddress::Tcp { host, port } => { |
| 1016 | + assert_eq!(host, "2001:db8::1", "Host was not correctly converted"); |
| 1017 | + assert_eq!(port, Some(27017), "Port was not correctly converted"); |
| 1018 | + } |
| 1019 | + _ => panic!("ServerAddress should have been Tcp variant"), |
| 1020 | + } |
| 1021 | +} |
0 commit comments