Skip to content

Commit

Permalink
fix(lib): remove macro usage to work on stable
Browse files Browse the repository at this point in the history
As usage of the `!include` macro is enforced, there is currently no way
to use the exported macros from `yup_hyper_mock`. Now some more
boilerplate code was added to make it work anyway.
  • Loading branch information
Byron committed Jun 18, 2015
1 parent f59d97d commit 6a5915d
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 31 deletions.
58 changes: 39 additions & 19 deletions src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,9 +339,14 @@ pub mod tests {
use std::default::Default;
use time::Duration;
use hyper;
use yup_hyper_mock::{SequentialConnector, MockStream};

mock_connector_in_order!(MockGoogleAuth {
"HTTP/1.1 200 OK\r\n\
pub struct MockGoogleAuth(SequentialConnector);

impl Default for MockGoogleAuth {
fn default() -> MockGoogleAuth {
let mut c = MockGoogleAuth(Default::default());
c.0.content.push("HTTP/1.1 200 OK\r\n\
Server: BOGUS\r\n\
\r\n\
{\r\n\
Expand All @@ -350,23 +355,38 @@ pub mod tests {
\"verification_url\" : \"http://www.google.com/device\",\r\n\
\"expires_in\" : 1800,\r\n\
\"interval\" : 0\r\n\
}"
"HTTP/1.1 200 OK\r\n\
Server: BOGUS\r\n\
\r\n\
{\r\n\
\"error\" : \"authorization_pending\"\r\n\
}"
"HTTP/1.1 200 OK\r\n\
Server: BOGUS\r\n\
\r\n\
{\r\n\
\"access_token\":\"1/fFAGRNJru1FTz70BzhT3Zg\",\r\n\
\"expires_in\":3920,\r\n\
\"token_type\":\"Bearer\",\r\n\
\"refresh_token\":\"1/6BMfW9j53gdGImsixUH6kU5RsR4zwI9lUVX-tqf8JXQ\"\r\n\
}"
});
}".to_string());

c.0.content.push("HTTP/1.1 200 OK\r\n\
Server: BOGUS\r\n\
\r\n\
{\r\n\
\"error\" : \"authorization_pending\"\r\n\
}".to_string());

c.0.content.push("HTTP/1.1 200 OK\r\n\
Server: BOGUS\r\n\
\r\n\
{\r\n\
\"access_token\":\"1/fFAGRNJru1FTz70BzhT3Zg\",\r\n\
\"expires_in\":3920,\r\n\
\"token_type\":\"Bearer\",\r\n\
\"refresh_token\":\"1/6BMfW9j53gdGImsixUH6kU5RsR4zwI9lUVX-tqf8JXQ\"\r\n\
}".to_string());
c

}
}

impl hyper::net::NetworkConnector for MockGoogleAuth {
type Stream = MockStream;

fn connect(&self, host: &str, port: u16, scheme: &str) -> ::hyper::Result<MockStream> {
self.0.connect(host, port, scheme)
}

fn set_ssl_verifier(&mut self, _: hyper::net::ContextVerifier) {}
}

#[test]
fn working_flow() {
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
//! The returned `Token` should be stored permanently to authorize future API requests.
//!
//! ```test_harness,no_run
//! #![feature(custom_derive, plugin)]
//! #![plugin(serde_macros)]
//! #![cfg_attr(feature = "nightly", feature(custom_derive, custom_attribute, plugin))]
//! #![cfg_attr(feature = "nightly", plugin(serde_macros))]
//! extern crate hyper;
//! extern crate yup_oauth2 as oauth2;
//! extern crate serde;
Expand Down
38 changes: 28 additions & 10 deletions src/refresh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,17 +123,35 @@ mod tests {
use std::default::Default;
use super::*;
use super::super::FlowType;
use yup_hyper_mock::{MockStream, SequentialConnector};

struct MockGoogleRefresh(SequentialConnector);

impl Default for MockGoogleRefresh {
fn default() -> MockGoogleRefresh {
let mut c = MockGoogleRefresh(Default::default());
c.0.content.push("HTTP/1.1 200 OK\r\n\
Server: BOGUS\r\n\
\r\n\
{\r\n\
\"access_token\":\"1/fFAGRNJru1FTz70BzhT3Zg\",\r\n\
\"expires_in\":3920,\r\n\
\"token_type\":\"Bearer\"\r\n\
}".to_string());

c
}
}

impl hyper::net::NetworkConnector for MockGoogleRefresh {
type Stream = MockStream;

mock_connector_in_order!(MockGoogleRefresh {
"HTTP/1.1 200 OK\r\n\
Server: BOGUS\r\n\
\r\n\
{\r\n\
\"access_token\":\"1/fFAGRNJru1FTz70BzhT3Zg\",\r\n\
\"expires_in\":3920,\r\n\
\"token_type\":\"Bearer\"\r\n\
}"
});
fn connect(&self, host: &str, port: u16, scheme: &str) -> ::hyper::Result<MockStream> {
self.0.connect(host, port, scheme)
}

fn set_ssl_verifier(&mut self, _: hyper::net::ContextVerifier) {}
}

#[test]
fn refresh_flow() {
Expand Down

0 comments on commit 6a5915d

Please sign in to comment.