Merge pull request #27 from PR0M3TH3AN/codex/extend-db_tests.rs-with-file_id-tests

Add tests for db::file_id
This commit is contained in:
thePR0M3TH3AN
2025-05-21 08:35:38 -04:00
committed by GitHub

View File

@@ -77,6 +77,30 @@ fn upsert_attr_inserts_and_updates() {
assert_eq!(v2, "v2");
}
#[test]
fn file_id_returns_id_and_errors_on_missing() {
let conn = open_mem();
// insert a single file
conn.execute(
"INSERT INTO files(path, size, mtime) VALUES (?1, 0, 0)",
["exist.txt"],
)
.unwrap();
// fetch its id via raw SQL
let fid: i64 = conn
.query_row("SELECT id FROM files WHERE path='exist.txt'", [], |r| r.get(0))
.unwrap();
// db::file_id should return the same id for existing paths
let looked_up = db::file_id(&conn, "exist.txt").unwrap();
assert_eq!(looked_up, fid);
// querying a missing path should yield an error
assert!(db::file_id(&conn, "missing.txt").is_err());
}
#[test]
fn add_and_remove_links_and_backlinks() {
let conn = open_mem();