More tests
This commit is contained in:
		| @@ -8,7 +8,7 @@ extern crate env_logger; | |||||||
|  |  | ||||||
| use h2::client; | use h2::client; | ||||||
|  |  | ||||||
| use http::request; | use http::*; | ||||||
|  |  | ||||||
| use futures::*; | use futures::*; | ||||||
|  |  | ||||||
| @@ -34,11 +34,19 @@ pub fn main() { | |||||||
|         println!("sending request"); |         println!("sending request"); | ||||||
|  |  | ||||||
|         let mut request = request::Head::default(); |         let mut request = request::Head::default(); | ||||||
|  |         request.method = method::POST; | ||||||
|         request.uri = "https://http2.akamai.com/".parse().unwrap(); |         request.uri = "https://http2.akamai.com/".parse().unwrap(); | ||||||
|         // request.version = version::H2; |         // request.version = version::H2; | ||||||
|  |  | ||||||
|         conn.send_request(1.into(), request, true) |         conn.send_request(1.into(), request, true) | ||||||
|     }) |     }) | ||||||
|  |     /* | ||||||
|  |     .then(|res| { | ||||||
|  |         let conn = res.unwrap(); | ||||||
|  |  | ||||||
|  |         conn.send_data(1.into(), "hello".into(), true) | ||||||
|  |     }) | ||||||
|  |     */ | ||||||
|     .then(|res| { |     .then(|res| { | ||||||
|         let conn = res.unwrap(); |         let conn = res.unwrap(); | ||||||
|         // Get the next message |         // Get the next message | ||||||
|   | |||||||
| @@ -38,6 +38,12 @@ pub fn main() { | |||||||
|  |  | ||||||
|                 // Receive a request |                 // Receive a request | ||||||
|                 conn.into_future() |                 conn.into_future() | ||||||
|  |                     .then(|res| { | ||||||
|  |                         let (frame, conn) = res.unwrap(); | ||||||
|  |                         println!("Zomg frame; {:?}", frame); | ||||||
|  |  | ||||||
|  |                         conn.into_future() | ||||||
|  |                     }) | ||||||
|                     .then(|res| { |                     .then(|res| { | ||||||
|                         let (frame, conn) = res.unwrap(); |                         let (frame, conn) = res.unwrap(); | ||||||
|                         println!("Zomg frame; {:?}", frame); |                         println!("Zomg frame; {:?}", frame); | ||||||
| @@ -47,12 +53,6 @@ pub fn main() { | |||||||
|  |  | ||||||
|                         conn.send_response(1.into(), response, false) |                         conn.send_response(1.into(), response, false) | ||||||
|                     }) |                     }) | ||||||
|                     .then(|res| { |  | ||||||
|                         let conn = res.unwrap(); |  | ||||||
|                         println!("... sending data frame"); |  | ||||||
|  |  | ||||||
|                         conn.send_data(1.into(), "hello".into(), false) |  | ||||||
|                     }) |  | ||||||
|                     .then(|res| { |                     .then(|res| { | ||||||
|                         let conn = res.unwrap(); |                         let conn = res.unwrap(); | ||||||
|                         println!("... sending next frame"); |                         println!("... sending next frame"); | ||||||
|   | |||||||
| @@ -6,7 +6,7 @@ extern crate env_logger; | |||||||
| extern crate bytes; | extern crate bytes; | ||||||
|  |  | ||||||
| use h2::{client, Frame}; | use h2::{client, Frame}; | ||||||
| use http::{request, status}; | use http::*; | ||||||
|  |  | ||||||
| use futures::*; | use futures::*; | ||||||
| use bytes::Bytes; | use bytes::Bytes; | ||||||
| @@ -158,6 +158,68 @@ fn request_with_zero_stream_id() { | |||||||
|     assert_user_err!(err, InvalidStreamId); |     assert_user_err!(err, InvalidStreamId); | ||||||
| } | } | ||||||
|  |  | ||||||
|  | #[test] | ||||||
|  | fn post_with_200_response() { | ||||||
|  |     let _ = ::env_logger::init(); | ||||||
|  |  | ||||||
|  |     let mock = mock_io::Builder::new() | ||||||
|  |         .handshake() | ||||||
|  |         .write(&[ | ||||||
|  |                // POST / | ||||||
|  |                0, 0, 16, 1, 4, 0, 0, 0, 1, 131, 135, 65, 139, 157, 41, | ||||||
|  |                172, 75, 143, 168, 233, 25, 151, 33, 233, 132, | ||||||
|  |         ]) | ||||||
|  |         .write(&[ | ||||||
|  |                // DATA | ||||||
|  |                0, 0, 5, 0, 1, 0, 0, 0, 1, 104, 101, 108, 108, 111, | ||||||
|  |         ]) | ||||||
|  |         .write(SETTINGS_ACK) | ||||||
|  |         // Read response | ||||||
|  |         .read(&[ | ||||||
|  |               // HEADERS | ||||||
|  |               0, 0, 1, 1, 4, 0, 0, 0, 1, 136, | ||||||
|  |               // DATA | ||||||
|  |               0, 0, 5, 0, 1, 0, 0, 0, 1, 119, 111, 114, 108, 100 | ||||||
|  |         ]) | ||||||
|  |         .build(); | ||||||
|  |  | ||||||
|  |     let h2 = client::handshake(mock) | ||||||
|  |         .wait().unwrap(); | ||||||
|  |  | ||||||
|  |     // Send the request | ||||||
|  |     let mut request = request::Head::default(); | ||||||
|  |     request.method = method::POST; | ||||||
|  |     request.uri = "https://http2.akamai.com/".parse().unwrap(); | ||||||
|  |     let h2 = h2.send_request(1.into(), request, false).wait().unwrap(); | ||||||
|  |  | ||||||
|  |     // Send the data | ||||||
|  |     let h2 = h2.send_data(1.into(), "hello".into(), true).wait().unwrap(); | ||||||
|  |  | ||||||
|  |     // 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"world"[..]); | ||||||
|  |             assert!(end_of_stream); | ||||||
|  |         } | ||||||
|  |         _ => panic!("unexpected frame"), | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     assert!(Stream::wait(h2).next().is_none()); | ||||||
|  | } | ||||||
|  |  | ||||||
| #[test] | #[test] | ||||||
| fn request_with_server_stream_id() { | fn request_with_server_stream_id() { | ||||||
|     let mock = mock_io::Builder::new() |     let mock = mock_io::Builder::new() | ||||||
| @@ -220,8 +282,31 @@ fn send_data_without_headers() { | |||||||
| } | } | ||||||
|  |  | ||||||
| #[test] | #[test] | ||||||
| #[ignore] |  | ||||||
| fn send_data_after_headers_eos() { | fn send_data_after_headers_eos() { | ||||||
|  |     let _ = ::env_logger::init(); | ||||||
|  |  | ||||||
|  |     let mock = mock_io::Builder::new() | ||||||
|  |         .handshake() | ||||||
|  |         // Write GET / | ||||||
|  |         .write(&[ | ||||||
|  |                // GET /, no EOS | ||||||
|  |                0, 0, 16, 1, 5, 0, 0, 0, 1, 131, 135, 65, 139, 157, 41, 172, | ||||||
|  |                75, 143, 168, 233, 25, 151, 33, 233, 132 | ||||||
|  |         ]) | ||||||
|  |         .build(); | ||||||
|  |  | ||||||
|  |     let h2 = client::handshake(mock) | ||||||
|  |         .wait().unwrap(); | ||||||
|  |  | ||||||
|  |     // Send the request | ||||||
|  |     let mut request = request::Head::default(); | ||||||
|  |     request.method = method::POST; | ||||||
|  |     request.uri = "https://http2.akamai.com/".parse().unwrap(); | ||||||
|  |     let h2 = h2.send_request(1.into(), request, true).wait().unwrap(); | ||||||
|  |  | ||||||
|  |     // Send the data | ||||||
|  |     let err = h2.send_data(1.into(), "hello".into(), true).wait().unwrap_err(); | ||||||
|  |     assert_user_err!(err, UnexpectedFrameType); | ||||||
| } | } | ||||||
|  |  | ||||||
| #[test] | #[test] | ||||||
| @@ -235,8 +320,24 @@ fn request_with_h1_version() { | |||||||
| } | } | ||||||
|  |  | ||||||
| #[test] | #[test] | ||||||
| #[ignore] |  | ||||||
| fn invalid_client_stream_id() { | fn invalid_client_stream_id() { | ||||||
|  |     let _ = ::env_logger::init(); | ||||||
|  |  | ||||||
|  |     for &id in &[0, 2] { | ||||||
|  |         let mock = mock_io::Builder::new() | ||||||
|  |             .handshake() | ||||||
|  |             .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(); | ||||||
|  |         let err = h2.send_request(id.into(), request, true).wait().unwrap_err(); | ||||||
|  |  | ||||||
|  |         assert_user_err!(err, InvalidStreamId); | ||||||
|  |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| #[test] | #[test] | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user