Test serde de/serialization of tokens

This commit is contained in:
Curtis McEnroe 2016-01-25 23:06:44 -05:00
parent ba5b74c698
commit 3cf2af8609
5 changed files with 38 additions and 0 deletions

View File

@ -20,4 +20,5 @@ serde = "0.6.1"
url = "0.5.0"
[dev-dependencies]
serde_json = "0.6.0"
yup-hyper-mock = "1.3.2"

View File

@ -149,3 +149,6 @@ pub mod token;
pub mod provider;
pub mod error;
pub mod client;
#[cfg(test)]
extern crate serde_json;

View File

@ -157,6 +157,7 @@ impl de::Visitor for FieldVisitor {
mod tests {
use chrono::{UTC, Duration};
use rustc_serialize::json::Json;
use serde_json;
use client::response::{FromResponse, ParseError};
use token::{Static, Expiring};
@ -258,4 +259,16 @@ mod tests {
assert!(expiring.expires() > &UTC::now());
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);
}
}

View File

@ -182,6 +182,7 @@ impl de::Visitor for FieldVisitor {
mod tests {
use chrono::{UTC, Duration, Timelike};
use rustc_serialize::json::{self, Json};
use serde_json;
use client::response::FromResponse;
use super::Expiring;
@ -218,4 +219,15 @@ mod tests {
let decoded = json::decode(&json).unwrap();
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);
}
}

View File

@ -39,6 +39,7 @@ impl Deserialize for Static {
#[cfg(test)]
mod tests {
use rustc_serialize::json::Json;
use serde_json;
use client::response::{FromResponse, ParseError};
use super::Static;
@ -57,4 +58,12 @@ mod tests {
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);
}
}