use flowsdk::mqtt_client::transport::{TcpTransport, Transport};
#[tokio::test]
#[ignore] async fn test_transport_abstraction_with_echo_server() {
let result = TcpTransport::connect("broker.emqx.io:1883").await;
assert!(result.is_ok(), "Should connect through Transport trait");
if let Ok(transport) = result {
let boxed: Box<dyn Transport> = Box::new(transport);
let peer = boxed.peer_addr();
assert!(peer.is_ok(), "Should get peer address through trait");
}
}
#[tokio::test]
async fn test_transport_trait_object() {
async fn use_any_transport(
addr: &str,
) -> Result<Box<dyn Transport>, Box<dyn std::error::Error>> {
let transport = TcpTransport::connect(addr).await?;
Ok(Box::new(transport))
}
let result = use_any_transport("invalid:9999").await;
assert!(result.is_err(), "Should fail with invalid address");
}
#[tokio::test]
async fn test_transport_as_async_io() {
fn _check_transport_bounds<T: Transport>(_t: T) {
}
async fn _use_transport<T: Transport>(
_transport: T,
) -> Result<String, Box<dyn std::error::Error>> {
Ok("test".to_string())
}
}