summaryrefslogtreecommitdiffstats
path: root/third_party/rust/tokio/tests/net_lookup_host.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
commit43a97878ce14b72f0981164f87f2e35e14151312 (patch)
tree620249daf56c0258faa40cbdcf9cfba06de2a846 /third_party/rust/tokio/tests/net_lookup_host.rs
parentInitial commit. (diff)
downloadfirefox-43a97878ce14b72f0981164f87f2e35e14151312.tar.xz
firefox-43a97878ce14b72f0981164f87f2e35e14151312.zip
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/tokio/tests/net_lookup_host.rs')
-rw-r--r--third_party/rust/tokio/tests/net_lookup_host.rs38
1 files changed, 38 insertions, 0 deletions
diff --git a/third_party/rust/tokio/tests/net_lookup_host.rs b/third_party/rust/tokio/tests/net_lookup_host.rs
new file mode 100644
index 0000000000..44c8e19e0d
--- /dev/null
+++ b/third_party/rust/tokio/tests/net_lookup_host.rs
@@ -0,0 +1,38 @@
+#![cfg(feature = "full")]
+
+use tokio::net;
+use tokio_test::assert_ok;
+
+use std::io;
+use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr};
+
+#[tokio::test]
+async fn lookup_socket_addr() {
+ let addr: SocketAddr = "127.0.0.1:8000".parse().unwrap();
+
+ let actual = assert_ok!(net::lookup_host(addr).await).collect::<Vec<_>>();
+ assert_eq!(vec![addr], actual);
+}
+
+#[tokio::test]
+async fn lookup_str_socket_addr() {
+ let addr: SocketAddr = "127.0.0.1:8000".parse().unwrap();
+
+ let actual = assert_ok!(net::lookup_host("127.0.0.1:8000").await).collect::<Vec<_>>();
+ assert_eq!(vec![addr], actual);
+}
+
+#[tokio::test]
+async fn resolve_dns() -> io::Result<()> {
+ let mut hosts = net::lookup_host("localhost:3000").await?;
+ let host = hosts.next().unwrap();
+
+ let expected = if host.is_ipv4() {
+ SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 3000)
+ } else {
+ SocketAddr::new(IpAddr::V6(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1)), 3000)
+ };
+ assert_eq!(host, expected);
+
+ Ok(())
+}