mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-30 00:55:00 +08:00
add test for search + update ci for test in release
This commit is contained in:
parent
f77f38dfa0
commit
b33dac9faa
2
.github/workflows/test.yml
vendored
2
.github/workflows/test.yml
vendored
@ -22,4 +22,4 @@ jobs:
|
|||||||
uses: actions-rs/cargo@v1
|
uses: actions-rs/cargo@v1
|
||||||
with:
|
with:
|
||||||
command: test
|
command: test
|
||||||
args: --locked
|
args: --locked --release
|
||||||
|
100018
meilisearch-http/tests/assets/movies.json
Normal file
100018
meilisearch-http/tests/assets/movies.json
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,16 +1,18 @@
|
|||||||
|
#![allow(dead_code)]
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
use tempdir::TempDir;
|
use http_service::Body;
|
||||||
use tide::server::Service;
|
use http_service_mock::{make_server, TestBackend};
|
||||||
use meilisearch_http::data::Data;
|
use meilisearch_http::data::Data;
|
||||||
use meilisearch_http::option::Opt;
|
use meilisearch_http::option::Opt;
|
||||||
use meilisearch_http::routes;
|
use meilisearch_http::routes;
|
||||||
|
use serde_json::json;
|
||||||
|
use tempdir::TempDir;
|
||||||
|
use tide::server::Service;
|
||||||
|
use async_std::task::{block_on, sleep};
|
||||||
|
|
||||||
use http_service_mock::{make_server, TestBackend};
|
pub fn setup_server() -> Result<TestBackend<Service<Data>>, Box<dyn Error>> {
|
||||||
|
|
||||||
|
|
||||||
pub fn setup_server() -> Result<TestBackend<Service<Data>>, Box<dyn Error>>{
|
|
||||||
|
|
||||||
let tmp_dir = TempDir::new("meilisearch")?;
|
let tmp_dir = TempDir::new("meilisearch")?;
|
||||||
|
|
||||||
let opt = Opt {
|
let opt = Opt {
|
||||||
@ -26,3 +28,86 @@ pub fn setup_server() -> Result<TestBackend<Service<Data>>, Box<dyn Error>>{
|
|||||||
let http_server = app.into_http_service();
|
let http_server = app.into_http_service();
|
||||||
Ok(make_server(http_server)?)
|
Ok(make_server(http_server)?)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
|
|
||||||
|
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());
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn enrich_server_with_movies_settings(server: &mut TestBackend<Service<Data>>) -> Result<(), Box<dyn Error>> {
|
||||||
|
|
||||||
|
let json = json!({
|
||||||
|
"rankingRules": [
|
||||||
|
"_typo",
|
||||||
|
"_words",
|
||||||
|
"_proximity",
|
||||||
|
"_attribute",
|
||||||
|
"_words_position",
|
||||||
|
"dsc(popularity)",
|
||||||
|
"_exact",
|
||||||
|
"dsc(vote_average)",
|
||||||
|
],
|
||||||
|
"rankingDistinct": null,
|
||||||
|
"attributeIdentifier": "id",
|
||||||
|
"attributesSearchable": [
|
||||||
|
"title",
|
||||||
|
"tagline",
|
||||||
|
"overview",
|
||||||
|
"cast",
|
||||||
|
"director",
|
||||||
|
"producer",
|
||||||
|
"production_companies",
|
||||||
|
"genres",
|
||||||
|
],
|
||||||
|
"attributesDisplayed": [
|
||||||
|
"title",
|
||||||
|
"director",
|
||||||
|
"producer",
|
||||||
|
"tagline",
|
||||||
|
"genres",
|
||||||
|
"id",
|
||||||
|
"overview",
|
||||||
|
"vote_count",
|
||||||
|
"vote_average",
|
||||||
|
"poster_path",
|
||||||
|
"popularity",
|
||||||
|
],
|
||||||
|
"stopWords": null,
|
||||||
|
"synonyms": null
|
||||||
|
});
|
||||||
|
|
||||||
|
let body = json.to_string().into_bytes();
|
||||||
|
|
||||||
|
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());
|
||||||
|
|
||||||
|
block_on(sleep(Duration::from_secs(5)));
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
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 res = server.simulate(req).unwrap();
|
||||||
|
|
||||||
|
println!("enrich_server_with_movies_documents: {:?}", res.status());
|
||||||
|
|
||||||
|
block_on(sleep(Duration::from_secs(5)));
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
86
meilisearch-http/tests/search.rs
Normal file
86
meilisearch-http/tests/search.rs
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
// use std::time::Duration;
|
||||||
|
// use std::convert::Into;
|
||||||
|
|
||||||
|
use async_std::task::{block_on};
|
||||||
|
use async_std::io::prelude::*;
|
||||||
|
use http_service::Body;
|
||||||
|
use serde_json::json;
|
||||||
|
use serde_json::Value;
|
||||||
|
use assert_json_diff::assert_json_eq;
|
||||||
|
|
||||||
|
mod common;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn basic_search() {
|
||||||
|
let mut server = common::setup_server().unwrap();
|
||||||
|
|
||||||
|
common::enrich_server_with_movies_index(&mut server).unwrap();
|
||||||
|
common::enrich_server_with_movies_settings(&mut server).unwrap();
|
||||||
|
common::enrich_server_with_movies_documents(&mut server).unwrap();
|
||||||
|
|
||||||
|
// 1 - Simple search
|
||||||
|
|
||||||
|
let req = http::Request::get("/indexes/movies/search?q=captain&limit=3").body(Body::empty()).unwrap();
|
||||||
|
let res = server.simulate(req).unwrap();
|
||||||
|
|
||||||
|
let mut buf = Vec::new();
|
||||||
|
block_on(res.into_body().read_to_end(&mut buf)).unwrap();
|
||||||
|
let res_value: Value = serde_json::from_slice(&buf).unwrap();
|
||||||
|
println!("res: {:?}", res_value);
|
||||||
|
|
||||||
|
let res_expected = json!([
|
||||||
|
{
|
||||||
|
"id": 299537,
|
||||||
|
"popularity": 44.726,
|
||||||
|
"vote_average": 7.0,
|
||||||
|
"title": "Captain Marvel",
|
||||||
|
"tagline": "Higher. Further. Faster.",
|
||||||
|
"overview": "The story follows Carol Danvers as she becomes one of the universe’s most powerful heroes when Earth is caught in the middle of a galactic war between two alien races. Set in the 1990s, Captain Marvel is an all-new adventure from a previously unseen period in the history of the Marvel Cinematic Universe.",
|
||||||
|
"director": "Ryan Fleck",
|
||||||
|
"producer": "Kevin Feige",
|
||||||
|
"genres": [
|
||||||
|
"Action",
|
||||||
|
"Adventure",
|
||||||
|
"Science Fiction"
|
||||||
|
],
|
||||||
|
"poster_path": "https://image.tmdb.org/t/p/w500/AtsgWhDnHTq68L0lLsUrCnM7TjG.jpg",
|
||||||
|
"vote_count": 7858
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 271110,
|
||||||
|
"popularity": 37.431,
|
||||||
|
"vote_average": 7.4,
|
||||||
|
"title": "Captain America: Civil War",
|
||||||
|
"tagline": "Divided We Fall",
|
||||||
|
"overview": "Following the events of Age of Ultron, the collective governments of the world pass an act designed to regulate all superhuman activity. This polarizes opinion amongst the Avengers, causing two factions to side with Iron Man or Captain America, which causes an epic battle between former allies.",
|
||||||
|
"director": "Anthony Russo",
|
||||||
|
"producer": "Kevin Feige",
|
||||||
|
"genres": [
|
||||||
|
"Adventure",
|
||||||
|
"Action",
|
||||||
|
"Science Fiction"
|
||||||
|
],
|
||||||
|
"poster_path": "https://image.tmdb.org/t/p/w500/kSBXou5Ac7vEqKd97wotJumyJvU.jpg",
|
||||||
|
"vote_count": 15079
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 1771,
|
||||||
|
"popularity": 19.657,
|
||||||
|
"vote_average": 6.9,
|
||||||
|
"title": "Captain America: The First Avenger",
|
||||||
|
"tagline": "When patriots become heroes",
|
||||||
|
"overview": "During World War II, Steve Rogers is a sickly man from Brooklyn who's transformed into super-soldier Captain America to aid in the war effort. Rogers must stop the Red Skull – Adolf Hitler's ruthless head of weaponry, and the leader of an organization that intends to use a mysterious device of untold powers for world domination.",
|
||||||
|
"director": "Joe Johnston",
|
||||||
|
"producer": "Kevin Feige",
|
||||||
|
"genres": [
|
||||||
|
"Action",
|
||||||
|
"Adventure",
|
||||||
|
"Science Fiction"
|
||||||
|
],
|
||||||
|
"poster_path": "https://image.tmdb.org/t/p/w500/vSNxAJTlD0r02V9sPYpOjqDZXUK.jpg",
|
||||||
|
"vote_count": 13853
|
||||||
|
}
|
||||||
|
]);
|
||||||
|
|
||||||
|
assert_json_eq!(res_expected, res_value["hits"].clone(), ordered: false);
|
||||||
|
}
|
@ -10,6 +10,14 @@ use assert_json_diff::assert_json_eq;
|
|||||||
|
|
||||||
mod common;
|
mod common;
|
||||||
|
|
||||||
|
// Process:
|
||||||
|
// - Write a full settings update
|
||||||
|
// - Delete all settings
|
||||||
|
// Check:
|
||||||
|
// - Settings are deleted, all fields are null
|
||||||
|
// - POST success repond Status Code 202
|
||||||
|
// - Get success repond Status Code 200
|
||||||
|
// - Delete success repond Status Code 202
|
||||||
#[test]
|
#[test]
|
||||||
fn write_all_and_delete() {
|
fn write_all_and_delete() {
|
||||||
let mut server = common::setup_server().unwrap();
|
let mut server = common::setup_server().unwrap();
|
||||||
@ -92,7 +100,7 @@ fn write_all_and_delete() {
|
|||||||
let res = server.simulate(req).unwrap();
|
let res = server.simulate(req).unwrap();
|
||||||
assert_eq!(res.status(), 202);
|
assert_eq!(res.status(), 202);
|
||||||
|
|
||||||
block_on(sleep(Duration::from_secs(1)));
|
block_on(sleep(Duration::from_secs(2)));
|
||||||
|
|
||||||
// 5 - Get all settings and check if they are empty
|
// 5 - Get all settings and check if they are empty
|
||||||
|
|
||||||
@ -117,7 +125,14 @@ fn write_all_and_delete() {
|
|||||||
assert_json_eq!(json, res_value, ordered: false);
|
assert_json_eq!(json, res_value, ordered: false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Process:
|
||||||
|
// - Write a full setting update
|
||||||
|
// - Rewrite an other settings confirmation
|
||||||
|
// Check:
|
||||||
|
// - Settings are overwrited
|
||||||
|
// - Forgotten attributes are deleted
|
||||||
|
// - Null attributes are deleted
|
||||||
|
// - Empty attribute are deleted
|
||||||
#[test]
|
#[test]
|
||||||
fn write_all_and_update() {
|
fn write_all_and_update() {
|
||||||
let mut server = common::setup_server().unwrap();
|
let mut server = common::setup_server().unwrap();
|
||||||
|
Loading…
Reference in New Issue
Block a user