mirror of
https://github.com/PR0M3TH3AN/Marlin.git
synced 2025-09-09 07:38:50 +00:00
Add unit tests for CLI run functions
This commit is contained in:
30
cli-bin/tests/cli_coll_unit.rs
Normal file
30
cli-bin/tests/cli_coll_unit.rs
Normal file
@@ -0,0 +1,30 @@
|
||||
mod cli {
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub enum Format { Text, Json }
|
||||
}
|
||||
|
||||
#[path = "../src/cli/coll.rs"]
|
||||
mod coll;
|
||||
|
||||
use libmarlin::db;
|
||||
|
||||
#[test]
|
||||
fn coll_run_creates_and_adds() {
|
||||
let mut conn = db::open(":memory:").unwrap();
|
||||
conn.execute("INSERT INTO files(path,size,mtime) VALUES ('a.txt',0,0)", []).unwrap();
|
||||
conn.execute("INSERT INTO files(path,size,mtime) VALUES ('b.txt',0,0)", []).unwrap();
|
||||
|
||||
let create = coll::CollCmd::Create(coll::CreateArgs{ name: "Set".into() });
|
||||
coll::run(&create, &mut conn, cli::Format::Text).unwrap();
|
||||
|
||||
let coll_id: i64 = conn.query_row("SELECT id FROM collections WHERE name='Set'", [], |r| r.get(0)).unwrap();
|
||||
|
||||
let add = coll::CollCmd::Add(coll::AddArgs{ name: "Set".into(), file_pattern: "*.txt".into() });
|
||||
coll::run(&add, &mut conn, cli::Format::Text).unwrap();
|
||||
|
||||
let cnt: i64 = conn.query_row("SELECT COUNT(*) FROM collection_files WHERE collection_id=?1", [coll_id], |r| r.get(0)).unwrap();
|
||||
assert_eq!(cnt, 2);
|
||||
|
||||
let list = coll::CollCmd::List(coll::ListArgs{ name: "Set".into() });
|
||||
coll::run(&list, &mut conn, cli::Format::Text).unwrap();
|
||||
}
|
Reference in New Issue
Block a user