mirror of
https://github.com/PR0M3TH3AN/Marlin.git
synced 2025-09-08 07:08:44 +00:00
test: cover db::file_id
This commit is contained in:
@@ -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();
|
||||
|
Reference in New Issue
Block a user