We don't need to repeatedly recreate the doc

master
Paul Woolcock 6 years ago
parent a05a67f3cb
commit 42d3a935c8
  1. 42
      src/helpers/toml.rs

@ -83,9 +83,7 @@ mod tests {
use std::{fs::OpenOptions, io::Cursor}; use std::{fs::OpenOptions, io::Cursor};
use tempfile::{tempdir, NamedTempFile}; use tempfile::{tempdir, NamedTempFile};
#[test] const DOC: &'static str = indoc!(
fn test_from_str() {
let doc = indoc!(
r#" r#"
base = "https://example.com" base = "https://example.com"
client_id = "adbc01234" client_id = "adbc01234"
@ -94,7 +92,10 @@ mod tests {
token = "fedc5678" token = "fedc5678"
"# "#
); );
let desered = from_str(&doc).expect("Couldn't deserialize Data");
#[test]
fn test_from_str() {
let desered = from_str(DOC).expect("Couldn't deserialize Data");
assert_eq!( assert_eq!(
desered, desered,
Data { Data {
@ -108,16 +109,7 @@ mod tests {
} }
#[test] #[test]
fn test_from_slice() { fn test_from_slice() {
let doc = indoc!( let doc = DOC.as_bytes();
r#"
base = "https://example.com"
client_id = "adbc01234"
client_secret = "0987dcba"
redirect = "urn:ietf:wg:oauth:2.0:oob"
token = "fedc5678"
"#
);
let doc = doc.as_bytes();
let desered = from_slice(&doc).expect("Couldn't deserialize Data"); let desered = from_slice(&doc).expect("Couldn't deserialize Data");
assert_eq!( assert_eq!(
desered, desered,
@ -132,16 +124,7 @@ mod tests {
} }
#[test] #[test]
fn test_from_reader() { fn test_from_reader() {
let doc = indoc!( let doc = DOC.as_bytes();
r#"
base = "https://example.com"
client_id = "adbc01234"
client_secret = "0987dcba"
redirect = "urn:ietf:wg:oauth:2.0:oob"
token = "fedc5678"
"#
);
let doc = doc.as_bytes();
let doc = Cursor::new(doc); let doc = Cursor::new(doc);
let desered = from_reader(doc).expect("Couldn't deserialize Data"); let desered = from_reader(doc).expect("Couldn't deserialize Data");
assert_eq!( assert_eq!(
@ -157,17 +140,8 @@ mod tests {
} }
#[test] #[test]
fn test_from_file() { fn test_from_file() {
let doc = indoc!(
r#"
base = "https://example.com"
client_id = "adbc01234"
client_secret = "0987dcba"
redirect = "urn:ietf:wg:oauth:2.0:oob"
token = "fedc5678"
"#
);
let mut datafile = NamedTempFile::new().expect("Couldn't create tempfile"); let mut datafile = NamedTempFile::new().expect("Couldn't create tempfile");
write!(&mut datafile, "{}", doc).expect("Couldn't write Data to file"); write!(&mut datafile, "{}", DOC).expect("Couldn't write Data to file");
let desered = from_file(datafile.path()).expect("Couldn't deserialize Data"); let desered = from_file(datafile.path()).expect("Couldn't deserialize Data");
assert_eq!( assert_eq!(
desered, desered,

Loading…
Cancel
Save