Test serde de/serialization of tokens
This commit is contained in:
parent
ba5b74c698
commit
3cf2af8609
|
@ -20,4 +20,5 @@ serde = "0.6.1"
|
||||||
url = "0.5.0"
|
url = "0.5.0"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
|
serde_json = "0.6.0"
|
||||||
yup-hyper-mock = "1.3.2"
|
yup-hyper-mock = "1.3.2"
|
||||||
|
|
|
@ -149,3 +149,6 @@ pub mod token;
|
||||||
pub mod provider;
|
pub mod provider;
|
||||||
pub mod error;
|
pub mod error;
|
||||||
pub mod client;
|
pub mod client;
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
extern crate serde_json;
|
||||||
|
|
|
@ -157,6 +157,7 @@ impl de::Visitor for FieldVisitor {
|
||||||
mod tests {
|
mod tests {
|
||||||
use chrono::{UTC, Duration};
|
use chrono::{UTC, Duration};
|
||||||
use rustc_serialize::json::Json;
|
use rustc_serialize::json::Json;
|
||||||
|
use serde_json;
|
||||||
|
|
||||||
use client::response::{FromResponse, ParseError};
|
use client::response::{FromResponse, ParseError};
|
||||||
use token::{Static, Expiring};
|
use token::{Static, Expiring};
|
||||||
|
@ -258,4 +259,16 @@ mod tests {
|
||||||
assert!(expiring.expires() > &UTC::now());
|
assert!(expiring.expires() > &UTC::now());
|
||||||
assert!(expiring.expires() <= &(UTC::now() + Duration::seconds(3600)));
|
assert!(expiring.expires() <= &(UTC::now() + Duration::seconds(3600)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn serialize_deserialize() {
|
||||||
|
let original = Bearer {
|
||||||
|
access_token: String::from("foo"),
|
||||||
|
scope: Some(String::from("bar")),
|
||||||
|
lifetime: Static,
|
||||||
|
};
|
||||||
|
let serialized = serde_json::to_value(&original);
|
||||||
|
let deserialized = serde_json::from_value(serialized).unwrap();
|
||||||
|
assert_eq!(original, deserialized);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -182,6 +182,7 @@ impl de::Visitor for FieldVisitor {
|
||||||
mod tests {
|
mod tests {
|
||||||
use chrono::{UTC, Duration, Timelike};
|
use chrono::{UTC, Duration, Timelike};
|
||||||
use rustc_serialize::json::{self, Json};
|
use rustc_serialize::json::{self, Json};
|
||||||
|
use serde_json;
|
||||||
|
|
||||||
use client::response::FromResponse;
|
use client::response::FromResponse;
|
||||||
use super::Expiring;
|
use super::Expiring;
|
||||||
|
@ -218,4 +219,15 @@ mod tests {
|
||||||
let decoded = json::decode(&json).unwrap();
|
let decoded = json::decode(&json).unwrap();
|
||||||
assert_eq!(expiring, decoded);
|
assert_eq!(expiring, decoded);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn serialize_deserialize() {
|
||||||
|
let original = Expiring {
|
||||||
|
refresh_token: String::from("foo"),
|
||||||
|
expires: UTC::now().with_nanosecond(0).unwrap(),
|
||||||
|
};
|
||||||
|
let serialized = serde_json::to_value(&original);
|
||||||
|
let deserialized = serde_json::from_value(serialized).unwrap();
|
||||||
|
assert_eq!(original, deserialized);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,6 +39,7 @@ impl Deserialize for Static {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use rustc_serialize::json::Json;
|
use rustc_serialize::json::Json;
|
||||||
|
use serde_json;
|
||||||
|
|
||||||
use client::response::{FromResponse, ParseError};
|
use client::response::{FromResponse, ParseError};
|
||||||
use super::Static;
|
use super::Static;
|
||||||
|
@ -57,4 +58,12 @@ mod tests {
|
||||||
Static::from_response(&json).unwrap_err()
|
Static::from_response(&json).unwrap_err()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn serialize_deserialize() {
|
||||||
|
let original = Static;
|
||||||
|
let serialized = serde_json::to_value(&original);
|
||||||
|
let deserialized = serde_json::from_value(serialized).unwrap();
|
||||||
|
assert_eq!(original, deserialized);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue