tokio-io-mock-fork

Crates.iotokio-io-mock-fork
lib.rstokio-io-mock-fork
version0.1.0
sourcesrc
created_at2025-04-01 21:35:54.224339+00
updated_at2025-04-01 21:35:54.224339+00
descriptionEnhanced tokio_test::io::Mock
homepage
repositoryhttps://github.com/vi/tokio-io-mock-fork
max_upload_size
id1615631
size89,608
Vitaly Shukela (vi)

documentation

README

tokio-io-mock-fork

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.

Additional Features

  • 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.

Example

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?;
Commit count: 0

cargo fmt