Start breaking out test files
This commit is contained in:
@@ -56,49 +56,6 @@ mod client_request {
|
||||
assert!(Stream::wait(h2).next().is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn get_with_204_response() {
|
||||
let _ = ::env_logger::init();
|
||||
|
||||
let mock = mock_io::Builder::new()
|
||||
.handshake()
|
||||
// Write GET /
|
||||
.write(&[
|
||||
0, 0, 0x10, 1, 5, 0, 0, 0, 1, 0x82, 0x87, 0x41, 0x8B, 0x9D, 0x29,
|
||||
0xAC, 0x4B, 0x8F, 0xA8, 0xE9, 0x19, 0x97, 0x21, 0xE9, 0x84,
|
||||
])
|
||||
.write(SETTINGS_ACK)
|
||||
// Read response
|
||||
.read(&[0, 0, 1, 1, 5, 0, 0, 0, 1, 0x89])
|
||||
.build();
|
||||
|
||||
let h2 = client::handshake(mock)
|
||||
.wait().unwrap();
|
||||
|
||||
// Send the request
|
||||
let mut request = request::Head::default();
|
||||
request.uri = "https://http2.akamai.com/".parse().unwrap();
|
||||
|
||||
trace!("sending request");
|
||||
let h2 = h2.send_request(1.into(), request, true).wait().unwrap();
|
||||
|
||||
// Get the response
|
||||
|
||||
trace!("getting response");
|
||||
let (resp, h2) = h2.into_future().wait().unwrap();
|
||||
|
||||
match resp.unwrap() {
|
||||
Frame::Headers { headers, .. } => {
|
||||
assert_eq!(headers.status, status::NO_CONTENT);
|
||||
}
|
||||
_ => panic!("unexpected frame"),
|
||||
}
|
||||
|
||||
// No more frames
|
||||
trace!("ensure no more responses");
|
||||
assert!(Stream::wait(h2).next().is_none());;
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn get_with_200_response() {
|
||||
let _ = ::env_logger::init();
|
||||
|
||||
48
tests/stream_states.rs
Normal file
48
tests/stream_states.rs
Normal file
@@ -0,0 +1,48 @@
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
|
||||
pub mod support;
|
||||
use support::*;
|
||||
|
||||
#[test]
|
||||
fn headers_only_bidirectional() {
|
||||
let _ = env_logger::init();
|
||||
|
||||
let mock = mock_io::Builder::new()
|
||||
.handshake()
|
||||
// Write GET /
|
||||
.write(&[
|
||||
0, 0, 0x10, 1, 5, 0, 0, 0, 1, 0x82, 0x87, 0x41, 0x8B, 0x9D, 0x29,
|
||||
0xAC, 0x4B, 0x8F, 0xA8, 0xE9, 0x19, 0x97, 0x21, 0xE9, 0x84,
|
||||
])
|
||||
.write(frames::SETTINGS_ACK)
|
||||
// Read response
|
||||
.read(&[0, 0, 1, 1, 5, 0, 0, 0, 1, 0x89])
|
||||
.build();
|
||||
|
||||
let h2 = client::handshake(mock)
|
||||
.wait().unwrap();
|
||||
|
||||
// Send the request
|
||||
let mut request = request::Head::default();
|
||||
request.uri = "https://http2.akamai.com/".parse().unwrap();
|
||||
|
||||
info!("sending request");
|
||||
let h2 = h2.send_request(1.into(), request, true).wait().unwrap();
|
||||
|
||||
// Get the response
|
||||
|
||||
info!("getting response");
|
||||
let (resp, h2) = h2.into_future().wait().unwrap();
|
||||
|
||||
match resp.unwrap() {
|
||||
h2::Frame::Headers { headers, .. } => {
|
||||
assert_eq!(headers.status, status::NO_CONTENT);
|
||||
}
|
||||
_ => panic!("unexpected frame"),
|
||||
}
|
||||
|
||||
// No more frames
|
||||
info!("ensure no more responses");
|
||||
assert!(Stream::wait(h2).next().is_none());;
|
||||
}
|
||||
46
tests/support/mod.rs
Normal file
46
tests/support/mod.rs
Normal file
@@ -0,0 +1,46 @@
|
||||
//! Utilities to support tests.
|
||||
|
||||
pub extern crate bytes;
|
||||
pub extern crate h2;
|
||||
pub extern crate http;
|
||||
pub extern crate futures;
|
||||
pub extern crate mock_io;
|
||||
pub extern crate env_logger;
|
||||
|
||||
pub use self::futures::{
|
||||
Future,
|
||||
Sink,
|
||||
Stream,
|
||||
};
|
||||
|
||||
pub use self::http::{
|
||||
request,
|
||||
response,
|
||||
status,
|
||||
};
|
||||
|
||||
pub use self::h2::{
|
||||
client,
|
||||
server,
|
||||
};
|
||||
|
||||
pub trait MockH2 {
|
||||
fn handshake(&mut self) -> &mut Self;
|
||||
}
|
||||
|
||||
impl MockH2 for mock_io::Builder {
|
||||
fn handshake(&mut self) -> &mut Self {
|
||||
self.write(b"PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n")
|
||||
// Settings frame
|
||||
.write(frames::SETTINGS)
|
||||
.read(frames::SETTINGS)
|
||||
.read(frames::SETTINGS_ACK)
|
||||
}
|
||||
}
|
||||
|
||||
pub mod frames {
|
||||
//! Some useful frames
|
||||
|
||||
pub const SETTINGS: &'static [u8] = &[0, 0, 0, 4, 0, 0, 0, 0, 0];
|
||||
pub const SETTINGS_ACK: &'static [u8] = &[0, 0, 0, 4, 1, 0, 0, 0, 0];
|
||||
}
|
||||
Reference in New Issue
Block a user