Start writing tests

This commit is contained in:
Carl Lerche
2017-06-29 20:59:21 -07:00
parent 0564747121
commit 63ffea61f5
3 changed files with 97 additions and 2 deletions

View File

@@ -15,12 +15,17 @@ fnv = "1.0.5"
ordermap = "0.2.10"
[dev-dependencies]
mock-io = { git = "https://github.com/carllerche/mock-io" }
# Fuzzing
quickcheck = "0.4.1"
rand = "0.3.15"
# HPACK fixtures
hex = "0.2.0"
walkdir = "1.0.0"
serde = "1.0.0"
serde_json = "1.0.0"
quickcheck = "0.4.1"
rand = "0.3.15"
# Akamai example
tokio-core = "0.1"

View File

@@ -120,6 +120,7 @@ impl<T> Sink for Settings<T>
}
fn poll_complete(&mut self) -> Poll<(), ConnectionError> {
trace!("Settings::poll_complete");
try_ready!(self.try_send_pending());
self.inner.poll_complete()
}

89
tests/client_request.rs Normal file
View File

@@ -0,0 +1,89 @@
extern crate h2;
extern crate http;
extern crate futures;
extern crate mock_io;
extern crate env_logger;
use h2::client;
use http::request;
use futures::*;
#[test]
fn handshake() {
let _ = ::env_logger::init().unwrap();
let mock = mock_io::Builder::new()
.client_handshake()
.build();
let mut h2 = client::handshake(mock)
.wait().unwrap();
// At this point, the connection should be closed
assert!(Stream::wait(h2).next().is_none());
}
#[test]
#[ignore] // Not working yet
fn hello_world() {
let _ = ::env_logger::init().unwrap();
let mock = mock_io::Builder::new()
.client_handshake()
// GET https://example.com/ HEADERS frame
.write(&[0, 0, 13, 1, 5, 0, 0, 0, 1, 130, 135, 65, 136, 47, 145, 211, 93, 5, 92, 135, 167, 132])
// .read(&[0, 0, 0, 1, 5, 0, 0, 0, 1])
.build();
let mut h2 = client::handshake(mock)
.wait().unwrap();
let mut request = request::Head::default();
request.uri = "https://example.com/".parse().unwrap();
// request.version = version::H2;
println!("~~~ SEND REQUEST ~~~");
// Send the request
let mut h2 = h2.send_request(1, request, true).wait().unwrap();
println!("~~~ WAIT FOR RESPONSE ~~~");
// Iterate the response frames
let mut h2 = Stream::wait(h2);
let headers = h2.next().unwrap();
// At this point, the connection should be closed
assert!(h2.next().is_none());
}
#[test]
#[ignore]
fn request_without_scheme() {
}
#[test]
#[ignore]
fn request_with_h1_version() {
}
const SETTINGS: &'static [u8] = &[0, 0, 0, 4, 0, 0, 0, 0, 0];
const SETTINGS_ACK: &'static [u8] = &[0, 0, 0, 4, 1, 0, 0, 0, 0];
trait MockH2 {
fn client_handshake(&mut self) -> &mut Self;
}
impl MockH2 for mock_io::Builder {
fn client_handshake(&mut self) -> &mut Self {
self.write(b"PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n")
// Settings frame
.write(SETTINGS)
/*
.read(&[0, 0, 0, 4, 0, 0, 0, 0, 0])
// Settings ACK
.write(&[0, 0, 0, 4, 1, 0, 0, 0, 0])
.read(&[0, 0, 0, 4, 1, 0, 0, 0, 0])
*/
}
}