Rewrite tests to use snapshots.
This commit is contained in:
parent
430b653a2c
commit
1f25982b84
58
tests/lib.rs
58
tests/lib.rs
|
@ -1,49 +1,41 @@
|
||||||
use gravatar_rs::Generator;
|
use gravatar_rs::Generator;
|
||||||
|
|
||||||
const BAUKE_EMAIL: &str = "me@bauke.xyz";
|
const BAUKE_EMAIL: &str = "me@bauke.xyz";
|
||||||
const BAUKE_HASH: &str = "ecd836ee843ff0ab75d4720bd40c2baf";
|
|
||||||
|
|
||||||
const HOLLLO_EMAIL: &str = "helllo@holllo.cc";
|
const HOLLLO_EMAIL: &str = "helllo@holllo.cc";
|
||||||
const HOLLLO_HASH: &str = "ebff9105dce4954b1bdb57fdab079ff3";
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_hash_email() {
|
fn test_hash_email() {
|
||||||
assert_eq!(Generator::hash_email(BAUKE_EMAIL), BAUKE_HASH);
|
let samples = [("bauke", BAUKE_EMAIL), ("holllo", HOLLLO_EMAIL)];
|
||||||
assert_eq!(Generator::hash_email(HOLLLO_EMAIL), HOLLLO_HASH);
|
|
||||||
|
|
||||||
// Make sure leading and trailing whitespace is removed.
|
for (name, email) in samples {
|
||||||
assert_eq!(
|
insta::assert_snapshot!(
|
||||||
Generator::hash_email(&format!(" {BAUKE_EMAIL} ")),
|
format!("hash-{name}"),
|
||||||
BAUKE_HASH
|
Generator::hash_email(email)
|
||||||
);
|
);
|
||||||
assert_eq!(
|
|
||||||
Generator::hash_email(&format!(" {HOLLLO_EMAIL} ")),
|
|
||||||
HOLLLO_HASH
|
|
||||||
);
|
|
||||||
|
|
||||||
// Make sure casing doesn't matter.
|
insta::assert_snapshot!(
|
||||||
assert_eq!(
|
format!("hash-{name}-whitespace"),
|
||||||
Generator::hash_email(&BAUKE_EMAIL.to_uppercase()),
|
Generator::hash_email(&format!(" {email} "))
|
||||||
BAUKE_HASH
|
);
|
||||||
);
|
|
||||||
assert_eq!(
|
insta::assert_snapshot!(
|
||||||
Generator::hash_email(&HOLLLO_EMAIL.to_uppercase()),
|
format!("hash-{name}-casing"),
|
||||||
HOLLLO_HASH
|
Generator::hash_email(&email.to_uppercase())
|
||||||
);
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_generator() {
|
fn test_generator() {
|
||||||
let base_urls = [&Generator::default().base_url, "cdn.libravatar.org"];
|
let emails = [BAUKE_EMAIL, HOLLLO_EMAIL];
|
||||||
let samples = [(BAUKE_EMAIL, BAUKE_HASH), (HOLLLO_EMAIL, HOLLLO_HASH)];
|
let samples = [
|
||||||
|
("gravatar", Generator::default().base_url),
|
||||||
|
("libravatar", "cdn.libravatar.org".to_string()),
|
||||||
|
];
|
||||||
|
|
||||||
for base_url in base_urls {
|
for (name, base_url) in samples {
|
||||||
let generator = Generator::default().set_base_url(base_url);
|
let generator = Generator::default().set_base_url(&base_url);
|
||||||
|
let urls = emails.map(|email| generator.generate(email));
|
||||||
for (email, hash) in samples {
|
insta::assert_debug_snapshot!(format!("generate-{name}"), urls);
|
||||||
let actual = generator.generate(email);
|
|
||||||
let expected = format!("https://{base_url}/avatar/{hash}");
|
|
||||||
assert_eq!(actual, expected);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
---
|
||||||
|
source: tests/lib.rs
|
||||||
|
expression: urls
|
||||||
|
---
|
||||||
|
[
|
||||||
|
"https://www.gravatar.com/avatar/ecd836ee843ff0ab75d4720bd40c2baf",
|
||||||
|
"https://www.gravatar.com/avatar/ebff9105dce4954b1bdb57fdab079ff3",
|
||||||
|
]
|
|
@ -0,0 +1,8 @@
|
||||||
|
---
|
||||||
|
source: tests/lib.rs
|
||||||
|
expression: urls
|
||||||
|
---
|
||||||
|
[
|
||||||
|
"https://cdn.libravatar.org/avatar/ecd836ee843ff0ab75d4720bd40c2baf",
|
||||||
|
"https://cdn.libravatar.org/avatar/ebff9105dce4954b1bdb57fdab079ff3",
|
||||||
|
]
|
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
source: tests/lib.rs
|
||||||
|
expression: "Generator::hash_email(&email.to_uppercase())"
|
||||||
|
---
|
||||||
|
ecd836ee843ff0ab75d4720bd40c2baf
|
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
source: tests/lib.rs
|
||||||
|
expression: "Generator::hash_email(&format!(\" {email} \"))"
|
||||||
|
---
|
||||||
|
ecd836ee843ff0ab75d4720bd40c2baf
|
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
source: tests/lib.rs
|
||||||
|
expression: "Generator::hash_email(email)"
|
||||||
|
---
|
||||||
|
ecd836ee843ff0ab75d4720bd40c2baf
|
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
source: tests/lib.rs
|
||||||
|
expression: "Generator::hash_email(&email.to_uppercase())"
|
||||||
|
---
|
||||||
|
ebff9105dce4954b1bdb57fdab079ff3
|
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
source: tests/lib.rs
|
||||||
|
expression: "Generator::hash_email(&format!(\" {email} \"))"
|
||||||
|
---
|
||||||
|
ebff9105dce4954b1bdb57fdab079ff3
|
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
source: tests/lib.rs
|
||||||
|
expression: "Generator::hash_email(email)"
|
||||||
|
---
|
||||||
|
ebff9105dce4954b1bdb57fdab079ff3
|
Loading…
Reference in New Issue