fix tests + fmt

This commit is contained in:
qdequele 2020-03-10 11:29:56 +01:00
parent c984d8d5a5
commit 179969a9e2
No known key found for this signature in database
GPG Key ID: B3F0A000EBF11745
10 changed files with 57 additions and 128 deletions

View File

@ -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#"
{

View File

@ -135,7 +135,10 @@ async fn update_multiple_documents(mut ctx: Request<Data>, 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 {

View File

@ -42,7 +42,7 @@ pub async fn list_indexes(ctx: Request<Data>) -> SResult<Response> {
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<Data>) -> SResult<Response> {
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<Data>) -> SResult<Response> {
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<Data>) -> SResult<Response> {
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<Data>) -> SResult<Response> {
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,
};

View File

@ -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);
}
}

View File

@ -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);

View File

@ -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() {

View File

@ -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;

View File

@ -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");

View File

@ -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);

View File

@ -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