From df9ac0792236801777bd03ae71e4f68533655ac3 Mon Sep 17 00:00:00 2001 From: Kushal Kumar Date: Wed, 18 Dec 2024 02:55:02 +0530 Subject: [PATCH] tests: split tests option crate in separate test file Signed-off-by: Kushal Kumar --- crates/meilisearch/src/lib.rs | 2 ++ crates/meilisearch/src/option.rs | 40 --------------------------- crates/meilisearch/src/option_test.rs | 36 ++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 40 deletions(-) create mode 100644 crates/meilisearch/src/option_test.rs diff --git a/crates/meilisearch/src/lib.rs b/crates/meilisearch/src/lib.rs index 633ad2776..1406fca05 100644 --- a/crates/meilisearch/src/lib.rs +++ b/crates/meilisearch/src/lib.rs @@ -7,6 +7,8 @@ pub mod extractors; pub mod metrics; pub mod middleware; pub mod option; +#[cfg(test)] +mod option_test; pub mod routes; pub mod search; pub mod search_queue; diff --git a/crates/meilisearch/src/option.rs b/crates/meilisearch/src/option.rs index 7e87a5a2c..33a8a2f71 100644 --- a/crates/meilisearch/src/option.rs +++ b/crates/meilisearch/src/option.rs @@ -1018,43 +1018,3 @@ where } deserializer.deserialize_any(BoolOrInt) } - -#[cfg(test)] -mod test { - - use super::*; - - #[test] - fn test_valid_opt() { - assert!(Opt::try_parse_from(Some("")).is_ok()); - } - - #[test] - #[ignore] - fn test_meilli_config_file_path_valid() { - temp_env::with_vars( - vec![("MEILI_CONFIG_FILE_PATH", Some("../config.toml"))], // Relative path in meilisearch package - || { - assert!(Opt::try_build().is_ok()); - }, - ); - } - - #[test] - #[ignore] - fn test_meilli_config_file_path_invalid() { - temp_env::with_vars(vec![("MEILI_CONFIG_FILE_PATH", Some("../configgg.toml"))], || { - let possible_error_messages = [ - "unable to open or read the \"../configgg.toml\" configuration file: No such file or directory (os error 2).", - "unable to open or read the \"../configgg.toml\" configuration file: The system cannot find the file specified. (os error 2).", // Windows - ]; - let error_message = Opt::try_build().unwrap_err().to_string(); - assert!( - possible_error_messages.contains(&error_message.as_str()), - "Expected onf of {:?}, got {:?}.", - possible_error_messages, - error_message - ); - }); - } -} diff --git a/crates/meilisearch/src/option_test.rs b/crates/meilisearch/src/option_test.rs new file mode 100644 index 000000000..1fdb06718 --- /dev/null +++ b/crates/meilisearch/src/option_test.rs @@ -0,0 +1,36 @@ +use crate::option::Opt; +use clap::Parser; + +#[test] +fn test_valid_opt() { + assert!(Opt::try_parse_from(Some("")).is_ok()); +} + +#[test] +#[ignore] +fn test_meilli_config_file_path_valid() { + temp_env::with_vars( + vec![("MEILI_CONFIG_FILE_PATH", Some("../config.toml"))], // Relative path in meilisearch package + || { + assert!(Opt::try_build().is_ok()); + }, + ); +} + +#[test] +#[ignore] +fn test_meilli_config_file_path_invalid() { + temp_env::with_vars(vec![("MEILI_CONFIG_FILE_PATH", Some("../configgg.toml"))], || { + let possible_error_messages = [ + "unable to open or read the \"../configgg.toml\" configuration file: No such file or directory (os error 2).", + "unable to open or read the \"../configgg.toml\" configuration file: The system cannot find the file specified. (os error 2).", // Windows + ]; + let error_message = Opt::try_build().unwrap_err().to_string(); + assert!( + possible_error_messages.contains(&error_message.as_str()), + "Expected onf of {:?}, got {:?}.", + possible_error_messages, + error_message + ); + }); +}