|
|
|
@ -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.")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|