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
|
/// crate was doing before the core was extracted. The Android bindings will want the
|
||||||
/// same thing.
|
/// same thing.
|
||||||
pub fn open_in_memory() -> rusqlite::Result<Db> {
|
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()?;
|
let conn = Connection::open_in_memory()?;
|
||||||
schema::migrate(&conn)?;
|
schema::migrate(&conn)?;
|
||||||
Ok(Db(Mutex::new(conn)))
|
Ok(conn)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A one-line count summary of the store, for the startup log.
|
/// A one-line count summary of the store, for the startup log.
|
||||||
|
|||||||
@@ -593,11 +593,9 @@ fn dirname(path: &str) -> &str {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::local::schema;
|
|
||||||
|
|
||||||
fn store() -> (Connection, BlobStore, std::path::PathBuf) {
|
fn store() -> (Connection, BlobStore, std::path::PathBuf) {
|
||||||
let conn = Connection::open_in_memory().unwrap();
|
let conn = crate::local::memory_conn().unwrap();
|
||||||
schema::migrate(&conn).unwrap();
|
|
||||||
let dir = std::env::temp_dir().join(format!("inkwell-portable-{}", uuid::Uuid::new_v4()));
|
let dir = std::env::temp_dir().join(format!("inkwell-portable-{}", uuid::Uuid::new_v4()));
|
||||||
let blobs = BlobStore::new(dir.clone()).unwrap();
|
let blobs = BlobStore::new(dir.clone()).unwrap();
|
||||||
(conn, blobs, dir)
|
(conn, blobs, dir)
|
||||||
|
|||||||
@@ -80,12 +80,9 @@ pub fn sweep_if_unlinked(conn: &Connection) -> rusqlite::Result<Option<usize>> {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::local::schema;
|
|
||||||
|
|
||||||
fn db() -> Connection {
|
fn db() -> Connection {
|
||||||
let conn = Connection::open_in_memory().expect("in-memory db");
|
crate::local::memory_conn().expect("in-memory db")
|
||||||
schema::migrate(&conn).expect("migrate");
|
|
||||||
conn
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A trashed note of a given age, stamped in the format the CLIENT writes
|
/// 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.
|
//! against a real schema catches, which is what every test here runs.
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::local::schema;
|
|
||||||
|
|
||||||
fn db() -> Connection {
|
fn db() -> Connection {
|
||||||
let conn = Connection::open_in_memory().expect("in-memory db");
|
crate::local::memory_conn().expect("in-memory db")
|
||||||
schema::migrate(&conn).expect("migrate");
|
|
||||||
conn
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn note(conn: &Connection, body: &str) -> Note {
|
fn note(conn: &Connection, body: &str) -> Note {
|
||||||
|
|||||||
@@ -507,12 +507,9 @@ pub async fn run(
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::local::schema;
|
|
||||||
|
|
||||||
fn db() -> Connection {
|
fn db() -> Connection {
|
||||||
let conn = Connection::open_in_memory().expect("in-memory db");
|
crate::local::memory_conn().expect("in-memory db")
|
||||||
schema::migrate(&conn).expect("migrate");
|
|
||||||
conn
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn note(id: &str, revision: i64) -> wire::Note {
|
fn note(id: &str, revision: i64) -> wire::Note {
|
||||||
|
|||||||
@@ -702,13 +702,10 @@ pub fn parse_results(raw: &str) -> Result<Vec<PushResult>, String> {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::local::schema;
|
|
||||||
use crate::local::store;
|
use crate::local::store;
|
||||||
|
|
||||||
fn db() -> Connection {
|
fn db() -> Connection {
|
||||||
let conn = Connection::open_in_memory().expect("in-memory db");
|
crate::local::memory_conn().expect("in-memory db")
|
||||||
schema::migrate(&conn).expect("migrate");
|
|
||||||
conn
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn seed_note(conn: &Connection, id: &str, dirty: i64) {
|
fn seed_note(conn: &Connection, id: &str, dirty: i64) {
|
||||||
|
|||||||
@@ -85,15 +85,10 @@ pub async fn unshare(
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::local::schema;
|
|
||||||
use crate::sync::client::Member;
|
use crate::sync::client::Member;
|
||||||
use rusqlite::Connection;
|
|
||||||
use std::sync::Mutex;
|
|
||||||
|
|
||||||
fn db() -> Db {
|
fn db() -> Db {
|
||||||
let conn = Connection::open_in_memory().expect("in-memory db");
|
crate::local::open_in_memory().expect("in-memory db")
|
||||||
schema::migrate(&conn).expect("migrate");
|
|
||||||
Db(Mutex::new(conn))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
@@ -308,12 +308,9 @@ pub fn status(conn: &Connection) -> rusqlite::Result<Status> {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::local::schema;
|
|
||||||
|
|
||||||
fn db() -> Connection {
|
fn db() -> Connection {
|
||||||
let conn = Connection::open_in_memory().expect("in-memory db");
|
crate::local::memory_conn().expect("in-memory db")
|
||||||
schema::migrate(&conn).expect("migrate");
|
|
||||||
conn
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
Reference in New Issue
Block a user