mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-26 20:15:07 +08:00
test delete batches
This commit is contained in:
parent
d3758b6f76
commit
0a3e946726
@ -103,8 +103,8 @@ pub struct Opt {
|
|||||||
pub sentry_dsn: String,
|
pub sentry_dsn: String,
|
||||||
|
|
||||||
/// Disable Sentry error reporting.
|
/// Disable Sentry error reporting.
|
||||||
#[cfg(all(not(debug_assertions), feature = "sentry"))]
|
|
||||||
#[structopt(long, env = "MEILI_NO_SENTRY")]
|
#[structopt(long, env = "MEILI_NO_SENTRY")]
|
||||||
|
#[cfg(all(not(debug_assertions), feature = "sentry"))]
|
||||||
pub no_sentry: bool,
|
pub no_sentry: bool,
|
||||||
|
|
||||||
/// This environment variable must be set to `production` if you are running in production.
|
/// This environment variable must be set to `production` if you are running in production.
|
||||||
|
@ -126,6 +126,11 @@ impl Index<'_> {
|
|||||||
let url = format!("/indexes/{}/documents", self.uid);
|
let url = format!("/indexes/{}/documents", self.uid);
|
||||||
self.service.delete(url).await
|
self.service.delete(url).await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn delete_batch(&self, ids: Vec<u64>) -> (Value, StatusCode) {
|
||||||
|
let url = format!("/indexes/{}/documents/delete-batch", self.uid);
|
||||||
|
self.service.post(url, serde_json::to_value(&ids).unwrap()).await
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct GetDocumentOptions;
|
pub struct GetDocumentOptions;
|
||||||
|
@ -43,6 +43,10 @@ impl Server {
|
|||||||
snapshot_interval_sec: None,
|
snapshot_interval_sec: None,
|
||||||
import_dump: None,
|
import_dump: None,
|
||||||
indexer_options: IndexerOpts::default(),
|
indexer_options: IndexerOpts::default(),
|
||||||
|
#[cfg(all(not(debug_assertions), feature = "sentry"))]
|
||||||
|
sentry_dsn: String::from(""),
|
||||||
|
#[cfg(all(not(debug_assertions), feature = "sentry"))]
|
||||||
|
no_sentry: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
let data = Data::new(opt).unwrap();
|
let data = Data::new(opt).unwrap();
|
||||||
|
@ -28,6 +28,7 @@ async fn delete_one_document() {
|
|||||||
index.wait_update_id(0).await;
|
index.wait_update_id(0).await;
|
||||||
let (_response, code) = server.index("test").delete_document(0).await;
|
let (_response, code) = server.index("test").delete_document(0).await;
|
||||||
assert_eq!(code, 200);
|
assert_eq!(code, 200);
|
||||||
|
index.wait_update_id(1).await;
|
||||||
|
|
||||||
let (_response, code) = index.get_document(0, None).await;
|
let (_response, code) = index.get_document(0, None).await;
|
||||||
assert_eq!(code, 400);
|
assert_eq!(code, 400);
|
||||||
@ -50,7 +51,7 @@ async fn clear_all_documents() {
|
|||||||
let (_response, code) = index.clear_all_documents().await;
|
let (_response, code) = index.clear_all_documents().await;
|
||||||
assert_eq!(code, 200);
|
assert_eq!(code, 200);
|
||||||
|
|
||||||
let _update = index.wait_update_id(0).await;
|
let _update = index.wait_update_id(1).await;
|
||||||
let (response, code) = index.get_all_documents(GetAllDocumentsOptions::default()).await;
|
let (response, code) = index.get_all_documents(GetAllDocumentsOptions::default()).await;
|
||||||
assert_eq!(code, 200);
|
assert_eq!(code, 200);
|
||||||
assert!(response.as_array().unwrap().is_empty());
|
assert!(response.as_array().unwrap().is_empty());
|
||||||
@ -70,3 +71,42 @@ async fn clear_all_documents_empty_index() {
|
|||||||
assert_eq!(code, 200);
|
assert_eq!(code, 200);
|
||||||
assert!(response.as_array().unwrap().is_empty());
|
assert!(response.as_array().unwrap().is_empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[actix_rt::test]
|
||||||
|
async fn delete_batch_unexisting_index() {
|
||||||
|
let server = Server::new().await;
|
||||||
|
let (_response, code) = server.index("test").delete_batch(vec![]).await;
|
||||||
|
assert_eq!(code, 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[actix_rt::test]
|
||||||
|
async fn delete_batch() {
|
||||||
|
let server = Server::new().await;
|
||||||
|
let index = server.index("test");
|
||||||
|
index.add_documents(json!([{ "id": 1, "content": "foobar" }, { "id": 0, "content": "foobar" }, { "id": 3, "content": "foobar" }]), Some("id")).await;
|
||||||
|
index.wait_update_id(0).await;
|
||||||
|
let (_response, code) = index.delete_batch(vec![1, 0]).await;
|
||||||
|
assert_eq!(code, 200);
|
||||||
|
|
||||||
|
let _update = index.wait_update_id(1).await;
|
||||||
|
let (response, code) = index.get_all_documents(GetAllDocumentsOptions::default()).await;
|
||||||
|
assert_eq!(code, 200);
|
||||||
|
assert_eq!(response.as_array().unwrap().len(), 1);
|
||||||
|
assert_eq!(response.as_array().unwrap()[0]["id"], 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[actix_rt::test]
|
||||||
|
async fn delete_no_document_batch() {
|
||||||
|
let server = Server::new().await;
|
||||||
|
let index = server.index("test");
|
||||||
|
index.add_documents(json!([{ "id": 1, "content": "foobar" }, { "id": 0, "content": "foobar" }, { "id": 3, "content": "foobar" }]), Some("id")).await;
|
||||||
|
index.wait_update_id(0).await;
|
||||||
|
let (_response, code) = index.delete_batch(vec![]).await;
|
||||||
|
assert_eq!(code, 200);
|
||||||
|
|
||||||
|
let _update = index.wait_update_id(1).await;
|
||||||
|
let (response, code) = index.get_all_documents(GetAllDocumentsOptions::default()).await;
|
||||||
|
assert_eq!(code, 200);
|
||||||
|
assert_eq!(response.as_array().unwrap().len(), 3);
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user