add test for search + update ci for test in release

This commit is contained in:
qdequele 2020-01-22 14:30:09 +01:00
parent f77f38dfa0
commit b33dac9faa
No known key found for this signature in database
GPG Key ID: B3F0A000EBF11745
5 changed files with 100214 additions and 10 deletions

View File

@ -22,4 +22,4 @@ jobs:
uses: actions-rs/cargo@v1
with:
command: test
args: --locked
args: --locked --release

File diff suppressed because it is too large Load Diff

View File

@ -1,16 +1,18 @@
#![allow(dead_code)]
use std::error::Error;
use std::time::Duration;
use tempdir::TempDir;
use tide::server::Service;
use http_service::Body;
use http_service_mock::{make_server, TestBackend};
use meilisearch_http::data::Data;
use meilisearch_http::option::Opt;
use meilisearch_http::routes;
use http_service_mock::{make_server, TestBackend};
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")?;
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();
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(())
}

View 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 universes 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);
}

View File

@ -10,6 +10,14 @@ use assert_json_diff::assert_json_eq;
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]
fn write_all_and_delete() {
let mut server = common::setup_server().unwrap();
@ -92,7 +100,7 @@ fn write_all_and_delete() {
let res = server.simulate(req).unwrap();
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
@ -117,7 +125,14 @@ fn write_all_and_delete() {
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]
fn write_all_and_update() {
let mut server = common::setup_server().unwrap();