add tests for list index and create index.

This commit is contained in:
mpostma 2021-02-03 20:20:51 +01:00
parent f988306691
commit 8d462afb79
No known key found for this signature in database
GPG Key ID: CBC8A7C1D7A28C3A
2 changed files with 41 additions and 0 deletions

View File

@ -129,3 +129,17 @@ impl IndexController for LocalIndexController {
Ok(output_meta) Ok(output_meta)
} }
} }
#[cfg(test)]
mod test {
use super::*;
use tempfile::tempdir;
use crate::make_index_controller_tests;
make_index_controller_tests!({
let options = IndexerOpts::default();
let path = tempdir().unwrap();
let size = 4096 * 100;
LocalIndexController::new(path, options, size, size).unwrap()
});
}

View File

@ -155,3 +155,30 @@ pub trait IndexController {
fn list_indexes(&self) -> anyhow::Result<Vec<IndexMetadata>>; fn list_indexes(&self) -> anyhow::Result<Vec<IndexMetadata>>;
} }
#[cfg(test)]
#[macro_use]
pub(crate) mod test {
use super::*;
#[macro_export]
macro_rules! make_index_controller_tests {
($controller_buider:block) => {
#[test]
fn test_create_and_list_indexes() {
crate::index_controller::test::create_and_list_indexes($controller_buider);
}
};
}
pub(crate) fn create_and_list_indexes<S: IndexController>(controller: S) {
controller.create_index("test_index").unwrap();
controller.create_index("test_index2").unwrap();
let indexes = controller.list_indexes().unwrap();
assert_eq!(indexes.len(), 2);
assert_eq!(indexes[0].name, "test_index");
assert_eq!(indexes[1].name, "test_index2");
}
}