mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-25 19:45:05 +08:00
add delete_index_fail function
This commit is contained in:
parent
2654ce6e6c
commit
2a18917af3
@ -272,6 +272,20 @@ impl<'a> Index<'a, Shared> {
|
|||||||
}
|
}
|
||||||
(task, code)
|
(task, code)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn delete_index_fail(&self) -> (Value, StatusCode) {
|
||||||
|
let (mut task, code) = self._delete().await;
|
||||||
|
if code.is_success() {
|
||||||
|
task = self.wait_task(task.uid()).await;
|
||||||
|
if task.is_success() {
|
||||||
|
panic!(
|
||||||
|
"`delete_index_fail` succeeded: {}",
|
||||||
|
serde_json::to_string_pretty(&task).unwrap()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
(task, code)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
@ -314,6 +328,12 @@ impl<State> Index<'_, State> {
|
|||||||
});
|
});
|
||||||
self.service.post_encoded("/indexes", body, self.encoder).await
|
self.service.post_encoded("/indexes", body, self.encoder).await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(super) async fn _delete(&self) -> (Value, StatusCode) {
|
||||||
|
let url = format!("/indexes/{}", urlencode(self.uid.as_ref()));
|
||||||
|
self.service.delete(url).await
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn wait_task(&self, update_id: u64) -> Value {
|
pub async fn wait_task(&self, update_id: u64) -> Value {
|
||||||
// try several times to get status, or panic to not wait forever
|
// try several times to get status, or panic to not wait forever
|
||||||
let url = format!("/tasks/{}", update_id);
|
let url = format!("/tasks/{}", update_id);
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use crate::common::Server;
|
use crate::common::{shared_does_not_exists_index, Server};
|
||||||
use crate::json;
|
use crate::json;
|
||||||
|
|
||||||
#[actix_rt::test]
|
#[actix_rt::test]
|
||||||
@ -24,18 +24,13 @@ async fn create_and_delete_index() {
|
|||||||
|
|
||||||
#[actix_rt::test]
|
#[actix_rt::test]
|
||||||
async fn error_delete_unexisting_index() {
|
async fn error_delete_unexisting_index() {
|
||||||
let server = Server::new_shared();
|
let index = shared_does_not_exists_index().await;
|
||||||
let index = server.unique_index();
|
let (task, code) = index.delete_index_fail().await;
|
||||||
let (task, code) = index.delete().await;
|
|
||||||
|
|
||||||
assert_eq!(code, 202);
|
assert_eq!(code, 202);
|
||||||
|
|
||||||
let msg = format!(
|
|
||||||
"Index `{}` not found.",
|
|
||||||
task["indexUid"].as_str().expect("indexUid should exist").trim_matches('"')
|
|
||||||
);
|
|
||||||
let expected_response = json!({
|
let expected_response = json!({
|
||||||
"message": msg,
|
"message": "Index `DOES_NOT_EXISTS` not found.",
|
||||||
"code": "index_not_found",
|
"code": "index_not_found",
|
||||||
"type": "invalid_request",
|
"type": "invalid_request",
|
||||||
"link": "https://docs.meilisearch.com/errors#index_not_found"
|
"link": "https://docs.meilisearch.com/errors#index_not_found"
|
||||||
|
Loading…
Reference in New Issue
Block a user