Add tests for secret.rs

Signed-off-by: constantoine <cleo.rebert-ext@treezor.com>
This commit is contained in:
constantoine 2022-10-10 10:22:52 +02:00
parent 3f39b3a1ba
commit b308f7455d
No known key found for this signature in database
GPG Key ID: 0FA097951CF65367
1 changed files with 24 additions and 0 deletions

View File

@ -242,4 +242,28 @@ mod tests {
Secret::Encoded(_) => panic!("should be raw"),
}
}
#[test]
#[cfg(feature = "gen_secret")]
fn secret_gen_default() {
match Secret::default() {
Secret::Raw(secret) => assert_eq!(secret.len(), 20),
Secret::Encoded(_) => panic!("should be raw"),
}
}
#[test]
#[cfg(feature = "gen_secret")]
fn secret_empty() {
let non_ascii = vec![240, 159, 146, 150];
let sec = Secret::Encoded(std::str::from_utf8(&non_ascii).unwrap().to_owned());
let to_r = sec.to_raw();
assert!(to_r.is_err());
let to_b = sec.to_bytes();
assert!(to_b.is_err());
}
}