Sha256: a1ba4c6100584f3ec706810c9a4313875e8cd0bca13531bc7759d8ecdf0189fa

Contents?: true

Size: 1.08 KB

Versions: 8

Compression:

Stored size: 1.08 KB

Contents

#![cfg(all(feature = "full", not(tokio_wasi)))] // Wasi does not support direct socket operations

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(())
}

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
wasmtime-9.0.1 ./ext/cargo-vendor/tokio-1.28.1/tests/net_lookup_host.rs
wasmtime-8.0.0 ./ext/cargo-vendor/tokio-1.27.0/tests/net_lookup_host.rs
wasmtime-7.0.0 ./ext/cargo-vendor/tokio-1.27.0/tests/net_lookup_host.rs
wasmtime-6.0.1 ./ext/cargo-vendor/tokio-1.25.0/tests/net_lookup_host.rs
wasmtime-6.0.0 ./ext/cargo-vendor/tokio-1.25.0/tests/net_lookup_host.rs
wasmtime-5.0.0 ./ext/cargo-vendor/tokio-1.24.2/tests/net_lookup_host.rs
wasmtime-0.4.1 ./ext/cargo-vendor/tokio-1.23.0/tests/net_lookup_host.rs
wasmtime-0.4.0 ./ext/cargo-vendor/tokio-1.23.0/tests/net_lookup_host.rs