mirror of
https://github.com/OMGeeky/tarpc.git
synced 2026-02-13 21:18:18 +01:00
Replace transport integration tests with unit tests.
I want 'cargo test' to run faster.
This commit is contained in:
@@ -198,3 +198,41 @@ where
|
||||
Poll::Ready(next.map(|conn| Ok(new(conn))))
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use assert_matches::assert_matches;
|
||||
use futures::{Sink, Stream};
|
||||
use futures_test::task::noop_waker_ref;
|
||||
use pin_utils::pin_mut;
|
||||
use std::{io::Cursor, task::{Context, Poll}};
|
||||
use super::Transport;
|
||||
|
||||
fn ctx() -> Context<'static> {
|
||||
Context::from_waker(&noop_waker_ref())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_stream() {
|
||||
let reader = *b"\x00\x00\x00\x18\"Test one, check check.\"";
|
||||
let reader: Box<[u8]> = Box::new(reader);
|
||||
let transport = Transport::<_, String, String>::from(Cursor::new(reader));
|
||||
pin_mut!(transport);
|
||||
|
||||
assert_matches!(
|
||||
transport.poll_next(&mut ctx()),
|
||||
Poll::Ready(Some(Ok(ref s))) if s == "Test one, check check.");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_sink() {
|
||||
let writer: &mut [u8] = &mut [0; 28];
|
||||
let transport = Transport::<_, String, String>::from(Cursor::new(&mut *writer));
|
||||
pin_mut!(transport);
|
||||
|
||||
assert_matches!(transport.as_mut().poll_ready(&mut ctx()), Poll::Ready(Ok(())));
|
||||
assert_matches!(transport.as_mut().start_send("Test one, check check.".into()), Ok(()));
|
||||
assert_matches!(transport.poll_flush(&mut ctx()), Poll::Ready(Ok(())));
|
||||
assert_eq!(writer, b"\x00\x00\x00\x18\"Test one, check check.\"");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user