Core tests make a throwaway blob store with blobs::scratch
blobs, store and portable each built a BlobStore in a temp directory their own way: pid+tag twice, a uuid once. blobs::scratch(tag) is that, with a counter, so two tests can never share a directory even if they pick the same tag. The desktop's and ffi's temp-dir helpers stay, one per crate: sharing them would need a test-util feature on the core crate. DRY pass #2, batch 2, F9 (#5372). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1810,12 +1810,6 @@ mod tests {
|
||||
assert_eq!(list_labels(&conn).expect("labels")[0].count, Some(1));
|
||||
}
|
||||
|
||||
fn blobs(tag: &str) -> crate::sync::blobs::BlobStore {
|
||||
let dir = std::env::temp_dir().join(format!("ts-store-blobs-{}-{tag}", std::process::id()));
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
crate::sync::blobs::BlobStore::new(dir).expect("blobs")
|
||||
}
|
||||
|
||||
fn tombstones(conn: &Connection) -> Vec<(String, String)> {
|
||||
let mut stmt = conn
|
||||
.prepare("SELECT entity, id FROM pending_deletes ORDER BY entity, id")
|
||||
@@ -1829,7 +1823,7 @@ mod tests {
|
||||
#[test]
|
||||
fn an_attached_file_is_kept_here_and_queued_to_upload() {
|
||||
let conn = db();
|
||||
let blobs = blobs("attach");
|
||||
let blobs = crate::sync::blobs::scratch("attach");
|
||||
let n = note(&conn, "with a receipt");
|
||||
conn.execute("UPDATE notes SET dirty = 0", [])
|
||||
.expect("clean");
|
||||
@@ -1873,7 +1867,7 @@ mod tests {
|
||||
#[test]
|
||||
fn attaching_to_a_note_that_is_gone_writes_nothing() {
|
||||
let conn = db();
|
||||
let blobs = blobs("gone");
|
||||
let blobs = crate::sync::blobs::scratch("gone");
|
||||
assert!(add_attachment(&conn, &blobs, "missing", "a.txt", "text/plain", b"hi").is_err());
|
||||
let rows: i64 = conn
|
||||
.query_row("SELECT COUNT(*) FROM attachments", [], |r| r.get(0))
|
||||
@@ -1886,7 +1880,7 @@ mod tests {
|
||||
#[test]
|
||||
fn only_a_file_the_server_holds_leaves_a_tombstone_when_removed() {
|
||||
let conn = db();
|
||||
let blobs = blobs("remove");
|
||||
let blobs = crate::sync::blobs::scratch("remove");
|
||||
let n = note(&conn, "two files");
|
||||
conn.execute(
|
||||
"INSERT INTO attachments (id, note_id, url) VALUES ('synced', ?1, '/x')",
|
||||
|
||||
Reference in New Issue
Block a user