Move tests and support utilities to sub crates. (#268)
These crates will not be published to crates.io, but moving them allows `tower-h2` to also depend on the test utilities.
This commit is contained in:
15
tests/h2-support/Cargo.toml
Normal file
15
tests/h2-support/Cargo.toml
Normal file
@@ -0,0 +1,15 @@
|
||||
[package]
|
||||
name = "h2-support"
|
||||
version = "0.1.0"
|
||||
authors = ["Carl Lerche <me@carllerche.com>"]
|
||||
|
||||
[dependencies]
|
||||
h2 = { path = "../..", features = ["unstable"] }
|
||||
|
||||
bytes = "0.4.7"
|
||||
env_logger = "0.5.9"
|
||||
futures = "0.1.21"
|
||||
http = "0.1.5"
|
||||
string = "0.1.0"
|
||||
tokio-io = "0.1.6"
|
||||
tokio-timer = "0.1.2"
|
||||
5
tests/h2-support/README.md
Normal file
5
tests/h2-support/README.md
Normal file
@@ -0,0 +1,5 @@
|
||||
# h2 test support
|
||||
|
||||
This crate includes utilities for writing h2 tests. This is broken up into a
|
||||
separate crate because it requires the `unstable` feature flag and to enable
|
||||
`tower-h2` to use the same helpers.
|
||||
36
tests/h2-support/src/lib.rs
Normal file
36
tests/h2-support/src/lib.rs
Normal file
@@ -0,0 +1,36 @@
|
||||
//! Utilities to support tests.
|
||||
|
||||
pub extern crate bytes;
|
||||
pub extern crate env_logger;
|
||||
#[macro_use]
|
||||
pub extern crate futures;
|
||||
pub extern crate h2;
|
||||
pub extern crate http;
|
||||
pub extern crate string;
|
||||
#[macro_use]
|
||||
pub extern crate tokio_io;
|
||||
|
||||
#[macro_use]
|
||||
mod assert;
|
||||
|
||||
pub mod raw;
|
||||
|
||||
pub mod frames;
|
||||
pub mod prelude;
|
||||
pub mod mock;
|
||||
pub mod mock_io;
|
||||
pub mod notify;
|
||||
pub mod util;
|
||||
|
||||
mod future_ext;
|
||||
|
||||
pub use future_ext::{FutureExt, Unwrap};
|
||||
|
||||
pub type WindowSize = usize;
|
||||
pub const DEFAULT_WINDOW_SIZE: WindowSize = (1 << 16) - 1;
|
||||
|
||||
// This is our test Codec type
|
||||
pub type Codec<T> = h2::Codec<T, ::std::io::Cursor<::bytes::Bytes>>;
|
||||
|
||||
// This is the frame type that is sent
|
||||
pub type SendFrame = h2::frame::Frame<::std::io::Cursor<::bytes::Bytes>>;
|
||||
@@ -605,11 +605,25 @@ where
|
||||
type Error = ();
|
||||
|
||||
fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
|
||||
use self::Frame::Data;
|
||||
|
||||
let (frame, handle) = match self.inner.poll().unwrap() {
|
||||
Async::Ready((frame, handle)) => (frame, handle),
|
||||
Async::NotReady => return Ok(Async::NotReady),
|
||||
};
|
||||
assert_eq!(frame.unwrap(), self.frame, "recv_frame");
|
||||
|
||||
let frame = frame.unwrap();
|
||||
|
||||
match (frame, &self.frame) {
|
||||
(Data(ref a), &Data(ref b)) => {
|
||||
assert_eq!(a.payload().len(), b.payload().len(), "recv_frame data payload len");
|
||||
assert_eq!(a, b, "recv_frame");
|
||||
}
|
||||
(ref a, b) => {
|
||||
assert_eq!(a, b, "recv_frame");
|
||||
}
|
||||
}
|
||||
|
||||
Ok(Async::Ready(handle))
|
||||
}
|
||||
}
|
||||
@@ -7,19 +7,19 @@ macro_rules! raw_codec {
|
||||
$fn:ident => [$($chunk:expr,)+];
|
||||
)*
|
||||
) => {{
|
||||
let mut b = $crate::support::mock_io::Builder::new();
|
||||
let mut b = $crate::mock_io::Builder::new();
|
||||
|
||||
$({
|
||||
let mut chunk = vec![];
|
||||
|
||||
$(
|
||||
$crate::support::raw::Chunk::push(&$chunk, &mut chunk);
|
||||
$crate::raw::Chunk::push(&$chunk, &mut chunk);
|
||||
)+
|
||||
|
||||
b.$fn(&chunk[..]);
|
||||
})*
|
||||
|
||||
$crate::support::Codec::new(b.build())
|
||||
$crate::Codec::new(b.build())
|
||||
}}
|
||||
}
|
||||
|
||||
11
tests/h2-tests/Cargo.toml
Normal file
11
tests/h2-tests/Cargo.toml
Normal file
@@ -0,0 +1,11 @@
|
||||
[package]
|
||||
name = "h2-tests"
|
||||
version = "0.1.0"
|
||||
authors = ["Carl Lerche <me@carllerche.com>"]
|
||||
publish = false
|
||||
|
||||
[dependencies]
|
||||
|
||||
[dev-dependencies]
|
||||
h2-support = { path = "../h2-support" }
|
||||
log = "0.4.1"
|
||||
7
tests/h2-tests/README.md
Normal file
7
tests/h2-tests/README.md
Normal file
@@ -0,0 +1,7 @@
|
||||
# h2 integration tests
|
||||
|
||||
This crate includes the h2 integration tests. These tests exist in a separate
|
||||
crate because they transitively depend on the `unstable` feature flag via
|
||||
`h2-support`. Due to a cargo limitation, if these tests existed as part of the
|
||||
`h2` crate, it would require that `h2-support` be published to crates.io and
|
||||
force the `unstable` feature flag to always be on.
|
||||
@@ -1,8 +1,8 @@
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
extern crate h2_support;
|
||||
|
||||
pub mod support;
|
||||
use support::prelude::*;
|
||||
use h2_support::prelude::*;
|
||||
|
||||
#[test]
|
||||
fn handshake() {
|
||||
@@ -1,6 +1,7 @@
|
||||
#[macro_use]
|
||||
pub mod support;
|
||||
use support::prelude::*;
|
||||
extern crate h2_support;
|
||||
|
||||
use h2_support::prelude::*;
|
||||
|
||||
use std::error::Error;
|
||||
|
||||
@@ -151,7 +152,7 @@ fn read_continuation_frames() {
|
||||
assert_eq!(res.status(), StatusCode::OK);
|
||||
let (head, _body) = res.into_parts();
|
||||
let expected = large.iter().fold(HeaderMap::new(), |mut map, &(name, ref value)| {
|
||||
use support::frames::HttpTryInto;
|
||||
use h2_support::frames::HttpTryInto;
|
||||
map.append(name, value.as_str().try_into().unwrap());
|
||||
map
|
||||
});
|
||||
@@ -1,6 +1,6 @@
|
||||
#[macro_use]
|
||||
pub mod support;
|
||||
use support::prelude::*;
|
||||
extern crate h2_support;
|
||||
|
||||
use h2_support::prelude::*;
|
||||
|
||||
#[test]
|
||||
fn write_continuation_frames() {
|
||||
@@ -1,6 +1,6 @@
|
||||
#[macro_use]
|
||||
pub mod support;
|
||||
use support::prelude::*;
|
||||
extern crate h2_support;
|
||||
|
||||
use h2_support::prelude::*;
|
||||
|
||||
// In this case, the stream & connection both have capacity, but capacity is not
|
||||
// explicitly requested.
|
||||
@@ -1,6 +1,7 @@
|
||||
#[macro_use]
|
||||
pub mod support;
|
||||
use support::prelude::*;
|
||||
extern crate h2_support;
|
||||
|
||||
use h2_support::prelude::*;
|
||||
|
||||
#[test]
|
||||
fn recv_single_ping() {
|
||||
@@ -1,7 +1,8 @@
|
||||
#[macro_use]
|
||||
pub mod support;
|
||||
use support::{DEFAULT_WINDOW_SIZE};
|
||||
use support::prelude::*;
|
||||
extern crate h2_support;
|
||||
|
||||
use h2_support::{DEFAULT_WINDOW_SIZE};
|
||||
use h2_support::prelude::*;
|
||||
|
||||
#[test]
|
||||
fn single_stream_send_large_body() {
|
||||
@@ -1,5 +1,6 @@
|
||||
pub mod support;
|
||||
use support::prelude::*;
|
||||
extern crate h2_support;
|
||||
|
||||
use h2_support::prelude::*;
|
||||
|
||||
#[test]
|
||||
fn recv_push_works() {
|
||||
@@ -1,6 +1,8 @@
|
||||
#![deny(warnings)]
|
||||
pub mod support;
|
||||
use support::prelude::*;
|
||||
|
||||
extern crate h2_support;
|
||||
|
||||
use h2_support::prelude::*;
|
||||
|
||||
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];
|
||||
@@ -1,9 +1,10 @@
|
||||
#![deny(warnings)]
|
||||
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
extern crate h2_support;
|
||||
|
||||
pub mod support;
|
||||
use support::prelude::*;
|
||||
use h2_support::prelude::*;
|
||||
|
||||
#[test]
|
||||
fn send_recv_headers_only() {
|
||||
@@ -1,8 +1,8 @@
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
extern crate h2_support;
|
||||
|
||||
pub mod support;
|
||||
use support::prelude::*;
|
||||
use h2_support::prelude::*;
|
||||
|
||||
#[test]
|
||||
fn recv_trailers_only() {
|
||||
Reference in New Issue
Block a user