mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-26 12:05:05 +08:00
fix tests
This commit is contained in:
parent
0cd8869349
commit
a56e8c1a0c
7
Cargo.lock
generated
7
Cargo.lock
generated
@ -1817,6 +1817,7 @@ dependencies = [
|
|||||||
"tempfile",
|
"tempfile",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
"tokio 1.3.0",
|
"tokio 1.3.0",
|
||||||
|
"urlencoding",
|
||||||
"uuid",
|
"uuid",
|
||||||
"vergen",
|
"vergen",
|
||||||
]
|
]
|
||||||
@ -3503,6 +3504,12 @@ dependencies = [
|
|||||||
"serde",
|
"serde",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "urlencoding"
|
||||||
|
version = "1.1.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c9232eb53352b4442e40d7900465dfc534e8cb2dc8f18656fcb2ac16112b5593"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "utf8-width"
|
name = "utf8-width"
|
||||||
version = "0.1.4"
|
version = "0.1.4"
|
||||||
|
@ -74,6 +74,7 @@ serde_url_params = "0.2.0"
|
|||||||
tempdir = "0.3.7"
|
tempdir = "0.3.7"
|
||||||
assert-json-diff = { branch = "master", git = "https://github.com/qdequele/assert-json-diff" }
|
assert-json-diff = { branch = "master", git = "https://github.com/qdequele/assert-json-diff" }
|
||||||
actix-rt = "2.1.0"
|
actix-rt = "2.1.0"
|
||||||
|
urlencoding = "1.1.1"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["sentry"]
|
default = ["sentry"]
|
||||||
|
@ -2,7 +2,7 @@ use std::time::Duration;
|
|||||||
|
|
||||||
use actix_web::http::StatusCode;
|
use actix_web::http::StatusCode;
|
||||||
use serde_json::{json, Value};
|
use serde_json::{json, Value};
|
||||||
use tokio::time::delay_for;
|
use tokio::time::sleep;
|
||||||
|
|
||||||
use super::service::Service;
|
use super::service::Service;
|
||||||
|
|
||||||
@ -79,7 +79,7 @@ impl Index<'_> {
|
|||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
delay_for(Duration::from_secs(1)).await;
|
sleep(Duration::from_secs(1)).await;
|
||||||
}
|
}
|
||||||
panic!("Timeout waiting for update id");
|
panic!("Timeout waiting for update id");
|
||||||
}
|
}
|
||||||
|
@ -2,14 +2,14 @@ use actix_web::{http::StatusCode, test};
|
|||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
|
|
||||||
use meilisearch_http::data::Data;
|
use meilisearch_http::data::Data;
|
||||||
use meilisearch_http::helpers::NormalizePath;
|
use meilisearch_http::create_app;
|
||||||
|
|
||||||
pub struct Service(pub Data);
|
pub struct Service(pub Data);
|
||||||
|
|
||||||
impl Service {
|
impl Service {
|
||||||
pub async fn post(&self, url: impl AsRef<str>, body: Value) -> (Value, StatusCode) {
|
pub async fn post(&self, url: impl AsRef<str>, body: Value) -> (Value, StatusCode) {
|
||||||
let mut app =
|
let mut app =
|
||||||
test::init_service(meilisearch_http::create_app(&self.0, true).wrap(NormalizePath)).await;
|
test::init_service(create_app!(&self.0, true)).await;
|
||||||
|
|
||||||
let req = test::TestRequest::post()
|
let req = test::TestRequest::post()
|
||||||
.uri(url.as_ref())
|
.uri(url.as_ref())
|
||||||
@ -26,12 +26,12 @@ impl Service {
|
|||||||
/// Send a test post request from a text body, with a `content-type:application/json` header.
|
/// Send a test post request from a text body, with a `content-type:application/json` header.
|
||||||
pub async fn post_str(&self, url: impl AsRef<str>, body: impl AsRef<str>) -> (Value, StatusCode) {
|
pub async fn post_str(&self, url: impl AsRef<str>, body: impl AsRef<str>) -> (Value, StatusCode) {
|
||||||
let mut app =
|
let mut app =
|
||||||
test::init_service(meilisearch_http::create_app(&self.0, true).wrap(NormalizePath)).await;
|
test::init_service(create_app!(&self.0, true)).await;
|
||||||
|
|
||||||
let req = test::TestRequest::post()
|
let req = test::TestRequest::post()
|
||||||
.uri(url.as_ref())
|
.uri(url.as_ref())
|
||||||
.set_payload(body.as_ref().to_string())
|
.set_payload(body.as_ref().to_string())
|
||||||
.header("content-type", "application/json")
|
.insert_header(("content-type", "application/json"))
|
||||||
.to_request();
|
.to_request();
|
||||||
let res = test::call_service(&mut app, req).await;
|
let res = test::call_service(&mut app, req).await;
|
||||||
let status_code = res.status();
|
let status_code = res.status();
|
||||||
@ -43,7 +43,7 @@ impl Service {
|
|||||||
|
|
||||||
pub async fn get(&self, url: impl AsRef<str>) -> (Value, StatusCode) {
|
pub async fn get(&self, url: impl AsRef<str>) -> (Value, StatusCode) {
|
||||||
let mut app =
|
let mut app =
|
||||||
test::init_service(meilisearch_http::create_app(&self.0, true).wrap(NormalizePath)).await;
|
test::init_service(create_app!(&self.0, true)).await;
|
||||||
|
|
||||||
let req = test::TestRequest::get().uri(url.as_ref()).to_request();
|
let req = test::TestRequest::get().uri(url.as_ref()).to_request();
|
||||||
let res = test::call_service(&mut app, req).await;
|
let res = test::call_service(&mut app, req).await;
|
||||||
@ -56,7 +56,7 @@ impl Service {
|
|||||||
|
|
||||||
pub async fn put(&self, url: impl AsRef<str>, body: Value) -> (Value, StatusCode) {
|
pub async fn put(&self, url: impl AsRef<str>, body: Value) -> (Value, StatusCode) {
|
||||||
let mut app =
|
let mut app =
|
||||||
test::init_service(meilisearch_http::create_app(&self.0, true).wrap(NormalizePath)).await;
|
test::init_service(create_app!(&self.0, true)).await;
|
||||||
|
|
||||||
let req = test::TestRequest::put()
|
let req = test::TestRequest::put()
|
||||||
.uri(url.as_ref())
|
.uri(url.as_ref())
|
||||||
@ -72,7 +72,7 @@ impl Service {
|
|||||||
|
|
||||||
pub async fn delete(&self, url: impl AsRef<str>) -> (Value, StatusCode) {
|
pub async fn delete(&self, url: impl AsRef<str>) -> (Value, StatusCode) {
|
||||||
let mut app =
|
let mut app =
|
||||||
test::init_service(meilisearch_http::create_app(&self.0, true).wrap(NormalizePath)).await;
|
test::init_service(create_app!(&self.0, true)).await;
|
||||||
|
|
||||||
let req = test::TestRequest::delete().uri(url.as_ref()).to_request();
|
let req = test::TestRequest::delete().uri(url.as_ref()).to_request();
|
||||||
let res = test::call_service(&mut app, req).await;
|
let res = test::call_service(&mut app, req).await;
|
||||||
|
Loading…
Reference in New Issue
Block a user