mirror of
https://github.com/elicpeter/nyx.git
synced 2026-06-27 20:29:39 +02:00
test: Add unit tests for index building and scanning functionality (#9)
This commit is contained in:
parent
46c4732f6e
commit
72ca7fa45d
3 changed files with 92 additions and 0 deletions
|
|
@ -129,3 +129,30 @@ pub fn build_index(
|
|||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn build_index_creates_db_and_registers_files() {
|
||||
let mut cfg = Config::default();
|
||||
cfg.performance.worker_threads = Some(1);
|
||||
cfg.performance.channel_multiplier = 1;
|
||||
cfg.performance.batch_size = 2;
|
||||
|
||||
let td = tempfile::tempdir().unwrap();
|
||||
let project_dir = td.path().join("proj");
|
||||
fs::create_dir(&project_dir).unwrap();
|
||||
let f_txt = project_dir.join("readme.txt");
|
||||
fs::write(&f_txt, "hello").unwrap();
|
||||
|
||||
let db_path = td.path().join("proj.sqlite");
|
||||
|
||||
build_index("proj", &project_dir, &db_path, &cfg).expect("index build should succeed");
|
||||
|
||||
// ── Assert ────────────────────────────────────────────────────────────────
|
||||
assert!(db_path.is_file(), "SQLite file must exist");
|
||||
|
||||
let pool = Indexer::init(&db_path).unwrap();
|
||||
let idx = Indexer::from_pool("proj", &pool).unwrap();
|
||||
let files = idx.get_files("proj").unwrap();
|
||||
assert_eq!(files.len(), 1, "exactly one file indexed");
|
||||
assert_eq!(files[0], f_txt);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -165,3 +165,35 @@ pub fn scan_with_index_parallel(
|
|||
|
||||
Ok(diags)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn scan_with_index_parallel_uses_existing_index_without_rescanning() {
|
||||
let mut cfg = Config::default();
|
||||
cfg.performance.worker_threads = Some(1);
|
||||
cfg.performance.channel_multiplier = 1;
|
||||
cfg.performance.batch_size = 2;
|
||||
|
||||
let td = tempfile::tempdir().unwrap();
|
||||
let project_dir = td.path().join("proj");
|
||||
std::fs::create_dir(&project_dir).unwrap();
|
||||
std::fs::write(project_dir.join("foo.txt"), "abc").unwrap();
|
||||
|
||||
let (project_name, db_path) = get_project_info(&project_dir, td.path()).unwrap();
|
||||
crate::commands::index::build_index(&project_name, &project_dir, &db_path, &cfg).unwrap();
|
||||
|
||||
let pool = Indexer::init(&db_path).unwrap();
|
||||
|
||||
assert_eq!(
|
||||
Indexer::from_pool(&project_name, &pool)
|
||||
.unwrap()
|
||||
.get_files(&project_name)
|
||||
.unwrap()
|
||||
.len(),
|
||||
1
|
||||
);
|
||||
|
||||
let diags = scan_with_index_parallel(&project_name, Arc::clone(&pool), &cfg)
|
||||
.expect("scan should succeed");
|
||||
|
||||
assert!(diags.is_empty());
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue