Added random cache ids.

This commit is contained in:
2022-12-04 11:09:56 -05:00
parent 14c6c9dffe
commit 47b9a071a4
3 changed files with 12 additions and 5 deletions

View File

@ -1,7 +1,8 @@
pub mod error;
use async_std::{fs::create_dir, path::Path};
use async_std::{fs::create_dir, path::Path};
use error::DBError;
use rand::{distributions::Alphanumeric, thread_rng, Rng};
const DATA: &str = "data";
@ -29,7 +30,8 @@ impl MoreThanText {
}
async fn add_entry(&self, _entry: CacheEntry) -> String {
"fred".to_string()
let id: String = thread_rng().sample_iter(&Alphanumeric).take(32).collect();
return id;
}
}
@ -100,9 +102,12 @@ mod cache {
use setup::MTT;
#[async_std::test]
async fn add_entry() {
async fn ids_are_random() {
let mtt = MTT::new().await;
let data = CacheEntry::Raw("something".to_string());
mtt.db.add_entry(data).await;
let data1 = CacheEntry::Raw("one".to_string());
let data2 = CacheEntry::Raw("two".to_string());
let id1 = mtt.db.add_entry(data1).await;
let id2 = mtt.db.add_entry(data2).await;
assert_ne!(id1, id2, "Ids should be unique.")
}
}