DRY pass #3: core tests open their store and seed a label one way (#5373)

Five test modules wrote the same db() over memory_conn, and portable.rs
unwrapped it inline; local::test_db() is that. Four pull/push tests wrote the
same label INSERT; local::seed_label(conn, id, name, dirty) is it. Both are
cfg(test), beside memory_conn, as wire::sample_note is beside wire::Note.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-08 15:17:30 -04:00
co-authored by Claude Opus 5.5
parent 1b128a9374
commit 78810d8832
7 changed files with 27 additions and 40 deletions
+17
View File
@@ -88,6 +88,23 @@ pub(crate) fn memory_conn() -> rusqlite::Result<Connection> {
Ok(conn)
}
/// A test's store: [`memory_conn`], which can't fail on a fresh in-memory database.
#[cfg(test)]
pub(crate) fn test_db() -> Connection {
memory_conn().expect("in-memory db")
}
/// A label this device holds, by id and name, for tests that need one in place.
#[cfg(test)]
pub(crate) fn seed_label(conn: &Connection, id: &str, name: &str, dirty: i64) {
conn.execute(
"INSERT INTO labels (id, name, color, created_at, updated_at, dirty)
VALUES (?1, ?2, 'default', '2026-01-01', '2026-01-01', ?3)",
rusqlite::params![id, name, dirty],
)
.expect("seed label");
}
/// A one-line count summary of the store, for the startup log.
pub fn summary(db: &Db) -> String {
let conn = match db.conn() {
+1 -1
View File
@@ -595,7 +595,7 @@ mod tests {
use super::*;
fn store() -> (Connection, BlobStore, std::path::PathBuf) {
let conn = crate::local::memory_conn().unwrap();
let conn = crate::local::test_db();
let blobs = crate::sync::blobs::scratch("portable");
let dir = blobs.root().to_path_buf();
(conn, blobs, dir)
+1 -3
View File
@@ -81,9 +81,7 @@ pub fn sweep_if_unlinked(conn: &Connection) -> rusqlite::Result<Option<usize>> {
mod tests {
use super::*;
fn db() -> Connection {
crate::local::memory_conn().expect("in-memory db")
}
use crate::local::test_db as db;
/// A trashed note of a given age, stamped in the format the CLIENT writes
/// (`...Z`, millisecond precision — see `store::now`).
+1 -3
View File
@@ -1123,9 +1123,7 @@ mod tests {
use super::*;
fn db() -> Connection {
crate::local::memory_conn().expect("in-memory db")
}
use crate::local::test_db as db;
fn note(conn: &Connection, body: &str) -> Note {
create_note(