Add test infrastructure to work directly with frames (#56)

This adds a `Codec` based testing API. This is a bit less annoying than writing
at the raw H2 wire protocol level...
This commit is contained in:
Carl Lerche
2017-09-06 14:18:37 -07:00
committed by GitHub
parent 711086c184
commit cd76aca6d4
17 changed files with 601 additions and 222 deletions

View File

@@ -0,0 +1,50 @@
#[macro_export]
macro_rules! assert_closed {
($transport:expr) => {{
assert_eq!($transport.poll().unwrap(), None.into());
}}
}
#[macro_export]
macro_rules! assert_ping {
($frame:expr) => {{
match $frame {
::h2::frame::Frame::Ping(v) => v,
f => panic!("expected PING; actual={:?}", f),
}
}}
}
#[macro_export]
macro_rules! assert_settings {
($frame:expr) => {{
match $frame {
::h2::frame::Frame::Settings(v) => v,
f => panic!("expected SETTINGS; actual={:?}", f),
}
}}
}
#[macro_export]
macro_rules! poll_err {
($transport:expr) => {{
match $transport.poll() {
Err(e) => e,
frame => panic!("expected error; actual={:?}", frame),
}
}}
}
#[macro_export]
macro_rules! poll_data {
($transport:expr) => {{
use h2::frame::Frame;
use futures::Async;
match $transport.poll() {
Ok(Async::Ready(Some(Frame::Data(frame)))) => frame,
frame => panic!("expected data frame; actual={:?}", frame),
}
}}
}