pub struct TcpServerMocker { /* private fields */ }
Expand description

A TCP server mocker

Can be used to mock a TCP server if the application you want to test uses TCP sockets to connect to a server.

Only 1 client can be connected to the mocked server. When the connection is closed, the mocked server will stop.

Trait Implementations

TcpServerMocker implementation

Example

use std::io::Write;
use std::net::TcpStream;
use socket_server_mocker::server_mocker::ServerMocker;
use socket_server_mocker::server_mocker_instruction::{ServerMockerInstructionsList, ServerMockerInstruction};
use socket_server_mocker::tcp_server_mocker::TcpServerMocker;

let tcp_server_mocker = TcpServerMocker::new(1234);
let mut client = TcpStream::connect("127.0.0.1:1234").unwrap();

tcp_server_mocker.add_mock_instructions_list(ServerMockerInstructionsList::new_with_instructions([
    ServerMockerInstruction::ReceiveMessage,
    ServerMockerInstruction::StopExchange,
].as_slice()));
client.write_all(&[1, 2, 3]).unwrap();

let mock_server_received_message = tcp_server_mocker.pop_received_message();
assert_eq!(Some(vec![1, 2, 3]), mock_server_received_message);
Creates a new server mocker Read more
Returns the port on which the mock server is listening Read more
Adds a list of instructions to the server mocker Read more
Return first message received by the mock server on the messages queue Read more
Default timeout in milliseconds for the server to wait for a message from the client.
Timeout if no more instruction is available and ServerMockerInstruction::StopExchange hasn’t been sent
Adds a slice of instructions to the server mocker Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.