diff --git a/Cargo.lock b/Cargo.lock index c038707..f8afa75 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1088,6 +1088,7 @@ version = "0.1.0" dependencies = [ "async-std", "config", + "rand 0.7.3", "serde", "serial_test", "tempfile", diff --git a/Cargo.toml b/Cargo.toml index 90d7dc3..fadb1d6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,6 +9,7 @@ edition = "2021" #async-graphql = "*" async-std = { version = "*", features = ["attributes"] } config = "*" +rand = "*" serde = "*" tide = "*" diff --git a/src/morethantext/mod.rs b/src/morethantext/mod.rs index 1809904..f38b865 100644 --- a/src/morethantext/mod.rs +++ b/src/morethantext/mod.rs @@ -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.") } }