Core tests open their store through local::memory_conn
Seven test modules each built a migrated in-memory store by hand: open, migrate, and (in sharing) wrap it in a Db. local::memory_conn() is that, and open_in_memory uses it too. Each module's db() is now one line, and the schema, Connection and Mutex imports it needed are gone. DRY pass #2, batch 2, F9 (#5372). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -77,9 +77,15 @@ pub fn open(path: &Path) -> rusqlite::Result<Db> {
|
||||
/// crate was doing before the core was extracted. The Android bindings will want the
|
||||
/// same thing.
|
||||
pub fn open_in_memory() -> rusqlite::Result<Db> {
|
||||
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<Connection> {
|
||||
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.
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -80,12 +80,9 @@ pub fn sweep_if_unlinked(conn: &Connection) -> rusqlite::Result<Option<usize>> {
|
||||
#[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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user