mirror of
https://github.com/meilisearch/MeiliSearch
synced 2025-07-03 11:57:07 +02:00
run cargo fmt
This commit is contained in:
parent
9c0497c419
commit
c276dda305
18 changed files with 315 additions and 179 deletions
|
@ -2,6 +2,7 @@
|
|||
use std::error::Error;
|
||||
use std::time::Duration;
|
||||
|
||||
use async_std::task::{block_on, sleep};
|
||||
use http_service::Body;
|
||||
use http_service_mock::{make_server, TestBackend};
|
||||
use meilisearch_http::data::Data;
|
||||
|
@ -10,7 +11,6 @@ use meilisearch_http::routes;
|
|||
use serde_json::json;
|
||||
use tempdir::TempDir;
|
||||
use tide::server::Service;
|
||||
use async_std::task::{block_on, sleep};
|
||||
|
||||
pub fn setup_server() -> Result<TestBackend<Service<Data>>, Box<dyn Error>> {
|
||||
let tmp_dir = TempDir::new("meilisearch")?;
|
||||
|
@ -29,13 +29,18 @@ pub fn setup_server() -> Result<TestBackend<Service<Data>>, Box<dyn Error>> {
|
|||
Ok(make_server(http_server)?)
|
||||
}
|
||||
|
||||
pub fn enrich_server_with_movies_index(server: &mut TestBackend<Service<Data>>) -> Result<(), Box<dyn Error>> {
|
||||
|
||||
pub fn enrich_server_with_movies_index(
|
||||
server: &mut TestBackend<Service<Data>>,
|
||||
) -> Result<(), Box<dyn Error>> {
|
||||
let body = json!({
|
||||
"uid": "movies",
|
||||
}).to_string().into_bytes();
|
||||
})
|
||||
.to_string()
|
||||
.into_bytes();
|
||||
|
||||
let req = http::Request::post("/indexes").body(Body::from(body)).unwrap();
|
||||
let req = http::Request::post("/indexes")
|
||||
.body(Body::from(body))
|
||||
.unwrap();
|
||||
let res = server.simulate(req).unwrap();
|
||||
|
||||
println!("enrich_server_with_movies_index: {:?}", res.status());
|
||||
|
@ -43,8 +48,9 @@ pub fn enrich_server_with_movies_index(server: &mut TestBackend<Service<Data>>)
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub fn enrich_server_with_movies_settings(server: &mut TestBackend<Service<Data>>) -> Result<(), Box<dyn Error>> {
|
||||
|
||||
pub fn enrich_server_with_movies_settings(
|
||||
server: &mut TestBackend<Service<Data>>,
|
||||
) -> Result<(), Box<dyn Error>> {
|
||||
let json = json!({
|
||||
"rankingRules": [
|
||||
"_typo",
|
||||
|
@ -87,7 +93,9 @@ pub fn enrich_server_with_movies_settings(server: &mut TestBackend<Service<Data>
|
|||
|
||||
let body = json.to_string().into_bytes();
|
||||
|
||||
let req = http::Request::post("/indexes/movies/settings").body(Body::from(body)).unwrap();
|
||||
let req = http::Request::post("/indexes/movies/settings")
|
||||
.body(Body::from(body))
|
||||
.unwrap();
|
||||
let res = server.simulate(req).unwrap();
|
||||
|
||||
println!("enrich_server_with_movies_settings: {:?}", res.status());
|
||||
|
@ -97,11 +105,14 @@ pub fn enrich_server_with_movies_settings(server: &mut TestBackend<Service<Data>
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub fn enrich_server_with_movies_documents(server: &mut TestBackend<Service<Data>>) -> Result<(), Box<dyn Error>> {
|
||||
|
||||
pub fn enrich_server_with_movies_documents(
|
||||
server: &mut TestBackend<Service<Data>>,
|
||||
) -> Result<(), Box<dyn Error>> {
|
||||
let body = include_bytes!("assets/movies.json").to_vec();
|
||||
|
||||
let req = http::Request::post("/indexes/movies/documents").body(Body::from(body)).unwrap();
|
||||
let req = http::Request::post("/indexes/movies/documents")
|
||||
.body(Body::from(body))
|
||||
.unwrap();
|
||||
let res = server.simulate(req).unwrap();
|
||||
|
||||
println!("enrich_server_with_movies_documents: {:?}", res.status());
|
||||
|
@ -110,4 +121,3 @@ pub fn enrich_server_with_movies_documents(server: &mut TestBackend<Service<Data
|
|||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
|
@ -18,9 +18,13 @@ fn test_healthyness() {
|
|||
|
||||
let body = json!({
|
||||
"health": false,
|
||||
}).to_string().into_bytes();
|
||||
})
|
||||
.to_string()
|
||||
.into_bytes();
|
||||
|
||||
let req = http::Request::put("/health").body(Body::from(body)).unwrap();
|
||||
let req = http::Request::put("/health")
|
||||
.body(Body::from(body))
|
||||
.unwrap();
|
||||
let res = server.simulate(req).unwrap();
|
||||
assert_eq!(res.status(), 200);
|
||||
|
||||
|
@ -34,9 +38,13 @@ fn test_healthyness() {
|
|||
|
||||
let body = json!({
|
||||
"health": true,
|
||||
}).to_string().into_bytes();
|
||||
})
|
||||
.to_string()
|
||||
.into_bytes();
|
||||
|
||||
let req = http::Request::put("/health").body(Body::from(body)).unwrap();
|
||||
let req = http::Request::put("/health")
|
||||
.body(Body::from(body))
|
||||
.unwrap();
|
||||
let res = server.simulate(req).unwrap();
|
||||
assert_eq!(res.status(), 200);
|
||||
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
use async_std::task::block_on;
|
||||
use async_std::io::prelude::*;
|
||||
use async_std::task::block_on;
|
||||
use http_service::Body;
|
||||
use serde_json::json;
|
||||
use std::convert::Into;
|
||||
use serde_json::Value;
|
||||
use std::convert::Into;
|
||||
|
||||
mod common;
|
||||
|
||||
|
@ -17,9 +17,13 @@ fn create_index_with_name() {
|
|||
|
||||
let body = json!({
|
||||
"name": "movies",
|
||||
}).to_string().into_bytes();
|
||||
})
|
||||
.to_string()
|
||||
.into_bytes();
|
||||
|
||||
let req = http::Request::post("/indexes").body(Body::from(body)).unwrap();
|
||||
let req = http::Request::post("/indexes")
|
||||
.body(Body::from(body))
|
||||
.unwrap();
|
||||
let res = server.simulate(req).unwrap();
|
||||
assert_eq!(res.status(), 201);
|
||||
|
||||
|
@ -73,9 +77,13 @@ fn create_index_with_uid() {
|
|||
|
||||
let body = json!({
|
||||
"uid": "movies",
|
||||
}).to_string().into_bytes();
|
||||
})
|
||||
.to_string()
|
||||
.into_bytes();
|
||||
|
||||
let req = http::Request::post("/indexes").body(Body::from(body)).unwrap();
|
||||
let req = http::Request::post("/indexes")
|
||||
.body(Body::from(body))
|
||||
.unwrap();
|
||||
let res = server.simulate(req).unwrap();
|
||||
assert_eq!(res.status(), 201);
|
||||
|
||||
|
@ -130,9 +138,13 @@ fn create_index_with_name_and_uid() {
|
|||
let body = json!({
|
||||
"name": "Films",
|
||||
"uid": "fr_movies",
|
||||
}).to_string().into_bytes();
|
||||
})
|
||||
.to_string()
|
||||
.into_bytes();
|
||||
|
||||
let req = http::Request::post("/indexes").body(Body::from(body)).unwrap();
|
||||
let req = http::Request::post("/indexes")
|
||||
.body(Body::from(body))
|
||||
.unwrap();
|
||||
let res = server.simulate(req).unwrap();
|
||||
assert_eq!(res.status(), 201);
|
||||
|
||||
|
@ -185,9 +197,13 @@ fn rename_index() {
|
|||
|
||||
let body = json!({
|
||||
"name": "movies",
|
||||
}).to_string().into_bytes();
|
||||
})
|
||||
.to_string()
|
||||
.into_bytes();
|
||||
|
||||
let req = http::Request::post("/indexes").body(Body::from(body)).unwrap();
|
||||
let req = http::Request::post("/indexes")
|
||||
.body(Body::from(body))
|
||||
.unwrap();
|
||||
let res = server.simulate(req).unwrap();
|
||||
assert_eq!(res.status(), 201);
|
||||
|
||||
|
@ -212,9 +228,13 @@ fn rename_index() {
|
|||
|
||||
let body = json!({
|
||||
"name": "TV Shows",
|
||||
}).to_string().into_bytes();
|
||||
})
|
||||
.to_string()
|
||||
.into_bytes();
|
||||
|
||||
let req = http::Request::put(format!("/indexes/{}", r1_uid)).body(Body::from(body)).unwrap();
|
||||
let req = http::Request::put(format!("/indexes/{}", r1_uid))
|
||||
.body(Body::from(body))
|
||||
.unwrap();
|
||||
let res = server.simulate(req).unwrap();
|
||||
assert_eq!(res.status(), 200);
|
||||
|
||||
|
@ -268,9 +288,13 @@ fn delete_index_and_recreate_it() {
|
|||
|
||||
let body = json!({
|
||||
"name": "movies",
|
||||
}).to_string().into_bytes();
|
||||
})
|
||||
.to_string()
|
||||
.into_bytes();
|
||||
|
||||
let req = http::Request::post("/indexes").body(Body::from(body)).unwrap();
|
||||
let req = http::Request::post("/indexes")
|
||||
.body(Body::from(body))
|
||||
.unwrap();
|
||||
let res = server.simulate(req).unwrap();
|
||||
assert_eq!(res.status(), 201);
|
||||
|
||||
|
@ -317,7 +341,9 @@ fn delete_index_and_recreate_it() {
|
|||
// Update "movies" to "TV Shows"
|
||||
// DELETE: /indexes/:uid
|
||||
|
||||
let req = http::Request::delete(format!("/indexes/{}", r1_uid)).body(Body::empty()).unwrap();
|
||||
let req = http::Request::delete(format!("/indexes/{}", r1_uid))
|
||||
.body(Body::empty())
|
||||
.unwrap();
|
||||
let res = server.simulate(req).unwrap();
|
||||
assert_eq!(res.status(), 204);
|
||||
|
||||
|
@ -345,9 +371,13 @@ fn delete_index_and_recreate_it() {
|
|||
|
||||
let body = json!({
|
||||
"name": "movies",
|
||||
}).to_string().into_bytes();
|
||||
})
|
||||
.to_string()
|
||||
.into_bytes();
|
||||
|
||||
let req = http::Request::post("/indexes").body(Body::from(body)).unwrap();
|
||||
let req = http::Request::post("/indexes")
|
||||
.body(Body::from(body))
|
||||
.unwrap();
|
||||
let res = server.simulate(req).unwrap();
|
||||
assert_eq!(res.status(), 201);
|
||||
|
||||
|
@ -401,9 +431,13 @@ fn check_multiples_indexes() {
|
|||
|
||||
let body = json!({
|
||||
"name": "movies",
|
||||
}).to_string().into_bytes();
|
||||
})
|
||||
.to_string()
|
||||
.into_bytes();
|
||||
|
||||
let req = http::Request::post("/indexes").body(Body::from(body)).unwrap();
|
||||
let req = http::Request::post("/indexes")
|
||||
.body(Body::from(body))
|
||||
.unwrap();
|
||||
let res = server.simulate(req).unwrap();
|
||||
assert_eq!(res.status(), 201);
|
||||
|
||||
|
@ -452,9 +486,13 @@ fn check_multiples_indexes() {
|
|||
|
||||
let body = json!({
|
||||
"name": "films",
|
||||
}).to_string().into_bytes();
|
||||
})
|
||||
.to_string()
|
||||
.into_bytes();
|
||||
|
||||
let req = http::Request::post("/indexes").body(Body::from(body)).unwrap();
|
||||
let req = http::Request::post("/indexes")
|
||||
.body(Body::from(body))
|
||||
.unwrap();
|
||||
let res = server.simulate(req).unwrap();
|
||||
assert_eq!(res.status(), 201);
|
||||
|
||||
|
@ -524,7 +562,6 @@ fn check_multiples_indexes() {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
#[test]
|
||||
fn create_index_failed() {
|
||||
let mut server = common::setup_server().unwrap();
|
||||
|
@ -549,7 +586,9 @@ fn create_index_failed() {
|
|||
|
||||
let body = json!({}).to_string().into_bytes();
|
||||
|
||||
let req = http::Request::post("/indexes").body(Body::from(body)).unwrap();
|
||||
let req = http::Request::post("/indexes")
|
||||
.body(Body::from(body))
|
||||
.unwrap();
|
||||
let res = server.simulate(req).unwrap();
|
||||
assert_eq!(res.status(), 400);
|
||||
|
||||
|
@ -567,9 +606,13 @@ fn create_index_failed() {
|
|||
let body = json!({
|
||||
"name": "movies",
|
||||
"active": true
|
||||
}).to_string().into_bytes();
|
||||
})
|
||||
.to_string()
|
||||
.into_bytes();
|
||||
|
||||
let req = http::Request::post("/indexes").body(Body::from(body)).unwrap();
|
||||
let req = http::Request::post("/indexes")
|
||||
.body(Body::from(body))
|
||||
.unwrap();
|
||||
let res = server.simulate(req).unwrap();
|
||||
assert_eq!(res.status(), 400);
|
||||
|
||||
|
@ -587,9 +630,13 @@ fn create_index_failed() {
|
|||
let body = json!({
|
||||
"name": "movies",
|
||||
"uid": 0
|
||||
}).to_string().into_bytes();
|
||||
})
|
||||
.to_string()
|
||||
.into_bytes();
|
||||
|
||||
let req = http::Request::post("/indexes").body(Body::from(body)).unwrap();
|
||||
let req = http::Request::post("/indexes")
|
||||
.body(Body::from(body))
|
||||
.unwrap();
|
||||
let res = server.simulate(req).unwrap();
|
||||
assert_eq!(res.status(), 400);
|
||||
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
use std::time::Duration;
|
||||
use std::convert::Into;
|
||||
use std::time::Duration;
|
||||
|
||||
use async_std::task::{block_on, sleep};
|
||||
use assert_json_diff::assert_json_eq;
|
||||
use async_std::io::prelude::*;
|
||||
use async_std::task::{block_on, sleep};
|
||||
use http_service::Body;
|
||||
use serde_json::json;
|
||||
use serde_json::Value;
|
||||
use assert_json_diff::assert_json_eq;
|
||||
|
||||
mod common;
|
||||
|
||||
|
@ -26,9 +26,13 @@ fn write_all_and_delete() {
|
|||
|
||||
let body = json!({
|
||||
"uid": "movies",
|
||||
}).to_string().into_bytes();
|
||||
})
|
||||
.to_string()
|
||||
.into_bytes();
|
||||
|
||||
let req = http::Request::post("/indexes").body(Body::from(body)).unwrap();
|
||||
let req = http::Request::post("/indexes")
|
||||
.body(Body::from(body))
|
||||
.unwrap();
|
||||
let res = server.simulate(req).unwrap();
|
||||
assert_eq!(res.status(), 201);
|
||||
|
||||
|
@ -76,7 +80,9 @@ fn write_all_and_delete() {
|
|||
|
||||
let body = json.to_string().into_bytes();
|
||||
|
||||
let req = http::Request::post("/indexes/movies/settings").body(Body::from(body)).unwrap();
|
||||
let req = http::Request::post("/indexes/movies/settings")
|
||||
.body(Body::from(body))
|
||||
.unwrap();
|
||||
let res = server.simulate(req).unwrap();
|
||||
assert_eq!(res.status(), 202);
|
||||
|
||||
|
@ -84,7 +90,9 @@ fn write_all_and_delete() {
|
|||
|
||||
// 3 - Get all settings and compare to the previous one
|
||||
|
||||
let req = http::Request::get("/indexes/movies/settings").body(Body::empty()).unwrap();
|
||||
let req = http::Request::get("/indexes/movies/settings")
|
||||
.body(Body::empty())
|
||||
.unwrap();
|
||||
let res = server.simulate(req).unwrap();
|
||||
assert_eq!(res.status(), 200);
|
||||
|
||||
|
@ -96,7 +104,9 @@ fn write_all_and_delete() {
|
|||
|
||||
// 4 - Delete all settings
|
||||
|
||||
let req = http::Request::delete("/indexes/movies/settings").body(Body::empty()).unwrap();
|
||||
let req = http::Request::delete("/indexes/movies/settings")
|
||||
.body(Body::empty())
|
||||
.unwrap();
|
||||
let res = server.simulate(req).unwrap();
|
||||
assert_eq!(res.status(), 202);
|
||||
|
||||
|
@ -104,7 +114,9 @@ fn write_all_and_delete() {
|
|||
|
||||
// 5 - Get all settings and check if they are empty
|
||||
|
||||
let req = http::Request::get("/indexes/movies/settings").body(Body::empty()).unwrap();
|
||||
let req = http::Request::get("/indexes/movies/settings")
|
||||
.body(Body::empty())
|
||||
.unwrap();
|
||||
let res = server.simulate(req).unwrap();
|
||||
assert_eq!(res.status(), 200);
|
||||
|
||||
|
@ -141,9 +153,13 @@ fn write_all_and_update() {
|
|||
|
||||
let body = json!({
|
||||
"uid": "movies",
|
||||
}).to_string().into_bytes();
|
||||
})
|
||||
.to_string()
|
||||
.into_bytes();
|
||||
|
||||
let req = http::Request::post("/indexes").body(Body::from(body)).unwrap();
|
||||
let req = http::Request::post("/indexes")
|
||||
.body(Body::from(body))
|
||||
.unwrap();
|
||||
let res = server.simulate(req).unwrap();
|
||||
assert_eq!(res.status(), 201);
|
||||
|
||||
|
@ -191,7 +207,9 @@ fn write_all_and_update() {
|
|||
|
||||
let body = json.to_string().into_bytes();
|
||||
|
||||
let req = http::Request::post("/indexes/movies/settings").body(Body::from(body)).unwrap();
|
||||
let req = http::Request::post("/indexes/movies/settings")
|
||||
.body(Body::from(body))
|
||||
.unwrap();
|
||||
let res = server.simulate(req).unwrap();
|
||||
assert_eq!(res.status(), 202);
|
||||
|
||||
|
@ -199,7 +217,9 @@ fn write_all_and_update() {
|
|||
|
||||
// 3 - Get all settings and compare to the previous one
|
||||
|
||||
let req = http::Request::get("/indexes/movies/settings").body(Body::empty()).unwrap();
|
||||
let req = http::Request::get("/indexes/movies/settings")
|
||||
.body(Body::empty())
|
||||
.unwrap();
|
||||
let res = server.simulate(req).unwrap();
|
||||
assert_eq!(res.status(), 200);
|
||||
|
||||
|
@ -244,7 +264,9 @@ fn write_all_and_update() {
|
|||
|
||||
let body_update = json_update.to_string().into_bytes();
|
||||
|
||||
let req = http::Request::post("/indexes/movies/settings").body(Body::from(body_update)).unwrap();
|
||||
let req = http::Request::post("/indexes/movies/settings")
|
||||
.body(Body::from(body_update))
|
||||
.unwrap();
|
||||
let res = server.simulate(req).unwrap();
|
||||
assert_eq!(res.status(), 202);
|
||||
|
||||
|
@ -252,7 +274,9 @@ fn write_all_and_update() {
|
|||
|
||||
// 5 - Get all settings and check if the content is the same of (4)
|
||||
|
||||
let req = http::Request::get("/indexes/movies/settings").body(Body::empty()).unwrap();
|
||||
let req = http::Request::get("/indexes/movies/settings")
|
||||
.body(Body::empty())
|
||||
.unwrap();
|
||||
let res = server.simulate(req).unwrap();
|
||||
assert_eq!(res.status(), 200);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue