Skip to content

Commit 9adbc57

Browse files
committed
Fix failing tests
The initial error was during compile time because of passing None for the request `data` parameter. The docs were updated to reflect that `None` must be parameterized like `None::<u8>`. Having resolved that, there was a runtime error for the tests where one of them would fail because the specified port was already used. Presumably the tests run in parallel. The StackListener type was updated to take a `port: u16` argument which it will attempt to listen on. This isn't an ideal solution, and another issue will be filed to address it. Resolves #1.
1 parent a6cf29d commit 9adbc57

File tree

2 files changed

+20
-16
lines changed

2 files changed

+20
-16
lines changed

src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ impl ::std::fmt::Display for Error {
9393
/// `rustc_serialize::Encodable`, and the result type must implement `rustc_serialize::Decodable`.
9494
/// This can usually be achieved with `#[derive(RustcEncodable)]` and `#[derive(RustcDecodable)]`.
9595
///
96+
/// **Note:** If not providing data, you must provide a parameterized `None` such as `None::<u8>`.
97+
///
9698
/// # Example
9799
///
98100
/// ```no_run

tests/lib.rs

+18-16
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,23 @@ struct ResponseData {
3838
pong: bool
3939
}
4040

41-
const HOST: &'static str = "0.0.0.0:12345";
42-
fn url(frag: &str) -> String {
43-
format!("http://{}{}", HOST, frag)
44-
}
45-
4641
struct StackListener {
47-
server: ::hyper::server::Listening
42+
server: ::hyper::server::Listening,
43+
host: String,
4844
}
4945

5046
impl StackListener {
51-
pub fn new() -> StackListener {
47+
pub fn new(port: u16) -> StackListener {
48+
let host = format!("0.0.0.0:{}", port);
5249
StackListener {
53-
server: PingServer::build().listen_with(HOST, 1, Protocol::Http).unwrap()
50+
server: PingServer::build().listen_with(&host[..], 1, Protocol::Http).unwrap(),
51+
host: host
5452
}
5553
}
54+
55+
pub fn url(&self, path: &str) -> String {
56+
format!("http://{}{}", self.host, path)
57+
}
5658
}
5759

5860
impl Drop for StackListener {
@@ -63,22 +65,22 @@ impl Drop for StackListener {
6365

6466
#[test]
6567
#[allow(unused_variables)]
66-
fn ping_pong() {
67-
let server = StackListener::new();
68+
fn with_data() {
69+
let server = StackListener::new(40918);
6870

6971
let req = RequestData { ping: true };
7072

7173
// When this fails, the error I get it "called Option::unwrap() on a None value" which is not
7274
// helpful for resolving what the problem is.
73-
let res: ResponseData = request(Method::Post, &(url("/ping"))[..], Some(req)).unwrap().unwrap();
75+
let url = server.url("/ping");
76+
let res: ResponseData = request(Method::Post, &url[..], Some(req)).unwrap().unwrap();
7477
}
7578

7679
#[test]
7780
#[allow(unused_variables)]
78-
fn ping_pong_none_data() {
79-
let server = StackListener::new();
81+
fn none_data() {
82+
let server = StackListener::new(40919);
8083

81-
// When this fails, the error I get it "called Option::unwrap() on a None value" which is not
82-
// helpful for resolving what the problem is.
83-
let res: ResponseData = request(Method::Post, &(url("/ping"))[..], None).unwrap().unwrap();
84+
let url = server.url("/ping");
85+
let res: ResponseData = request(Method::Post, &url[..], None::<u8>).unwrap().unwrap();
8486
}

0 commit comments

Comments
 (0)