pub struct WebSocketTestClient { /* private fields */ }Expand description
WebSocket test client for integration testing
Provides high-level API for WebSocket connection management, message sending/receiving, and authentication.
Implementations§
Source§impl WebSocketTestClient
impl WebSocketTestClient
Sourcepub async fn connect(url: &str) -> Result<Self, WsError>
pub async fn connect(url: &str) -> Result<Self, WsError>
Connect to WebSocket server
§Example
use reinhardt_test::websocket::WebSocketTestClient;
#[tokio::test]
async fn test_connect() {
let client = WebSocketTestClient::connect("ws://localhost:8080/ws")
.await
.unwrap();
}Sourcepub async fn connect_with_token(url: &str, token: &str) -> Result<Self, WsError>
pub async fn connect_with_token(url: &str, token: &str) -> Result<Self, WsError>
Connect to WebSocket server with Bearer token authentication
Adds Authorization: Bearer <token> header to the WebSocket handshake request.
§Example
use reinhardt_test::websocket::WebSocketTestClient;
#[tokio::test]
async fn test_auth() {
let client = WebSocketTestClient::connect_with_token(
"ws://localhost:8080/ws",
"my-secret-token"
)
.await
.unwrap();
}Sourcepub async fn connect_with_query_token(
url: &str,
token: &str,
) -> Result<Self, WsError>
pub async fn connect_with_query_token( url: &str, token: &str, ) -> Result<Self, WsError>
Connect to WebSocket server with query parameter authentication
Appends ?token=<token> to the URL.
§Example
use reinhardt_test::websocket::WebSocketTestClient;
#[tokio::test]
async fn test_query_auth() {
let client = WebSocketTestClient::connect_with_query_token(
"ws://localhost:8080/ws",
"my-token"
)
.await
.unwrap();
}Connect to WebSocket server with cookie authentication
Adds Cookie: <cookie_name>=<cookie_value> header to the WebSocket handshake request.
§Example
use reinhardt_test::websocket::WebSocketTestClient;
#[tokio::test]
async fn test_cookie_auth() {
let client = WebSocketTestClient::connect_with_cookie(
"ws://localhost:8080/ws",
"session_id",
"abc123"
)
.await
.unwrap();
}Sourcepub async fn send_text(&mut self, text: &str) -> Result<(), WsError>
pub async fn send_text(&mut self, text: &str) -> Result<(), WsError>
Send text message to WebSocket server
§Example
use reinhardt_test::websocket::WebSocketTestClient;
#[tokio::test]
async fn test_send() {
let mut client = WebSocketTestClient::connect("ws://localhost:8080/ws")
.await
.unwrap();
client.send_text("Hello").await.unwrap();
}Sourcepub async fn send_binary(&mut self, data: &[u8]) -> Result<(), WsError>
pub async fn send_binary(&mut self, data: &[u8]) -> Result<(), WsError>
Send binary message to WebSocket server
Sourcepub async fn send_ping(&mut self, payload: &[u8]) -> Result<(), WsError>
pub async fn send_ping(&mut self, payload: &[u8]) -> Result<(), WsError>
Send ping message to WebSocket server
Sourcepub async fn send_pong(&mut self, payload: &[u8]) -> Result<(), WsError>
pub async fn send_pong(&mut self, payload: &[u8]) -> Result<(), WsError>
Send pong message to WebSocket server
Sourcepub async fn receive(&mut self) -> Option<Result<Message, WsError>>
pub async fn receive(&mut self) -> Option<Result<Message, WsError>>
Receive next message from WebSocket server
Returns None if connection is closed.
Sourcepub async fn receive_text(&mut self) -> Result<String, WsError>
pub async fn receive_text(&mut self) -> Result<String, WsError>
Receive text message from WebSocket server with timeout
§Example
use reinhardt_test::websocket::WebSocketTestClient;
#[tokio::test]
async fn test_receive() {
let mut client = WebSocketTestClient::connect("ws://localhost:8080/ws")
.await
.unwrap();
let text = client.receive_text().await.unwrap();
assert_eq!(text, "Welcome");
}Sourcepub async fn receive_text_with_timeout(
&mut self,
duration: Duration,
) -> Result<String, WsError>
pub async fn receive_text_with_timeout( &mut self, duration: Duration, ) -> Result<String, WsError>
Receive text message with custom timeout
Sourcepub async fn receive_binary(&mut self) -> Result<Vec<u8>, WsError>
pub async fn receive_binary(&mut self) -> Result<Vec<u8>, WsError>
Receive binary message from WebSocket server with timeout
Auto Trait Implementations§
impl !Freeze for WebSocketTestClient
impl !RefUnwindSafe for WebSocketTestClient
impl Send for WebSocketTestClient
impl Sync for WebSocketTestClient
impl Unpin for WebSocketTestClient
impl UnsafeUnpin for WebSocketTestClient
impl !UnwindSafe for WebSocketTestClient
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more