From 8d462afb79b3048b722367365ea7f0cbeb81d831 Mon Sep 17 00:00:00 2001 From: mpostma Date: Wed, 3 Feb 2021 20:20:51 +0100 Subject: [PATCH] add tests for list index and create index. --- .../local_index_controller/mod.rs | 14 ++++++++++ src/index_controller/mod.rs | 27 +++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/src/index_controller/local_index_controller/mod.rs b/src/index_controller/local_index_controller/mod.rs index ec70c4443..21139e636 100644 --- a/src/index_controller/local_index_controller/mod.rs +++ b/src/index_controller/local_index_controller/mod.rs @@ -129,3 +129,17 @@ impl IndexController for LocalIndexController { 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() + }); +} diff --git a/src/index_controller/mod.rs b/src/index_controller/mod.rs index 38ff149bf..720c52cdc 100644 --- a/src/index_controller/mod.rs +++ b/src/index_controller/mod.rs @@ -155,3 +155,30 @@ pub trait IndexController { fn list_indexes(&self) -> anyhow::Result>; } + + +#[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(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"); + } +}