test delete batches

This commit is contained in:
mpostma 2021-02-23 14:13:43 +01:00
parent d3758b6f76
commit 0a3e946726
No known key found for this signature in database
GPG Key ID: CBC8A7C1D7A28C3A
4 changed files with 51 additions and 2 deletions

View File

@ -103,8 +103,8 @@ pub struct Opt {
pub sentry_dsn: String,
/// Disable Sentry error reporting.
#[cfg(all(not(debug_assertions), feature = "sentry"))]
#[structopt(long, env = "MEILI_NO_SENTRY")]
#[cfg(all(not(debug_assertions), feature = "sentry"))]
pub no_sentry: bool,
/// This environment variable must be set to `production` if you are running in production.

View File

@ -126,6 +126,11 @@ impl Index<'_> {
let url = format!("/indexes/{}/documents", self.uid);
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;

View File

@ -43,6 +43,10 @@ impl Server {
snapshot_interval_sec: None,
import_dump: None,
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();

View File

@ -28,6 +28,7 @@ async fn delete_one_document() {
index.wait_update_id(0).await;
let (_response, code) = server.index("test").delete_document(0).await;
assert_eq!(code, 200);
index.wait_update_id(1).await;
let (_response, code) = index.get_document(0, None).await;
assert_eq!(code, 400);
@ -50,7 +51,7 @@ async fn clear_all_documents() {
let (_response, code) = index.clear_all_documents().await;
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;
assert_eq!(code, 200);
assert!(response.as_array().unwrap().is_empty());
@ -70,3 +71,42 @@ async fn clear_all_documents_empty_index() {
assert_eq!(code, 200);
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);
}