#![cfg(not(target_family = "wasm"))] #![feature(once_cell_try)] use std::matches; static_assertions::assert_impl_all!(xwt_wtransport::Endpoint: xwt_core::endpoint::Connect); static_assertions::assert_impl_all!(xwt_wtransport::Endpoint: xwt_core::endpoint::Accept); static_assertions::assert_impl_all!(xwt_wtransport::Session: xwt_core::base::Session); fn setup() -> color_eyre::eyre::Result<()> { static INIT: std::sync::OnceLock<()> = std::sync::OnceLock::new(); INIT.get_or_try_init::<_, color_eyre::eyre::Error>(|| { tracing_subscriber::fmt::init(); color_eyre::install()?; Ok(()) })?; Ok(()) } fn test_endpoint() -> xwt_wtransport::Endpoint { let mut root_store = wtransport::tls::rustls::RootCertStore::empty(); root_store.add_parsable_certificates( [xwt_test_assets::CERT].map(wtransport::tls::rustls::pki_types::CertificateDer::from_slice), ); let digest = xwt_cert_fingerprint::Sha256::compute_for_der(xwt_test_assets::CERT); tracing::info!("certificate sha256 digest: {digest}"); let mut tls_config = wtransport::tls::rustls::ClientConfig::builder() .with_root_certificates(root_store) .with_no_client_auth(); tls_config.alpn_protocols = vec!["h3".into()]; let endpoint = wtransport::Endpoint::client( wtransport::ClientConfig::builder() .with_bind_address("0.0.0.0:0".parse().unwrap()) .with_custom_tls(tls_config) .build(), ) .unwrap(); xwt_wtransport::Endpoint(endpoint) } #[tokio::test] async fn streams() -> color_eyre::eyre::Result<()> { setup()?; let endpoint = test_endpoint(); xwt_tests::tests::streams::run(endpoint, xwt_tests::consts::ECHO_SERVER_URL).await?; Ok(()) } #[tokio::test] async fn datagrams() -> color_eyre::eyre::Result<()> { setup()?; let endpoint = test_endpoint(); xwt_tests::tests::datagrams::run(endpoint, xwt_tests::consts::ECHO_SERVER_URL).await?; Ok(()) } #[tokio::test] async fn datagrams_read_into() -> color_eyre::eyre::Result<()> { setup()?; let endpoint = test_endpoint(); xwt_tests::tests::datagrams_read_into::run(endpoint, xwt_tests::consts::ECHO_SERVER_URL) .await?; Ok(()) } #[tokio::test] async fn read_small_buf() -> color_eyre::eyre::Result<()> { setup()?; let endpoint = test_endpoint(); xwt_tests::tests::read_small_buf::run(endpoint, xwt_tests::consts::ECHO_SERVER_URL).await?; Ok(()) } #[tokio::test] async fn read_resize_buf() -> color_eyre::eyre::Result<()> { setup()?; let endpoint = test_endpoint(); xwt_tests::tests::read_resize_buf::run(endpoint, xwt_tests::consts::ECHO_SERVER_URL).await?; Ok(()) } #[tokio::test] async fn session_drop() -> color_eyre::eyre::Result<()> { setup()?; let endpoint = test_endpoint(); xwt_tests::tests::session_drop::run(endpoint, xwt_tests::consts::ECHO_SERVER_URL, |error| { matches!(error, wtransport::error::StreamReadError::NotConnected) }) .await?; Ok(()) } #[tokio::test] async fn accept_bi_stream() -> color_eyre::eyre::Result<()> { setup()?; let endpoint = test_endpoint(); xwt_tests::tests::accept_bi_stream::run(endpoint, xwt_tests::consts::ECHO_OPEN_BI_SERVER_URL) .await?; Ok(()) }