Added random cache ids.
This commit is contained in:
parent
14c6c9dffe
commit
47b9a071a4
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -1088,6 +1088,7 @@ version = "0.1.0"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"async-std",
|
"async-std",
|
||||||
"config",
|
"config",
|
||||||
|
"rand 0.7.3",
|
||||||
"serde",
|
"serde",
|
||||||
"serial_test",
|
"serial_test",
|
||||||
"tempfile",
|
"tempfile",
|
||||||
|
@ -9,6 +9,7 @@ edition = "2021"
|
|||||||
#async-graphql = "*"
|
#async-graphql = "*"
|
||||||
async-std = { version = "*", features = ["attributes"] }
|
async-std = { version = "*", features = ["attributes"] }
|
||||||
config = "*"
|
config = "*"
|
||||||
|
rand = "*"
|
||||||
serde = "*"
|
serde = "*"
|
||||||
tide = "*"
|
tide = "*"
|
||||||
|
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
pub mod error;
|
pub mod error;
|
||||||
use async_std::{fs::create_dir, path::Path};
|
|
||||||
|
|
||||||
|
use async_std::{fs::create_dir, path::Path};
|
||||||
use error::DBError;
|
use error::DBError;
|
||||||
|
use rand::{distributions::Alphanumeric, thread_rng, Rng};
|
||||||
|
|
||||||
const DATA: &str = "data";
|
const DATA: &str = "data";
|
||||||
|
|
||||||
@ -29,7 +30,8 @@ impl MoreThanText {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn add_entry(&self, _entry: CacheEntry) -> String {
|
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;
|
use setup::MTT;
|
||||||
|
|
||||||
#[async_std::test]
|
#[async_std::test]
|
||||||
async fn add_entry() {
|
async fn ids_are_random() {
|
||||||
let mtt = MTT::new().await;
|
let mtt = MTT::new().await;
|
||||||
let data = CacheEntry::Raw("something".to_string());
|
let data1 = CacheEntry::Raw("one".to_string());
|
||||||
mtt.db.add_entry(data).await;
|
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.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user