diff --git a/Cargo.lock b/Cargo.lock index d2fb785f..8e72731b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3428,6 +3428,7 @@ dependencies = [ "itertools", "libsqlite3-sys", "log", + "rand 0.8.1", "serde", "serde_json", "simplelog", diff --git a/vit-servicing-station-lib/Cargo.toml b/vit-servicing-station-lib/Cargo.toml index f689f229..313f654c 100644 --- a/vit-servicing-station-lib/Cargo.toml +++ b/vit-servicing-station-lib/Cargo.toml @@ -36,3 +36,4 @@ libsqlite3-sys = { version = "0.9.3", features = ["bundled"] } [dev-dependencies] tempfile = "3" +rand = "0.8" diff --git a/vit-servicing-station-lib/src/v0/context.rs b/vit-servicing-station-lib/src/v0/context.rs index aa8fbc6e..510256e5 100644 --- a/vit-servicing-station-lib/src/v0/context.rs +++ b/vit-servicing-station-lib/src/v0/context.rs @@ -36,11 +36,19 @@ pub fn new_shared_context( #[cfg(test)] pub mod test { + use rand::{distributions::Alphanumeric, thread_rng, Rng}; + use super::*; use crate::db; pub fn new_in_memmory_db_test_shared_context() -> SharedContext { - let pool = db::load_db_connection_pool("").unwrap(); + let name: String = thread_rng() + .sample_iter(Alphanumeric) + .take(5) + .map(char::from) + .collect(); + let db_url = format!("file:{}?mode=memory&cache=shared", name); + let pool = db::load_db_connection_pool(&db_url).unwrap(); let block0: Vec = vec![1, 2, 3, 4, 5]; Arc::new(RwLock::new(Context::new(pool, "", block0))) }