diff --git a/meilisearch-core/src/database.rs b/meilisearch-core/src/database.rs index 6029f54fc..09daf4864 100644 --- a/meilisearch-core/src/database.rs +++ b/meilisearch-core/src/database.rs @@ -359,7 +359,7 @@ mod tests { use crate::criterion::{self, CriteriaBuilder}; use crate::update::{ProcessedUpdateResult, UpdateStatus}; - use crate::settings::{Settings, SettingsUpdate, UpdateState}; + use crate::settings::Settings; use crate::{Document, DocumentId}; use serde::de::IgnoredAny; use std::sync::mpsc; @@ -379,17 +379,11 @@ mod tests { database.set_update_callback(Box::new(update_fn)); - let settings_update = SettingsUpdate{ - primary_key: UpdateState::Update("id".to_string()), - ..SettingsUpdate::default() - }; - - let mut writer = db.update_write_txn().unwrap(); - let update_id = index.settings_update(&mut writer, settings_update).unwrap(); + let mut writer = db.main_write_txn().unwrap(); + index.main.put_schema(&mut writer, &Schema::with_primary_key("id")).unwrap(); writer.commit().unwrap(); // block until the transaction is processed - let _ = receiver.iter().find(|id| *id == update_id); let settings = { let data = r#" @@ -450,18 +444,10 @@ mod tests { database.set_update_callback(Box::new(update_fn)); - let settings_update = SettingsUpdate{ - primary_key: UpdateState::Update("id".to_string()), - ..SettingsUpdate::default() - }; - - let mut writer = db.update_write_txn().unwrap(); - let update_id = index.settings_update(&mut writer, settings_update).unwrap(); + let mut writer = db.main_write_txn().unwrap(); + index.main.put_schema(&mut writer, &Schema::with_primary_key("id")).unwrap(); writer.commit().unwrap(); - // block until the transaction is processed - let _ = receiver.iter().find(|id| *id == update_id); - let settings = { let data = r#" { @@ -520,18 +506,10 @@ mod tests { database.set_update_callback(Box::new(update_fn)); - let settings_update = SettingsUpdate{ - primary_key: UpdateState::Update("id".to_string()), - ..SettingsUpdate::default() - }; - - let mut writer = db.update_write_txn().unwrap(); - let update_id = index.settings_update(&mut writer, settings_update).unwrap(); + let mut writer = db.main_write_txn().unwrap(); + index.main.put_schema(&mut writer, &Schema::with_primary_key("id")).unwrap(); writer.commit().unwrap(); - // block until the transaction is processed - let _ = receiver.iter().find(|id| *id == update_id); - let settings = { let data = r#" { @@ -583,18 +561,10 @@ mod tests { database.set_update_callback(Box::new(update_fn)); - let settings_update = SettingsUpdate{ - primary_key: UpdateState::Update("id".to_string()), - ..SettingsUpdate::default() - }; - - let mut writer = db.update_write_txn().unwrap(); - let update_id = index.settings_update(&mut writer, settings_update).unwrap(); + let mut writer = db.main_write_txn().unwrap(); + index.main.put_schema(&mut writer, &Schema::with_primary_key("id")).unwrap(); writer.commit().unwrap(); - // block until the transaction is processed - let _ = receiver.iter().find(|id| *id == update_id); - let settings = { let data = r#" { @@ -735,18 +705,10 @@ mod tests { database.set_update_callback(Box::new(update_fn)); - let settings_update = SettingsUpdate{ - primary_key: UpdateState::Update("id".to_string()), - ..SettingsUpdate::default() - }; - - let mut writer = db.update_write_txn().unwrap(); - let update_id = index.settings_update(&mut writer, settings_update).unwrap(); + let mut writer = db.main_write_txn().unwrap(); + index.main.put_schema(&mut writer, &Schema::with_primary_key("id")).unwrap(); writer.commit().unwrap(); - // block until the transaction is processed - let _ = receiver.iter().find(|id| *id == update_id); - let settings = { let data = r#" { @@ -823,18 +785,10 @@ mod tests { database.set_update_callback(Box::new(update_fn)); - let settings_update = SettingsUpdate{ - primary_key: UpdateState::Update("id".to_string()), - ..SettingsUpdate::default() - }; - - let mut writer = db.update_write_txn().unwrap(); - let update_id = index.settings_update(&mut writer, settings_update).unwrap(); + let mut writer = db.main_write_txn().unwrap(); + index.main.put_schema(&mut writer, &Schema::with_primary_key("id")).unwrap(); writer.commit().unwrap(); - // block until the transaction is processed - let _ = receiver.iter().find(|id| *id == update_id); - let settings = { let data = r#" { @@ -970,18 +924,10 @@ mod tests { database.set_update_callback(Box::new(update_fn)); - let settings_update = SettingsUpdate{ - primary_key: UpdateState::Update("id".to_string()), - ..SettingsUpdate::default() - }; - - let mut writer = db.update_write_txn().unwrap(); - let update_id = index.settings_update(&mut writer, settings_update).unwrap(); + let mut writer = db.main_write_txn().unwrap(); + index.main.put_schema(&mut writer, &Schema::with_primary_key("id")).unwrap(); writer.commit().unwrap(); - // block until the transaction is processed - let _ = receiver.iter().find(|id| *id == update_id); - let settings = { let data = r#" { @@ -1045,18 +991,10 @@ mod tests { database.set_update_callback(Box::new(update_fn)); - let settings_update = SettingsUpdate{ - primary_key: UpdateState::Update("id".to_string()), - ..SettingsUpdate::default() - }; - - let mut writer = db.update_write_txn().unwrap(); - let update_id = index.settings_update(&mut writer, settings_update).unwrap(); + let mut writer = db.main_write_txn().unwrap(); + index.main.put_schema(&mut writer, &Schema::with_primary_key("id")).unwrap(); writer.commit().unwrap(); - // block until the transaction is processed - let _ = receiver.iter().find(|id| *id == update_id); - let settings = { let data = r#" { diff --git a/meilisearch-http/src/routes/document.rs b/meilisearch-http/src/routes/document.rs index c80fc2509..1eb7b66c1 100644 --- a/meilisearch-http/src/routes/document.rs +++ b/meilisearch-http/src/routes/document.rs @@ -135,7 +135,10 @@ async fn update_multiple_documents(mut ctx: Request, is_partial: bool) -> let db = &ctx.state().db; let reader = db.main_read_txn()?; - let mut schema = index.main.schema(&reader)?.ok_or(ResponseError::internal("schema not found"))?; + let mut schema = index + .main + .schema(&reader)? + .ok_or(ResponseError::internal("schema not found"))?; if schema.primary_key().is_none() { let id = match query.document_id { diff --git a/meilisearch-http/src/routes/index.rs b/meilisearch-http/src/routes/index.rs index ceb179b9f..a4b11f049 100644 --- a/meilisearch-http/src/routes/index.rs +++ b/meilisearch-http/src/routes/index.rs @@ -42,7 +42,7 @@ pub async fn list_indexes(ctx: Request) -> SResult { let primary_key = match index.main.schema(&reader) { Ok(Some(schema)) => match schema.primary_key() { Some(primary_key) => Some(primary_key.to_owned()), - None => None + None => None, }, _ => None, }; @@ -92,7 +92,7 @@ pub async fn get_index(ctx: Request) -> SResult { let primary_key = match index.main.schema(&reader) { Ok(Some(schema)) => match schema.primary_key() { Some(primary_key) => Some(primary_key.to_owned()), - None => None + None => None, }, _ => None, }; @@ -144,12 +144,15 @@ pub async fn create_index(mut ctx: Request) -> SResult { let uid = match body.uid { Some(uid) => { - if uid.chars().all(|x| x.is_ascii_alphanumeric() || x == '-' || x == '_') { + if uid + .chars() + .all(|x| x.is_ascii_alphanumeric() || x == '-' || x == '_') + { uid } else { - return Err(ResponseError::InvalidIndexUid) + return Err(ResponseError::InvalidIndexUid); } - }, + } None => loop { let uid = generate_uid(); if db.open_index(&uid).is_none() { @@ -235,8 +238,10 @@ pub async fn update_index(mut ctx: Request) -> SResult { if let Some(mut schema) = index.main.schema(&mut writer)? { match schema.primary_key() { Some(_) => { - return Err(ResponseError::bad_request("The index primary key cannot be updated")); - }, + return Err(ResponseError::bad_request( + "The index primary key cannot be updated", + )); + } None => { if let Ok(_) = schema.set_primary_key(&id) { index.main.put_schema(&mut writer, &schema)?; @@ -255,14 +260,9 @@ pub async fn update_index(mut ctx: Request) -> SResult { let updated_at = index.main.updated_at(&reader)?.into_internal_error()?; let primary_key = match index.main.schema(&reader) { - Ok(Some(schema)) => { - match schema.primary_key() { - Some(primary_key) => { - Some(primary_key.to_owned()) - }, - None => None - } - + Ok(Some(schema)) => match schema.primary_key() { + Some(primary_key) => Some(primary_key.to_owned()), + None => None, }, _ => None, }; diff --git a/meilisearch-http/tests/common.rs b/meilisearch-http/tests/common.rs index 9001fdce6..eee0fc283 100644 --- a/meilisearch-http/tests/common.rs +++ b/meilisearch-http/tests/common.rs @@ -69,9 +69,7 @@ impl Server { fn get_request(&mut self, url: &str) -> (Value, StatusCode) { eprintln!("get_request: {}", url); - let req = http::Request::get(url) - .body(Body::empty()) - .unwrap(); + let req = http::Request::get(url).body(Body::empty()).unwrap(); let res = self.mock.simulate(req).unwrap(); let status_code = res.status().clone(); @@ -97,7 +95,7 @@ impl Server { (response, status_code) } - fn post_request_async(&mut self, url: &str, body: Value) -> (Value, StatusCode) { + fn post_request_async(&mut self, url: &str, body: Value) -> (Value, StatusCode) { eprintln!("post_request_async: {}", url); let (response, status_code) = self.post_request(url, body); assert_eq!(status_code, 202); @@ -133,9 +131,7 @@ impl Server { fn delete_request(&mut self, url: &str) -> (Value, StatusCode) { eprintln!("delete_request: {}", url); - let req = http::Request::delete(url) - .body(Body::empty()) - .unwrap(); + let req = http::Request::delete(url).body(Body::empty()).unwrap(); let res = self.mock.simulate(req).unwrap(); let status_code = res.status().clone(); @@ -154,7 +150,6 @@ impl Server { (response, status_code) } - // // All Routes pub fn list_indexes(&mut self) -> (Value, StatusCode) { @@ -221,12 +216,20 @@ impl Server { } pub fn get_document(&mut self, document_id: impl ToString) -> (Value, StatusCode) { - let url = format!("/indexes/{}/documents/{}", self.uid, document_id.to_string()); + let url = format!( + "/indexes/{}/documents/{}", + self.uid, + document_id.to_string() + ); self.get_request(&url) } pub fn delete_document(&mut self, document_id: impl ToString) -> (Value, StatusCode) { - let url = format!("/indexes/{}/documents/{}", self.uid, document_id.to_string()); + let url = format!( + "/indexes/{}/documents/{}", + self.uid, + document_id.to_string() + ); self.delete_request_async(&url) } @@ -443,5 +446,4 @@ impl Server { self.add_or_replace_multiple_documents(body); } - } diff --git a/meilisearch-http/tests/documents_delete.rs b/meilisearch-http/tests/documents_delete.rs index 35041e023..0773702ca 100644 --- a/meilisearch-http/tests/documents_delete.rs +++ b/meilisearch-http/tests/documents_delete.rs @@ -14,7 +14,6 @@ fn delete() { assert_eq!(status_code, 404); } - // Resolve teh issue https://github.com/meilisearch/MeiliSearch/issues/493 #[test] fn delete_batch() { @@ -24,7 +23,7 @@ fn delete_batch() { let (_response, status_code) = server.get_document(419704); assert_eq!(status_code, 200); - let body = serde_json::json!([419704,512200,181812]); + let body = serde_json::json!([419704, 512200, 181812]); server.delete_multiple_documents(body); let (_response, status_code) = server.get_document(419704); diff --git a/meilisearch-http/tests/index.rs b/meilisearch-http/tests/index.rs index 855647be9..849cc425d 100644 --- a/meilisearch-http/tests/index.rs +++ b/meilisearch-http/tests/index.rs @@ -1,5 +1,5 @@ -use serde_json::json; use assert_json_diff::assert_json_eq; +use serde_json::json; mod common; @@ -413,8 +413,6 @@ fn create_index_failed() { assert_eq!(message, "invalid data"); } - - // Resolve issue https://github.com/meilisearch/MeiliSearch/issues/492 #[test] fn create_index_with_primary_key_and_index() { @@ -542,7 +540,6 @@ fn create_index_and_add_indentifier_after() { let (response, status_code) = server.get_index(); assert_eq!(status_code, 200); assert_eq!(response["primaryKey"].as_str().unwrap(), "id"); - } // Test that it's impossible to change the primary_key @@ -576,7 +573,6 @@ fn create_index_and_update_indentifier_after() { assert_eq!(response["primaryKey"].as_str().unwrap(), "id"); } - // Test that schema inference work well #[test] fn create_index_without_primary_key_and_add_document() { @@ -607,7 +603,6 @@ fn create_index_without_primary_key_and_add_document() { assert_eq!(response["primaryKey"].as_str().unwrap(), "id"); } - // Test search with no primary_key #[test] fn create_index_without_primary_key_and_search() { diff --git a/meilisearch-http/tests/search.rs b/meilisearch-http/tests/search.rs index 3823fd769..a53aecf89 100644 --- a/meilisearch-http/tests/search.rs +++ b/meilisearch-http/tests/search.rs @@ -1,6 +1,6 @@ -use std::convert::Into; -use serde_json::json; use assert_json_diff::assert_json_eq; +use serde_json::json; +use std::convert::Into; mod common; diff --git a/meilisearch-http/tests/settings.rs b/meilisearch-http/tests/settings.rs index 1e28f163f..c692e4104 100644 --- a/meilisearch-http/tests/settings.rs +++ b/meilisearch-http/tests/settings.rs @@ -1,6 +1,6 @@ -use std::convert::Into; use assert_json_diff::assert_json_eq; use serde_json::json; +use std::convert::Into; mod common; @@ -253,7 +253,6 @@ fn write_all_and_update() { assert_json_eq!(expected, response, ordered: false); } - #[test] fn test_default_settings() { let mut server = common::Server::with_uid("movies"); diff --git a/meilisearch-http/tests/settings_ranking_rules.rs b/meilisearch-http/tests/settings_ranking_rules.rs index cc8d3e422..a393374ee 100644 --- a/meilisearch-http/tests/settings_ranking_rules.rs +++ b/meilisearch-http/tests/settings_ranking_rules.rs @@ -115,9 +115,7 @@ fn send_undefined_rule() { }); server.create_index(body); - let body = json!([ - "typos", - ]); + let body = json!(["typos",]); let (_response, status_code) = server.update_ranking_rules_sync(body); assert_eq!(status_code, 400); @@ -132,9 +130,7 @@ fn send_malformed_custom_rule() { }); server.create_index(body); - let body = json!([ - "dsc(truc)", - ]); + let body = json!(["dsc(truc)",]); let (_response, status_code) = server.update_ranking_rules_sync(body); assert_eq!(status_code, 400); diff --git a/meilisearch-http/tests/settings_stop_words.rs b/meilisearch-http/tests/settings_stop_words.rs index 5ee250dd5..0c9257150 100644 --- a/meilisearch-http/tests/settings_stop_words.rs +++ b/meilisearch-http/tests/settings_stop_words.rs @@ -19,10 +19,7 @@ fn update_stop_words() { // 2 - Update stop words - let body = json!([ - "the", - "a" - ]); + let body = json!(["the", "a"]); server.update_stop_words(body.clone()); // 3 - Get all stop words and compare to the previous one