pub struct MockTransport { /* private fields */ }Expand description
Mock transport for testing. Programs expected command/response exchanges.
Implementations§
Source§impl MockTransport
impl MockTransport
Sourcepub fn expect(&mut self, command: &[u8], response: &[u8])
pub fn expect(&mut self, command: &[u8], response: &[u8])
Queue an expected command/response exchange.
When write() is called with command, the corresponding response
will be returned by the next read().
Sourcepub fn from_fixture(path: &Path) -> Result<Self, Error>
pub fn from_fixture(path: &Path) -> Result<Self, Error>
Load expected exchanges from a fixture file.
The file format uses > prefixed lines for commands and < prefixed
lines for responses. Literal \r sequences are converted to 0x0D.
§Errors
Returns an error if the file cannot be read.
Sourcepub fn queue_read(&mut self, data: &[u8])
pub fn queue_read(&mut self, data: &[u8])
Queue data to be returned by the next read() without requiring
a preceding write().
This is useful for testing unsolicited incoming data (e.g., MMDVM frames received from the radio without a prior command).
Sourcepub const fn expect_any_write(&mut self)
pub const fn expect_any_write(&mut self)
Accept any subsequent write() calls without validation.
When enabled, writes succeed without checking against expected exchanges and no response is queued.
Sourcepub fn assert_complete(&self)
pub fn assert_complete(&self)
Panic if any expected exchanges remain unconsumed.
§Panics
Panics if there are remaining exchanges that were not exercised.