Crates.io | tokio-io-mock-fork |
lib.rs | tokio-io-mock-fork |
version | 0.1.0 |
source | src |
created_at | 2025-04-01 21:35:54.224339+00 |
updated_at | 2025-04-01 21:35:54.224339+00 |
description | Enhanced tokio_test::io::Mock |
homepage | |
repository | https://github.com/vi/tokio-io-mock-fork |
max_upload_size | |
id | 1615631 |
size | 89,608 |
Forked and extended tokio_test::io
module.
Like original module, it allows creating AsyncRead
+ AsyncWrite
objects which behave according to
scenarios set using builder API.
More informative panic messages (can include name, number of read and written bytes, etc.)
More actions to mock: read EOFs, write shutdowns
Ability to skip checking some of the written bytes; ability to turn off assertions entirely after a certain point.
Panicless mode where failures are signaled using a channel instead.
Dedicated tools to work with large spans of zero bytes (without keeping them allocated in memory).
Text scenarios - a concise way to schedule multiple different actions using one &str
.
let mut mock = Builder::new().read(b"ping").eof().write(b"pong").build();
let mut buf = [0; 256];
let n = mock.read(&mut buf).await?;
assert_eq!(&buf[..n], b"ping");
let n = mock.read(&mut buf).await?;
assert_eq!(n, 0);
mock.write_all(b"pong").await?;