diff --git a/core/src/local/mod.rs b/core/src/local/mod.rs index 6db4203..2b4e2a4 100644 --- a/core/src/local/mod.rs +++ b/core/src/local/mod.rs @@ -77,9 +77,15 @@ pub fn open(path: &Path) -> rusqlite::Result { /// crate was doing before the core was extracted. The Android bindings will want the /// same thing. pub fn open_in_memory() -> rusqlite::Result { + Ok(Db(Mutex::new(memory_conn()?))) +} + +/// A migrated, in-memory connection: [`open_in_memory`]'s, and every core test's +/// store. +pub(crate) fn memory_conn() -> rusqlite::Result { let conn = Connection::open_in_memory()?; schema::migrate(&conn)?; - Ok(Db(Mutex::new(conn))) + Ok(conn) } /// A one-line count summary of the store, for the startup log. diff --git a/core/src/local/portable.rs b/core/src/local/portable.rs index 5e41756..2c5a5b8 100644 --- a/core/src/local/portable.rs +++ b/core/src/local/portable.rs @@ -593,11 +593,9 @@ fn dirname(path: &str) -> &str { #[cfg(test)] mod tests { use super::*; - use crate::local::schema; fn store() -> (Connection, BlobStore, std::path::PathBuf) { - let conn = Connection::open_in_memory().unwrap(); - schema::migrate(&conn).unwrap(); + let conn = crate::local::memory_conn().unwrap(); let dir = std::env::temp_dir().join(format!("inkwell-portable-{}", uuid::Uuid::new_v4())); let blobs = BlobStore::new(dir.clone()).unwrap(); (conn, blobs, dir) diff --git a/core/src/local/retention.rs b/core/src/local/retention.rs index 137a5c5..95dfd9f 100644 --- a/core/src/local/retention.rs +++ b/core/src/local/retention.rs @@ -80,12 +80,9 @@ pub fn sweep_if_unlinked(conn: &Connection) -> rusqlite::Result> { #[cfg(test)] mod tests { use super::*; - use crate::local::schema; fn db() -> Connection { - let conn = Connection::open_in_memory().expect("in-memory db"); - schema::migrate(&conn).expect("migrate"); - conn + crate::local::memory_conn().expect("in-memory db") } /// A trashed note of a given age, stamped in the format the CLIENT writes diff --git a/core/src/local/store.rs b/core/src/local/store.rs index 14a71bc..b8e49af 100644 --- a/core/src/local/store.rs +++ b/core/src/local/store.rs @@ -1143,12 +1143,9 @@ mod tests { //! against a real schema catches, which is what every test here runs. use super::*; - use crate::local::schema; fn db() -> Connection { - let conn = Connection::open_in_memory().expect("in-memory db"); - schema::migrate(&conn).expect("migrate"); - conn + crate::local::memory_conn().expect("in-memory db") } fn note(conn: &Connection, body: &str) -> Note { diff --git a/core/src/sync/pull.rs b/core/src/sync/pull.rs index 94fa2ca..1d80ed4 100644 --- a/core/src/sync/pull.rs +++ b/core/src/sync/pull.rs @@ -507,12 +507,9 @@ pub async fn run( #[cfg(test)] mod tests { use super::*; - use crate::local::schema; fn db() -> Connection { - let conn = Connection::open_in_memory().expect("in-memory db"); - schema::migrate(&conn).expect("migrate"); - conn + crate::local::memory_conn().expect("in-memory db") } fn note(id: &str, revision: i64) -> wire::Note { diff --git a/core/src/sync/push.rs b/core/src/sync/push.rs index c26d7df..9aa3305 100644 --- a/core/src/sync/push.rs +++ b/core/src/sync/push.rs @@ -702,13 +702,10 @@ pub fn parse_results(raw: &str) -> Result, String> { #[cfg(test)] mod tests { use super::*; - use crate::local::schema; use crate::local::store; fn db() -> Connection { - let conn = Connection::open_in_memory().expect("in-memory db"); - schema::migrate(&conn).expect("migrate"); - conn + crate::local::memory_conn().expect("in-memory db") } fn seed_note(conn: &Connection, id: &str, dirty: i64) { diff --git a/core/src/sync/sharing.rs b/core/src/sync/sharing.rs index 61fa751..ce14c79 100644 --- a/core/src/sync/sharing.rs +++ b/core/src/sync/sharing.rs @@ -85,15 +85,10 @@ pub async fn unshare( #[cfg(test)] mod tests { use super::*; - use crate::local::schema; use crate::sync::client::Member; - use rusqlite::Connection; - use std::sync::Mutex; fn db() -> Db { - let conn = Connection::open_in_memory().expect("in-memory db"); - schema::migrate(&conn).expect("migrate"); - Db(Mutex::new(conn)) + crate::local::open_in_memory().expect("in-memory db") } #[test] diff --git a/core/src/sync/state.rs b/core/src/sync/state.rs index 5db0a71..01a6281 100644 --- a/core/src/sync/state.rs +++ b/core/src/sync/state.rs @@ -308,12 +308,9 @@ pub fn status(conn: &Connection) -> rusqlite::Result { #[cfg(test)] mod tests { use super::*; - use crate::local::schema; fn db() -> Connection { - let conn = Connection::open_in_memory().expect("in-memory db"); - schema::migrate(&conn).expect("migrate"); - conn + crate::local::memory_conn().expect("in-memory db") } #[test]