Skip to content

Commit

Permalink
secrets: Add unit tests to rust core
Browse files Browse the repository at this point in the history
Signed-off-by: Trae Yelovich <[email protected]>
  • Loading branch information
traeok committed Nov 1, 2023
1 parent a56f4c6 commit e177bfb
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/secrets/core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
pub mod os;
pub mod os;
mod tests;
45 changes: 45 additions & 0 deletions packages/secrets/core/src/tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#[cfg(test)]
mod tests {
use crate::os::*;

const CREDENTIALS: [(&str, &str); 5] = [
("TestASCII", "ASCII string"),
("TestUTF8", "ᚻᛖ ᚳᚹᚫᚦ ᚦᚫᛏ ᚻᛖ ᛒᚢᛞᛖ ᚩᚾ ᚦᚫᛗ ᛚᚪᚾᛞᛖ ᚾᚩᚱᚦᚹᛖᚪᚱᛞᚢᛗ ᚹᛁᚦ ᚦᚪ ᚹᛖᛥᚫ"),
("TestCharSet", "I 💔 ASCII"),
("TestUTF16", "🌞🌙🌟🌴"),
("TestCJK", "「こんにちは世界」"),
];
const SERVICE: &str = "TestKeyring";

#[test]
fn test_get_and_set() {
let service = SERVICE.to_owned();
CREDENTIALS.iter().for_each(|cred| {
let acc = cred.0.to_string();
let pw = cred.1.to_string();
set_password(&service, &acc, &pw).unwrap();
assert_eq!(get_password(&service, &acc).unwrap_or(Some("".to_owned())), Some(pw));
});
}

#[test]
fn test_query() {
let service = SERVICE.to_owned();
let mut creds: Vec<(String, String)> = vec![];
let _res = find_credentials(&service, &mut creds);
assert_eq!(creds.len(), CREDENTIALS.len());
for cred in creds.iter() {
assert_eq!(CREDENTIALS.contains(&(cred.0.as_ref(), cred.1.as_ref())), true);
}
}

#[test]
fn test_remove_creds() {
let service = SERVICE.to_owned();
CREDENTIALS.iter().for_each(|cred| {
let acc = cred.0.to_string();
delete_password(&service, &acc).unwrap();
assert_eq!(get_password(&service, &acc).unwrap(), None);
});
}
}

0 comments on commit e177bfb

Please sign in to comment.