More tests
This commit is contained in:
@@ -5,11 +5,11 @@ extern crate mock_io;
|
||||
extern crate env_logger;
|
||||
extern crate bytes;
|
||||
|
||||
use h2::client;
|
||||
use http::request;
|
||||
use bytes::Bytes;
|
||||
use h2::{client, Frame};
|
||||
use http::{request, status};
|
||||
|
||||
use futures::*;
|
||||
use bytes::Bytes;
|
||||
|
||||
// TODO: move into another file
|
||||
macro_rules! assert_user_err {
|
||||
@@ -32,7 +32,7 @@ fn handshake() {
|
||||
.write(SETTINGS_ACK)
|
||||
.build();
|
||||
|
||||
let mut h2 = client::handshake(mock)
|
||||
let h2 = client::handshake(mock)
|
||||
.wait().unwrap();
|
||||
|
||||
// At this point, the connection should be closed
|
||||
@@ -55,7 +55,7 @@ fn get_with_204_response() {
|
||||
.read(&[0, 0, 1, 1, 5, 0, 0, 0, 1, 0x89])
|
||||
.build();
|
||||
|
||||
let mut h2 = client::handshake(mock)
|
||||
let h2 = client::handshake(mock)
|
||||
.wait().unwrap();
|
||||
|
||||
// Send the request
|
||||
@@ -66,11 +66,18 @@ fn get_with_204_response() {
|
||||
// Get the 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
|
||||
assert!(Stream::wait(h2).next().is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
fn get_with_200_response() {
|
||||
let _ = ::env_logger::init();
|
||||
|
||||
@@ -78,15 +85,18 @@ fn get_with_200_response() {
|
||||
.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,
|
||||
0, 0, 16, 1, 5, 0, 0, 0, 1, 130, 135, 65, 139, 157, 41, 172, 75,
|
||||
143, 168, 233, 25, 151, 33, 233, 132
|
||||
])
|
||||
.write(SETTINGS_ACK)
|
||||
// Read response
|
||||
.read(&[0, 0, 1, 1, 5, 0, 0, 0, 1, 0x89])
|
||||
.read(&[
|
||||
0, 0, 1, 1, 4, 0, 0, 0, 1, 136, 0, 0, 5, 0, 0, 0, 0, 0, 1, 104, 101,
|
||||
108, 108, 111, 0, 0, 5, 0, 1, 0, 0, 0, 1, 119, 111, 114, 108, 100,
|
||||
])
|
||||
.build();
|
||||
|
||||
let mut h2 = client::handshake(mock)
|
||||
let h2 = client::handshake(mock)
|
||||
.wait().unwrap();
|
||||
|
||||
// Send the request
|
||||
@@ -94,9 +104,40 @@ fn get_with_200_response() {
|
||||
request.uri = "https://http2.akamai.com/".parse().unwrap();
|
||||
let h2 = h2.send_request(1.into(), request, true).wait().unwrap();
|
||||
|
||||
// Get the response
|
||||
// Get the response headers
|
||||
let (resp, h2) = h2.into_future().wait().unwrap();
|
||||
|
||||
match resp.unwrap() {
|
||||
Frame::Headers { headers, .. } => {
|
||||
assert_eq!(headers.status, status::OK);
|
||||
}
|
||||
_ => panic!("unexpected frame"),
|
||||
}
|
||||
|
||||
// Get the response body
|
||||
let (data, h2) = h2.into_future().wait().unwrap();
|
||||
|
||||
match data.unwrap() {
|
||||
Frame::Data { id, data, end_of_stream } => {
|
||||
assert_eq!(id, 1.into());
|
||||
assert_eq!(data, &b"hello"[..]);
|
||||
assert!(!end_of_stream);
|
||||
}
|
||||
_ => panic!("unexpected frame"),
|
||||
}
|
||||
|
||||
// Get the response body
|
||||
let (data, h2) = h2.into_future().wait().unwrap();
|
||||
|
||||
match data.unwrap() {
|
||||
Frame::Data { id, data, end_of_stream } => {
|
||||
assert_eq!(id, 1.into());
|
||||
assert_eq!(data, &b"world"[..]);
|
||||
assert!(end_of_stream);
|
||||
}
|
||||
_ => panic!("unexpected frame"),
|
||||
}
|
||||
|
||||
assert!(Stream::wait(h2).next().is_none());
|
||||
}
|
||||
|
||||
@@ -135,10 +176,16 @@ fn request_with_server_stream_id() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
fn send_data_without_headers() {
|
||||
fn send_headers_twice_with_same_stream_id() {
|
||||
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,
|
||||
])
|
||||
.build();
|
||||
|
||||
let h2 = client::handshake(mock)
|
||||
@@ -147,11 +194,29 @@ fn send_data_without_headers() {
|
||||
// Send the request
|
||||
let mut request = request::Head::default();
|
||||
request.uri = "https://http2.akamai.com/".parse().unwrap();
|
||||
let h2 = h2.send_request(1.into(), request, true).wait().unwrap();
|
||||
|
||||
/*
|
||||
let err = h2.send_request(2.into(), request, true).wait().unwrap_err();
|
||||
assert_user_err!(err, InvalidStreamId);
|
||||
*/
|
||||
// Send another request with the same stream ID
|
||||
let mut request = request::Head::default();
|
||||
request.uri = "https://http2.akamai.com/".parse().unwrap();
|
||||
let err = h2.send_request(1.into(), request, true).wait().unwrap_err();
|
||||
|
||||
assert_user_err!(err, UnexpectedFrameType);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn send_data_without_headers() {
|
||||
let mock = mock_io::Builder::new()
|
||||
.handshake()
|
||||
.build();
|
||||
|
||||
let h2 = client::handshake(mock)
|
||||
.wait().unwrap();
|
||||
|
||||
let err = h2.send_data(1.into(), Bytes::from_static(b"hello world"), true)
|
||||
.wait().unwrap_err();
|
||||
|
||||
assert_user_err!(err, InactiveStreamId);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user