summaryrefslogtreecommitdiffstats
path: root/tokio-test/tests
diff options
context:
space:
mode:
authorSean McArthur <sean@seanmonstar.com>2019-07-11 14:41:37 -0700
committerSean McArthur <sean@seanmonstar.com>2019-07-12 11:19:12 -0700
commit48d7f7b93175b46fb5816ad03a47e4a58d2c8d52 (patch)
tree64c2fb483a10abbfb9b2d268bceefd28915a28bf /tokio-test/tests
parent22918231814fb5591a4c0c6d5aa0c5ba8172c9c1 (diff)
tokio-test: add tokio_test::io mock builder
Diffstat (limited to 'tokio-test/tests')
-rw-r--r--tokio-test/tests/io.rs26
1 files changed, 26 insertions, 0 deletions
diff --git a/tokio-test/tests/io.rs b/tokio-test/tests/io.rs
new file mode 100644
index 00000000..00044e83
--- /dev/null
+++ b/tokio-test/tests/io.rs
@@ -0,0 +1,26 @@
+#![deny(warnings, rust_2018_idioms)]
+#![feature(async_await)]
+
+use tokio::io::{AsyncReadExt, AsyncWriteExt};
+use tokio_test::io::Builder;
+
+#[tokio::test]
+async fn read() {
+ let mut mock = Builder::new().read(b"hello ").read(b"world!").build();
+
+ let mut buf = [0; 256];
+
+ let n = mock.read(&mut buf).await.expect("read 1");
+ assert_eq!(&buf[..n], b"hello ");
+
+ let n = mock.read(&mut buf).await.expect("read 2");
+ assert_eq!(&buf[..n], b"world!");
+}
+
+#[tokio::test]
+async fn write() {
+ let mut mock = Builder::new().write(b"hello ").write(b"world!").build();
+
+ mock.write_all(b"hello ").await.expect("write 1");
+ mock.write_all(b"world!").await.expect("write 2");
+}