mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-11-26 06:44:27 +01:00
make the tests compile again
This commit is contained in:
parent
b45c430165
commit
f7e546eea3
@ -1,6 +1,5 @@
|
|||||||
use crate::common::Server;
|
use crate::common::Server;
|
||||||
use actix_web::test;
|
use actix_web::test;
|
||||||
use meilisearch_http::{analytics, create_app};
|
|
||||||
use serde_json::{json, Value};
|
use serde_json::{json, Value};
|
||||||
|
|
||||||
#[actix_rt::test]
|
#[actix_rt::test]
|
||||||
@ -15,14 +14,7 @@ async fn error_api_key_bad_content_types() {
|
|||||||
|
|
||||||
let mut server = Server::new_auth().await;
|
let mut server = Server::new_auth().await;
|
||||||
server.use_api_key("MASTER_KEY");
|
server.use_api_key("MASTER_KEY");
|
||||||
let app = test::init_service(create_app!(
|
let app = server.init_web_app().await;
|
||||||
&server.service.meilisearch,
|
|
||||||
&server.service.auth,
|
|
||||||
true,
|
|
||||||
server.service.options,
|
|
||||||
analytics::MockAnalytics::new(&server.service.options).0
|
|
||||||
))
|
|
||||||
.await;
|
|
||||||
|
|
||||||
// post
|
// post
|
||||||
let req = test::TestRequest::post()
|
let req = test::TestRequest::post()
|
||||||
@ -87,14 +79,7 @@ async fn error_api_key_empty_content_types() {
|
|||||||
|
|
||||||
let mut server = Server::new_auth().await;
|
let mut server = Server::new_auth().await;
|
||||||
server.use_api_key("MASTER_KEY");
|
server.use_api_key("MASTER_KEY");
|
||||||
let app = test::init_service(create_app!(
|
let app = server.init_web_app().await;
|
||||||
&server.service.meilisearch,
|
|
||||||
&server.service.auth,
|
|
||||||
true,
|
|
||||||
server.service.options,
|
|
||||||
analytics::MockAnalytics::new(&server.service.options).0
|
|
||||||
))
|
|
||||||
.await;
|
|
||||||
|
|
||||||
// post
|
// post
|
||||||
let req = test::TestRequest::post()
|
let req = test::TestRequest::post()
|
||||||
@ -159,14 +144,7 @@ async fn error_api_key_missing_content_types() {
|
|||||||
|
|
||||||
let mut server = Server::new_auth().await;
|
let mut server = Server::new_auth().await;
|
||||||
server.use_api_key("MASTER_KEY");
|
server.use_api_key("MASTER_KEY");
|
||||||
let app = test::init_service(create_app!(
|
let app = server.init_web_app().await;
|
||||||
&server.service.meilisearch,
|
|
||||||
&server.service.auth,
|
|
||||||
true,
|
|
||||||
server.service.options,
|
|
||||||
analytics::MockAnalytics::new(&server.service.options).0
|
|
||||||
))
|
|
||||||
.await;
|
|
||||||
|
|
||||||
// post
|
// post
|
||||||
let req = test::TestRequest::post()
|
let req = test::TestRequest::post()
|
||||||
@ -223,14 +201,7 @@ async fn error_api_key_empty_payload() {
|
|||||||
|
|
||||||
let mut server = Server::new_auth().await;
|
let mut server = Server::new_auth().await;
|
||||||
server.use_api_key("MASTER_KEY");
|
server.use_api_key("MASTER_KEY");
|
||||||
let app = test::init_service(create_app!(
|
let app = server.init_web_app().await;
|
||||||
&server.service.meilisearch,
|
|
||||||
&server.service.auth,
|
|
||||||
true,
|
|
||||||
server.service.options,
|
|
||||||
analytics::MockAnalytics::new(&server.service.options).0
|
|
||||||
))
|
|
||||||
.await;
|
|
||||||
|
|
||||||
// post
|
// post
|
||||||
let req = test::TestRequest::post()
|
let req = test::TestRequest::post()
|
||||||
@ -279,14 +250,7 @@ async fn error_api_key_malformed_payload() {
|
|||||||
|
|
||||||
let mut server = Server::new_auth().await;
|
let mut server = Server::new_auth().await;
|
||||||
server.use_api_key("MASTER_KEY");
|
server.use_api_key("MASTER_KEY");
|
||||||
let app = test::init_service(create_app!(
|
let app = server.init_web_app().await;
|
||||||
&server.service.meilisearch,
|
|
||||||
&server.service.auth,
|
|
||||||
true,
|
|
||||||
server.service.options,
|
|
||||||
analytics::MockAnalytics::new(&server.service.options).0
|
|
||||||
))
|
|
||||||
.await;
|
|
||||||
|
|
||||||
// post
|
// post
|
||||||
let req = test::TestRequest::post()
|
let req = test::TestRequest::post()
|
||||||
|
@ -1,17 +1,19 @@
|
|||||||
#![allow(dead_code)]
|
#![allow(dead_code)]
|
||||||
|
|
||||||
|
use actix_http::body::MessageBody;
|
||||||
|
use actix_web::dev::ServiceResponse;
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
use actix_web::http::StatusCode;
|
use actix_web::http::StatusCode;
|
||||||
use byte_unit::{Byte, ByteUnit};
|
use byte_unit::{Byte, ByteUnit};
|
||||||
use meilisearch_auth::AuthController;
|
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
use tempfile::TempDir;
|
use tempfile::TempDir;
|
||||||
|
|
||||||
use meilisearch_http::option::{IndexerOpts, MaxMemory, Opt};
|
use meilisearch_http::option::{IndexerOpts, MaxMemory, Opt};
|
||||||
use meilisearch_http::setup_meilisearch;
|
use meilisearch_http::{analytics, create_app, setup_meilisearch};
|
||||||
use crate::common::encoder::Encoder;
|
use crate::common::encoder::Encoder;
|
||||||
|
|
||||||
use super::index::Index;
|
use super::index::Index;
|
||||||
@ -37,10 +39,9 @@ impl Server {
|
|||||||
|
|
||||||
let options = default_settings(dir.path());
|
let options = default_settings(dir.path());
|
||||||
|
|
||||||
let meilisearch = setup_meilisearch(&options).unwrap();
|
let (index_scheduler, auth) = setup_meilisearch(&options).unwrap();
|
||||||
let auth = AuthController::new(&options.db_path, &options.master_key).unwrap();
|
|
||||||
let service = Service {
|
let service = Service {
|
||||||
meilisearch,
|
index_scheduler: Arc::new(index_scheduler),
|
||||||
auth,
|
auth,
|
||||||
options,
|
options,
|
||||||
api_key: None,
|
api_key: None,
|
||||||
@ -61,10 +62,9 @@ impl Server {
|
|||||||
|
|
||||||
options.master_key = Some("MASTER_KEY".to_string());
|
options.master_key = Some("MASTER_KEY".to_string());
|
||||||
|
|
||||||
let meilisearch = setup_meilisearch(&options).unwrap();
|
let (index_scheduler, auth) = setup_meilisearch(&options).unwrap();
|
||||||
let auth = AuthController::new(&options.db_path, &options.master_key).unwrap();
|
|
||||||
let service = Service {
|
let service = Service {
|
||||||
meilisearch,
|
index_scheduler: Arc::new(index_scheduler),
|
||||||
auth,
|
auth,
|
||||||
options,
|
options,
|
||||||
api_key: None,
|
api_key: None,
|
||||||
@ -83,10 +83,9 @@ impl Server {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn new_with_options(options: Opt) -> Result<Self, anyhow::Error> {
|
pub async fn new_with_options(options: Opt) -> Result<Self, anyhow::Error> {
|
||||||
let meilisearch = setup_meilisearch(&options)?;
|
let (index_scheduler, auth) = setup_meilisearch(&options)?;
|
||||||
let auth = AuthController::new(&options.db_path, &options.master_key)?;
|
|
||||||
let service = Service {
|
let service = Service {
|
||||||
meilisearch,
|
index_scheduler: Arc::new(index_scheduler),
|
||||||
auth,
|
auth,
|
||||||
options,
|
options,
|
||||||
api_key: None,
|
api_key: None,
|
||||||
@ -98,6 +97,23 @@ impl Server {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn init_web_app(
|
||||||
|
&self,
|
||||||
|
) -> impl actix_web::dev::Service<
|
||||||
|
actix_http::Request,
|
||||||
|
Response = ServiceResponse<impl MessageBody>,
|
||||||
|
Error = actix_web::Error,
|
||||||
|
> {
|
||||||
|
actix_web::test::init_service(create_app(
|
||||||
|
self.service.index_scheduler.clone().into(),
|
||||||
|
self.service.auth.clone(),
|
||||||
|
self.service.options.clone(),
|
||||||
|
analytics::MockAnalytics::new(&self.service.options),
|
||||||
|
true,
|
||||||
|
))
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns a view to an index. There is no guarantee that the index exists.
|
/// Returns a view to an index. There is no guarantee that the index exists.
|
||||||
pub fn index(&self, uid: impl AsRef<str>) -> Index<'_> {
|
pub fn index(&self, uid: impl AsRef<str>) -> Index<'_> {
|
||||||
self.index_with_encoder(uid, Encoder::Plain)
|
self.index_with_encoder(uid, Encoder::Plain)
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
use actix_web::http::header::ContentType;
|
use actix_web::http::header::ContentType;
|
||||||
use actix_web::test::TestRequest;
|
use actix_web::test::TestRequest;
|
||||||
use actix_web::{http::StatusCode, test};
|
use actix_web::{http::StatusCode, test};
|
||||||
@ -9,7 +11,7 @@ use crate::common::encoder::Encoder;
|
|||||||
use meilisearch_http::{analytics, create_app, Opt};
|
use meilisearch_http::{analytics, create_app, Opt};
|
||||||
|
|
||||||
pub struct Service {
|
pub struct Service {
|
||||||
pub index_scheduler: IndexScheduler,
|
pub index_scheduler: Arc<IndexScheduler>,
|
||||||
pub auth: AuthController,
|
pub auth: AuthController,
|
||||||
pub options: Opt,
|
pub options: Opt,
|
||||||
pub api_key: Option<String>,
|
pub api_key: Option<String>,
|
||||||
@ -85,12 +87,12 @@ impl Service {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn request(&self, mut req: test::TestRequest) -> (Value, StatusCode) {
|
pub async fn request(&self, mut req: test::TestRequest) -> (Value, StatusCode) {
|
||||||
let app = test::init_service(create_app!(
|
let app = test::init_service(create_app(
|
||||||
&self.meilisearch,
|
self.index_scheduler.clone().into(),
|
||||||
&self.auth,
|
self.auth.clone(),
|
||||||
|
self.options.clone(),
|
||||||
|
analytics::MockAnalytics::new(&self.options),
|
||||||
true,
|
true,
|
||||||
self.options,
|
|
||||||
analytics::MockAnalytics::new(&self.options).0
|
|
||||||
))
|
))
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
|
@ -4,7 +4,6 @@ mod common;
|
|||||||
|
|
||||||
use crate::common::Server;
|
use crate::common::Server;
|
||||||
use actix_web::test;
|
use actix_web::test;
|
||||||
use meilisearch_http::{analytics, create_app};
|
|
||||||
use serde_json::{json, Value};
|
use serde_json::{json, Value};
|
||||||
|
|
||||||
enum HttpVerb {
|
enum HttpVerb {
|
||||||
@ -59,14 +58,8 @@ async fn error_json_bad_content_type() {
|
|||||||
|
|
||||||
let document = "{}";
|
let document = "{}";
|
||||||
let server = Server::new().await;
|
let server = Server::new().await;
|
||||||
let app = test::init_service(create_app!(
|
let app = server.init_web_app().await;
|
||||||
&server.service.meilisearch,
|
|
||||||
&server.service.auth,
|
|
||||||
true,
|
|
||||||
server.service.options,
|
|
||||||
analytics::MockAnalytics::new(&server.service.options).0
|
|
||||||
))
|
|
||||||
.await;
|
|
||||||
for (verb, route) in routes {
|
for (verb, route) in routes {
|
||||||
// Good content-type, we probably have an error since we didn't send anything in the json
|
// Good content-type, we probably have an error since we didn't send anything in the json
|
||||||
// so we only ensure we didn't get a bad media type error.
|
// so we only ensure we didn't get a bad media type error.
|
||||||
@ -142,14 +135,7 @@ async fn extract_actual_content_type() {
|
|||||||
let route = "/indexes/doggo/documents";
|
let route = "/indexes/doggo/documents";
|
||||||
let documents = "[{}]";
|
let documents = "[{}]";
|
||||||
let server = Server::new().await;
|
let server = Server::new().await;
|
||||||
let app = test::init_service(create_app!(
|
let app = server.init_web_app().await;
|
||||||
&server.service.meilisearch,
|
|
||||||
&server.service.auth,
|
|
||||||
true,
|
|
||||||
server.service.options,
|
|
||||||
analytics::MockAnalytics::new(&server.service.options).0
|
|
||||||
))
|
|
||||||
.await;
|
|
||||||
|
|
||||||
// Good content-type, we probably have an error since we didn't send anything in the json
|
// Good content-type, we probably have an error since we didn't send anything in the json
|
||||||
// so we only ensure we didn't get a bad media type error.
|
// so we only ensure we didn't get a bad media type error.
|
||||||
|
@ -18,14 +18,8 @@ async fn add_documents_test_json_content_types() {
|
|||||||
|
|
||||||
// this is a what is expected and should work
|
// this is a what is expected and should work
|
||||||
let server = Server::new().await;
|
let server = Server::new().await;
|
||||||
let app = test::init_service(create_app!(
|
let app = server.init_web_app().await;
|
||||||
&server.service.meilisearch,
|
|
||||||
&server.service.auth,
|
|
||||||
true,
|
|
||||||
server.service.options,
|
|
||||||
analytics::MockAnalytics::new(&server.service.options).0
|
|
||||||
))
|
|
||||||
.await;
|
|
||||||
// post
|
// post
|
||||||
let req = test::TestRequest::post()
|
let req = test::TestRequest::post()
|
||||||
.uri("/indexes/dog/documents")
|
.uri("/indexes/dog/documents")
|
||||||
@ -63,14 +57,8 @@ async fn add_single_document_test_json_content_types() {
|
|||||||
|
|
||||||
// this is a what is expected and should work
|
// this is a what is expected and should work
|
||||||
let server = Server::new().await;
|
let server = Server::new().await;
|
||||||
let app = test::init_service(create_app!(
|
let app = server.init_web_app().await;
|
||||||
&server.service.meilisearch,
|
|
||||||
&server.service.auth,
|
|
||||||
true,
|
|
||||||
server.service.options,
|
|
||||||
analytics::MockAnalytics::new(&server.service.options).0
|
|
||||||
))
|
|
||||||
.await;
|
|
||||||
// post
|
// post
|
||||||
let req = test::TestRequest::post()
|
let req = test::TestRequest::post()
|
||||||
.uri("/indexes/dog/documents")
|
.uri("/indexes/dog/documents")
|
||||||
@ -198,14 +186,8 @@ async fn error_add_documents_test_bad_content_types() {
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
let server = Server::new().await;
|
let server = Server::new().await;
|
||||||
let app = test::init_service(create_app!(
|
let app = server.init_web_app().await;
|
||||||
&server.service.meilisearch,
|
|
||||||
&server.service.auth,
|
|
||||||
true,
|
|
||||||
server.service.options,
|
|
||||||
analytics::MockAnalytics::new(&server.service.options).0
|
|
||||||
))
|
|
||||||
.await;
|
|
||||||
// post
|
// post
|
||||||
let req = test::TestRequest::post()
|
let req = test::TestRequest::post()
|
||||||
.uri("/indexes/dog/documents")
|
.uri("/indexes/dog/documents")
|
||||||
@ -266,14 +248,8 @@ async fn error_add_documents_test_no_content_type() {
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
let server = Server::new().await;
|
let server = Server::new().await;
|
||||||
let app = test::init_service(create_app!(
|
let app = server.init_web_app().await;
|
||||||
&server.service.meilisearch,
|
|
||||||
&server.service.auth,
|
|
||||||
true,
|
|
||||||
server.service.options,
|
|
||||||
analytics::MockAnalytics::new(&server.service.options).0
|
|
||||||
))
|
|
||||||
.await;
|
|
||||||
// post
|
// post
|
||||||
let req = test::TestRequest::post()
|
let req = test::TestRequest::post()
|
||||||
.uri("/indexes/dog/documents")
|
.uri("/indexes/dog/documents")
|
||||||
@ -326,14 +302,8 @@ async fn error_add_malformed_csv_documents() {
|
|||||||
let document = "id, content\n1234, hello, world\n12, hello world";
|
let document = "id, content\n1234, hello, world\n12, hello world";
|
||||||
|
|
||||||
let server = Server::new().await;
|
let server = Server::new().await;
|
||||||
let app = test::init_service(create_app!(
|
let app = server.init_web_app().await;
|
||||||
&server.service.meilisearch,
|
|
||||||
&server.service.auth,
|
|
||||||
true,
|
|
||||||
server.service.options,
|
|
||||||
analytics::MockAnalytics::new(&server.service.options).0
|
|
||||||
))
|
|
||||||
.await;
|
|
||||||
// post
|
// post
|
||||||
let req = test::TestRequest::post()
|
let req = test::TestRequest::post()
|
||||||
.uri("/indexes/dog/documents")
|
.uri("/indexes/dog/documents")
|
||||||
@ -388,14 +358,8 @@ async fn error_add_malformed_json_documents() {
|
|||||||
let document = r#"[{"id": 1}, {id: 2}]"#;
|
let document = r#"[{"id": 1}, {id: 2}]"#;
|
||||||
|
|
||||||
let server = Server::new().await;
|
let server = Server::new().await;
|
||||||
let app = test::init_service(create_app!(
|
let app = server.init_web_app().await;
|
||||||
&server.service.meilisearch,
|
|
||||||
&server.service.auth,
|
|
||||||
true,
|
|
||||||
server.service.options,
|
|
||||||
analytics::MockAnalytics::new(&server.service.options).0
|
|
||||||
))
|
|
||||||
.await;
|
|
||||||
// post
|
// post
|
||||||
let req = test::TestRequest::post()
|
let req = test::TestRequest::post()
|
||||||
.uri("/indexes/dog/documents")
|
.uri("/indexes/dog/documents")
|
||||||
@ -500,14 +464,8 @@ async fn error_add_malformed_ndjson_documents() {
|
|||||||
let document = "{\"id\": 1}\n{id: 2}";
|
let document = "{\"id\": 1}\n{id: 2}";
|
||||||
|
|
||||||
let server = Server::new().await;
|
let server = Server::new().await;
|
||||||
let app = test::init_service(create_app!(
|
let app = server.init_web_app().await;
|
||||||
&server.service.meilisearch,
|
|
||||||
&server.service.auth,
|
|
||||||
true,
|
|
||||||
server.service.options,
|
|
||||||
analytics::MockAnalytics::new(&server.service.options).0
|
|
||||||
))
|
|
||||||
.await;
|
|
||||||
// post
|
// post
|
||||||
let req = test::TestRequest::post()
|
let req = test::TestRequest::post()
|
||||||
.uri("/indexes/dog/documents")
|
.uri("/indexes/dog/documents")
|
||||||
@ -560,14 +518,8 @@ async fn error_add_missing_payload_csv_documents() {
|
|||||||
let document = "";
|
let document = "";
|
||||||
|
|
||||||
let server = Server::new().await;
|
let server = Server::new().await;
|
||||||
let app = test::init_service(create_app!(
|
let app = server.init_web_app().await;
|
||||||
&server.service.meilisearch,
|
|
||||||
&server.service.auth,
|
|
||||||
true,
|
|
||||||
server.service.options,
|
|
||||||
analytics::MockAnalytics::new(&server.service.options).0
|
|
||||||
))
|
|
||||||
.await;
|
|
||||||
// post
|
// post
|
||||||
let req = test::TestRequest::post()
|
let req = test::TestRequest::post()
|
||||||
.uri("/indexes/dog/documents")
|
.uri("/indexes/dog/documents")
|
||||||
@ -612,14 +564,8 @@ async fn error_add_missing_payload_json_documents() {
|
|||||||
let document = "";
|
let document = "";
|
||||||
|
|
||||||
let server = Server::new().await;
|
let server = Server::new().await;
|
||||||
let app = test::init_service(create_app!(
|
let app = server.init_web_app().await;
|
||||||
&server.service.meilisearch,
|
|
||||||
&server.service.auth,
|
|
||||||
true,
|
|
||||||
server.service.options,
|
|
||||||
analytics::MockAnalytics::new(&server.service.options).0
|
|
||||||
))
|
|
||||||
.await;
|
|
||||||
// post
|
// post
|
||||||
let req = test::TestRequest::post()
|
let req = test::TestRequest::post()
|
||||||
.uri("/indexes/dog/documents")
|
.uri("/indexes/dog/documents")
|
||||||
@ -664,14 +610,8 @@ async fn error_add_missing_payload_ndjson_documents() {
|
|||||||
let document = "";
|
let document = "";
|
||||||
|
|
||||||
let server = Server::new().await;
|
let server = Server::new().await;
|
||||||
let app = test::init_service(create_app!(
|
let app = server.init_web_app().await;
|
||||||
&server.service.meilisearch,
|
|
||||||
&server.service.auth,
|
|
||||||
true,
|
|
||||||
server.service.options,
|
|
||||||
analytics::MockAnalytics::new(&server.service.options).0
|
|
||||||
))
|
|
||||||
.await;
|
|
||||||
// post
|
// post
|
||||||
let req = test::TestRequest::post()
|
let req = test::TestRequest::post()
|
||||||
.uri("/indexes/dog/documents")
|
.uri("/indexes/dog/documents")
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
use meilisearch_http::analytics;
|
||||||
|
|
||||||
mod auth;
|
mod auth;
|
||||||
mod common;
|
mod common;
|
||||||
mod dashboard;
|
mod dashboard;
|
||||||
|
Loading…
Reference in New Issue
Block a user