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.
This commit is contained in:
Sebastian Thiel
2015-06-18 17:58:22 +02:00
parent f59d97d4c5
commit 6a5915d7d6
3 changed files with 69 additions and 31 deletions

View File

@@ -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<MockStream> {
self.0.connect(host, port, scheme)
}
fn set_ssl_verifier(&mut self, _: hyper::net::ContextVerifier) {}
}
#[test]
fn working_flow() {

View File

@@ -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;

View File

@@ -123,17 +123,35 @@ mod tests {
use std::default::Default;
use super::*;
use super::super::FlowType;
use yup_hyper_mock::{MockStream, SequentialConnector};
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\
}"
});
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;
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() {