Skip to content

Commit

Permalink
Streamlined the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MOZGIII committed Jul 21, 2023
1 parent 5ff8df4 commit 921ec97
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 23 deletions.
2 changes: 0 additions & 2 deletions crates/xwebtransport-error/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use xwebtransport_core::{prelude::*, traits};
pub enum Connect<Endpoint>
where
Endpoint: traits::EndpointConnect,
EndpointConnectConnectionFor<Endpoint>: traits::Connection,
{
Connect(Endpoint::Error),
Connecting(<Endpoint::Connecting as traits::Connecting>::Error),
Expand All @@ -14,7 +13,6 @@ where
pub enum Accept<Endpoint>
where
Endpoint: traits::EndpointAccept,
EndpointAcceptConnectionFor<Endpoint>: traits::Connection,
{
Accept(Endpoint::Error),
Connecting(<Endpoint::Connecting as traits::Connecting>::Error),
Expand Down
23 changes: 18 additions & 5 deletions crates/xwebtransport-tests/src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,33 @@
use tokio::io::{AsyncReadExt, AsyncWriteExt};
use xwebtransport_core::trait_utils::EndpointConnectConnectionFor;

#[derive(Debug, thiserror::Error)]
pub enum EchoError<Connection>
pub enum EchoError<Endpoint>
where
Connection: xwebtransport_core::OpenBiStream,
Endpoint: xwebtransport_core::EndpointConnect + std::fmt::Debug,
Endpoint::Connecting: std::fmt::Debug,
EndpointConnectConnectionFor<Endpoint>: xwebtransport_core::OpenBiStream + std::fmt::Debug,
{
Open(xwebtransport_error::OpenBi<Connection>),
Connect(xwebtransport_error::Connect<Endpoint>),
Open(xwebtransport_error::OpenBi<EndpointConnectConnectionFor<Endpoint>>),
Send(std::io::Error),
Recv(std::io::Error),
BadData(Vec<u8>),
}

pub async fn echo<Connection>(connection: Connection) -> Result<(), EchoError<Connection>>
pub async fn echo<Endpoint>(
endpoint: Endpoint,
params: Endpoint::Params<'_>,
) -> Result<(), EchoError<Endpoint>>
where
Connection: xwebtransport_core::Connection,
Endpoint: xwebtransport_core::EndpointConnect + std::fmt::Debug,
Endpoint::Connecting: std::fmt::Debug,
EndpointConnectConnectionFor<Endpoint>: xwebtransport_core::OpenBiStream + std::fmt::Debug,
{
let connection = crate::utils::connect(endpoint, "https://echo.webtransport.day", params)
.await
.map_err(EchoError::Connect)?;

let (send_stream, recv_stream) = crate::utils::open_bi(connection)
.await
.map_err(EchoError::Open)?;
Expand Down
1 change: 0 additions & 1 deletion crates/xwebtransport-tests/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ pub async fn connect<Endpoint>(
) -> Result<EndpointConnectConnectionFor<Endpoint>, xwebtransport_error::Connect<Endpoint>>
where
Endpoint: xwebtransport_core::EndpointConnect,
EndpointConnectConnectionFor<Endpoint>: xwebtransport_core::Connection,
{
let connecting = endpoint
.connect(url, params)
Expand Down
12 changes: 3 additions & 9 deletions crates/xwebtransport-web-sys/tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,7 @@ wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser);
async fn main() {
let endpoint = xwebtransport_web_sys::Endpoint;

let connection = xwebtransport_tests::utils::connect(
endpoint,
"https://echo.webtransport.day",
&Default::default(),
)
.await
.unwrap();

xwebtransport_tests::tests::echo(connection).await.unwrap();
xwebtransport_tests::tests::echo(endpoint, &Default::default())
.await
.unwrap();
}
9 changes: 3 additions & 6 deletions crates/xwebtransport-wtransport/tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ async fn main() {

let endpoint = xwebtransport_wtransport::Endpoint(endpoint);

let connection =
xwebtransport_tests::utils::connect(endpoint, "https://echo.webtransport.day", ())
.await
.unwrap();

xwebtransport_tests::tests::echo(connection).await.unwrap();
xwebtransport_tests::tests::echo(endpoint, ())
.await
.unwrap();
}

0 comments on commit 921ec97

Please sign in to comment.