Change the settings tests and macros to avoid oversights

This commit is contained in:
ManyTheFish 2024-11-28 11:34:35 +01:00
parent a2f64f6552
commit 68c4717e21
2 changed files with 274 additions and 275 deletions

View File

@ -17,6 +17,26 @@ use crate::extractors::authentication::GuardedData;
use crate::routes::{get_task_id, is_dry_run, SummarizedTaskView};
use crate::Opt;
macro_rules! make_setting_routes {
($({$route:literal, $update_verb:ident, $type:ty, $err_ty:ty, $attr:ident, $camelcase_attr:literal, $analytics:ident}),*) => {
$(
make_setting_route!($route, $update_verb, $type, $err_ty, $attr, $camelcase_attr, $analytics);
)*
pub fn configure(cfg: &mut web::ServiceConfig) {
use crate::extractors::sequential_extractor::SeqHandler;
cfg.service(
web::resource("")
.route(web::patch().to(SeqHandler(update_all)))
.route(web::get().to(SeqHandler(get_all)))
.route(web::delete().to(SeqHandler(delete_all))))
$(.service($attr::resources()))*;
}
pub const ALL_SETTINGS_NAMES: &[&str] = &[$(stringify!($attr)),*];
};
}
#[macro_export]
macro_rules! make_setting_route {
($route:literal, $update_verb:ident, $type:ty, $err_ty:ty, $attr:ident, $camelcase_attr:literal, $analytics:ident) => {
@ -153,7 +173,8 @@ macro_rules! make_setting_route {
};
}
make_setting_route!(
make_setting_routes!(
{
"/filterable-attributes",
put,
std::collections::BTreeSet<String>,
@ -163,9 +184,8 @@ make_setting_route!(
filterable_attributes,
"filterableAttributes",
FilterableAttributesAnalytics
);
make_setting_route!(
},
{
"/sortable-attributes",
put,
std::collections::BTreeSet<String>,
@ -175,9 +195,8 @@ make_setting_route!(
sortable_attributes,
"sortableAttributes",
SortableAttributesAnalytics
);
make_setting_route!(
},
{
"/displayed-attributes",
put,
Vec<String>,
@ -187,9 +206,8 @@ make_setting_route!(
displayed_attributes,
"displayedAttributes",
DisplayedAttributesAnalytics
);
make_setting_route!(
},
{
"/typo-tolerance",
patch,
meilisearch_types::settings::TypoSettings,
@ -199,9 +217,8 @@ make_setting_route!(
typo_tolerance,
"typoTolerance",
TypoToleranceAnalytics
);
make_setting_route!(
},
{
"/searchable-attributes",
put,
Vec<String>,
@ -211,9 +228,8 @@ make_setting_route!(
searchable_attributes,
"searchableAttributes",
SearchableAttributesAnalytics
);
make_setting_route!(
},
{
"/stop-words",
put,
std::collections::BTreeSet<String>,
@ -223,9 +239,8 @@ make_setting_route!(
stop_words,
"stopWords",
StopWordsAnalytics
);
make_setting_route!(
},
{
"/non-separator-tokens",
put,
std::collections::BTreeSet<String>,
@ -235,9 +250,8 @@ make_setting_route!(
non_separator_tokens,
"nonSeparatorTokens",
NonSeparatorTokensAnalytics
);
make_setting_route!(
},
{
"/separator-tokens",
put,
std::collections::BTreeSet<String>,
@ -247,9 +261,8 @@ make_setting_route!(
separator_tokens,
"separatorTokens",
SeparatorTokensAnalytics
);
make_setting_route!(
},
{
"/dictionary",
put,
std::collections::BTreeSet<String>,
@ -259,9 +272,8 @@ make_setting_route!(
dictionary,
"dictionary",
DictionaryAnalytics
);
make_setting_route!(
},
{
"/synonyms",
put,
std::collections::BTreeMap<String, Vec<String>>,
@ -271,9 +283,8 @@ make_setting_route!(
synonyms,
"synonyms",
SynonymsAnalytics
);
make_setting_route!(
},
{
"/distinct-attribute",
put,
String,
@ -283,9 +294,8 @@ make_setting_route!(
distinct_attribute,
"distinctAttribute",
DistinctAttributeAnalytics
);
make_setting_route!(
},
{
"/proximity-precision",
put,
meilisearch_types::settings::ProximityPrecisionView,
@ -295,9 +305,8 @@ make_setting_route!(
proximity_precision,
"proximityPrecision",
ProximityPrecisionAnalytics
);
make_setting_route!(
},
{
"/localized-attributes",
put,
Vec<meilisearch_types::locales::LocalizedAttributesRuleView>,
@ -307,9 +316,8 @@ make_setting_route!(
localized_attributes,
"localizedAttributes",
LocalesAnalytics
);
make_setting_route!(
},
{
"/ranking-rules",
put,
Vec<meilisearch_types::settings::RankingRuleView>,
@ -319,9 +327,8 @@ make_setting_route!(
ranking_rules,
"rankingRules",
RankingRulesAnalytics
);
make_setting_route!(
},
{
"/faceting",
patch,
meilisearch_types::settings::FacetingSettings,
@ -331,9 +338,8 @@ make_setting_route!(
faceting,
"faceting",
FacetingAnalytics
);
make_setting_route!(
},
{
"/pagination",
patch,
meilisearch_types::settings::PaginationSettings,
@ -343,9 +349,8 @@ make_setting_route!(
pagination,
"pagination",
PaginationAnalytics
);
make_setting_route!(
},
{
"/embedders",
patch,
std::collections::BTreeMap<String, Setting<meilisearch_types::milli::vector::settings::EmbeddingSettings>>,
@ -355,9 +360,8 @@ make_setting_route!(
embedders,
"embedders",
EmbeddersAnalytics
);
make_setting_route!(
},
{
"/search-cutoff-ms",
put,
u64,
@ -367,9 +371,8 @@ make_setting_route!(
search_cutoff_ms,
"searchCutoffMs",
SearchCutoffMsAnalytics
);
make_setting_route!(
},
{
"/facet-search",
put,
bool,
@ -379,9 +382,8 @@ make_setting_route!(
facet_search,
"facetSearch",
FacetSearchAnalytics
);
make_setting_route!(
},
{
"/prefix-search",
put,
meilisearch_types::settings::PrefixSearchSettings,
@ -391,41 +393,7 @@ make_setting_route!(
prefix_search,
"prefixSearch",
PrefixSearchAnalytics
);
macro_rules! generate_configure {
($($mod:ident),*) => {
pub fn configure(cfg: &mut web::ServiceConfig) {
use crate::extractors::sequential_extractor::SeqHandler;
cfg.service(
web::resource("")
.route(web::patch().to(SeqHandler(update_all)))
.route(web::get().to(SeqHandler(get_all)))
.route(web::delete().to(SeqHandler(delete_all))))
$(.service($mod::resources()))*;
}
};
}
generate_configure!(
filterable_attributes,
sortable_attributes,
displayed_attributes,
localized_attributes,
searchable_attributes,
distinct_attribute,
proximity_precision,
stop_words,
separator_tokens,
non_separator_tokens,
dictionary,
synonyms,
ranking_rules,
typo_tolerance,
pagination,
faceting,
embedders,
search_cutoff_ms
);
pub async fn update_all(

View File

@ -37,6 +37,23 @@ static DEFAULT_SETTINGS_VALUES: Lazy<HashMap<&'static str, Value>> = Lazy::new(|
}),
);
map.insert("search_cutoff_ms", json!(null));
map.insert("embedders", json!(null));
map.insert("facet_search", json!(true));
map.insert("prefix_search", json!("indexingTime"));
map.insert("proximity_precision", json!("byWord"));
map.insert("sortable_attributes", json!([]));
map.insert(
"typo_tolerance",
json!({
"enabled": true,
"minWordSizeForTypos": {
"oneTypo": 5,
"twoTypos": 9
},
"disableOnWords": [],
"disableOnAttributes": []
}),
);
map
});
@ -343,7 +360,7 @@ async fn error_update_setting_unexisting_index_invalid_uid() {
}
macro_rules! test_setting_routes {
($($setting:ident $write_method:ident), *) => {
($($setting:ident $write_method:ident,) *) => {
$(
mod $setting {
use crate::common::Server;
@ -409,6 +426,14 @@ macro_rules! test_setting_routes {
}
}
)*
#[actix_rt::test]
async fn all_setting_tested() {
let expected = std::collections::BTreeSet::from_iter(meilisearch::routes::indexes::settings::ALL_SETTINGS_NAMES.iter());
let tested = std::collections::BTreeSet::from_iter([$(stringify!($setting)),*].iter());
let diff: Vec<_> = expected.difference(&tested).collect();
assert!(diff.is_empty(), "Not all settings were tested, please add the following settings to the `test_setting_routes!` macro: {:?}", diff);
}
};
}
@ -426,7 +451,13 @@ test_setting_routes!(
synonyms put,
pagination patch,
faceting patch,
search_cutoff_ms put
search_cutoff_ms put,
embedders patch,
facet_search put,
prefix_search put,
proximity_precision put,
sortable_attributes put,
typo_tolerance patch,
);
#[actix_rt::test]