socket_server_mocker/instructions.rs
1//! # `server_mocker_instruction`
2//!
3//! Instructions sent by the testing code to the mocked server.
4
5/// Type of network instruction executed by the server mocker.
6#[derive(Debug, Clone, PartialEq)]
7pub enum Instruction {
8 /// Send given message to the client
9 SendMessage(Vec<u8>),
10 /// Send a message to the client depending on the last received message
11 ///
12 /// If the given function returns None, no message is sent
13 ///
14 /// # Example
15 /// ```
16 /// # use socket_server_mocker::Instruction::{self, SendMessageDependingOnLastReceivedMessage};
17 /// SendMessageDependingOnLastReceivedMessage(|last_received_message: Option<Vec<u8>>| {
18 /// if let Some(last_received_message) = last_received_message {
19 /// if last_received_message == vec![0x01, 0x02, 0x03] {
20 /// Some(vec![0x04, 0x05, 0x06])
21 /// } else {
22 /// None
23 /// }
24 /// } else {
25 /// None
26 /// }
27 /// });
28 /// ```
29 SendMessageDependingOnLastReceivedMessage(fn(Option<Vec<u8>>) -> Option<Vec<u8>>),
30 /// Wait for a message to be received.
31 ///
32 /// The message could be recovered with [`ServerMocker::pop_received_message`](crate::ServerMocker::pop_received_message)
33 ReceiveMessage,
34 /// Wait for a message to be received with a maximum size (useful in UDP).
35 ///
36 /// If the message is bigger than the given size, the message is truncated.
37 ///
38 /// The message could be recovered with [`ServerMocker::pop_received_message`](crate::ServerMocker::pop_received_message)
39 ReceiveMessageWithMaxSize(usize),
40 /// Stop the exchange with the client, close the connection in case of TCP
41 StopExchange,
42}