Skip to content

Commit 1ca1a45

Browse files
committed
Add localhost parse test
1 parent a90b796 commit 1ca1a45

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

src/utils.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1267,15 +1267,17 @@ mod util_tests {
12671267
use std::net::Ipv4Addr;
12681268

12691269
#[tokio::test]
1270-
/// Tests whether URL strings can be parsed successfully.
1271-
/// Testing DNS resolution is not possible in unit tests due to the lack of static IPs to test against,
1272-
/// so if you have any, please add them here
1270+
/// Tests whether URL strings can be parsed successfully
12731271
async fn test_create_socket_addr() {
12741272
let ip_raw = "0.0.0.0".to_string();
12751273
let ip_with_port = "0.0.0.0:12300".to_string();
1274+
let domain = "http://localhost".to_string();
1275+
let domain_with_port = "http://localhost:12300".to_string();
12761276

12771277
let ip_addr = create_socket_addr(&ip_raw).await.unwrap();
12781278
let ip_with_port_addr = create_socket_addr(&ip_with_port).await.unwrap();
1279+
let domain_addr = create_socket_addr(&domain).await.unwrap();
1280+
let domain_with_port_addr = create_socket_addr(&domain_with_port).await.unwrap();
12791281

12801282
assert_eq!(
12811283
ip_addr,
@@ -1285,5 +1287,15 @@ mod util_tests {
12851287
ip_with_port_addr,
12861288
SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), 12300)
12871289
);
1290+
1291+
assert_eq!(
1292+
domain_addr,
1293+
SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 80)
1294+
);
1295+
1296+
assert_eq!(
1297+
domain_with_port_addr,
1298+
SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 12300)
1299+
);
12881300
}
12891301
}

0 commit comments

Comments
 (0)