From 6a5915d7d64820ecaf6aed30c92f2f7fbe28d72f Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Thu, 18 Jun 2015 17:58:22 +0200 Subject: [PATCH] fix(lib): remove macro usage to work on stable 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. --- src/device.rs | 58 +++++++++++++++++++++++++++++++++----------------- src/lib.rs | 4 ++-- src/refresh.rs | 38 ++++++++++++++++++++++++--------- 3 files changed, 69 insertions(+), 31 deletions(-) diff --git a/src/device.rs b/src/device.rs index 6304ca30e..de602b2ce 100644 --- a/src/device.rs +++ b/src/device.rs @@ -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\ @@ -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 { + self.0.connect(host, port, scheme) + } + + fn set_ssl_verifier(&mut self, _: hyper::net::ContextVerifier) {} + } #[test] fn working_flow() { diff --git a/src/lib.rs b/src/lib.rs index e65dc85ae..706972d2c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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; diff --git a/src/refresh.rs b/src/refresh.rs index 1c79960df..9c4dc6c84 100644 --- a/src/refresh.rs +++ b/src/refresh.rs @@ -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 { + self.0.connect(host, port, scheme) + } + + fn set_ssl_verifier(&mut self, _: hyper::net::ContextVerifier) {} + } #[test] fn refresh_flow() {