From 6280bd51a9a633ea8b7e7096845722317e6cdaa2 Mon Sep 17 00:00:00 2001 From: Irevoire Date: Thu, 27 Oct 2022 00:56:34 +0200 Subject: [PATCH] actually fix the test and the swap_indexes name resolution --- meilisearch-http/src/routes/swap_indexes.rs | 29 ++----------- meilisearch-http/tests/tasks/mod.rs | 45 +++++++++++++++------ 2 files changed, 36 insertions(+), 38 deletions(-) diff --git a/meilisearch-http/src/routes/swap_indexes.rs b/meilisearch-http/src/routes/swap_indexes.rs index 6498e4692..5b939e8cc 100644 --- a/meilisearch-http/src/routes/swap_indexes.rs +++ b/meilisearch-http/src/routes/swap_indexes.rs @@ -7,6 +7,7 @@ use meilisearch_types::error::ResponseError; use meilisearch_types::tasks::{IndexSwap, KindWithContent}; use serde::Deserialize; +use super::SummarizedTaskView; use crate::error::MeilisearchHttpError; use crate::extractors::authentication::policies::*; use crate::extractors::authentication::{AuthenticationError, GuardedData}; @@ -31,7 +32,6 @@ pub async fn swap_indexes( let mut swaps = vec![]; let mut indexes_set = BTreeSet::::default(); let mut unauthorized_indexes = BTreeSet::new(); - let mut unknown_indexes = BTreeSet::new(); let mut duplicate_indexes = BTreeSet::new(); for SwapIndexesPayload { indexes } in params.into_inner().into_iter() { let (lhs, rhs) = match indexes.as_slice() { @@ -46,20 +46,6 @@ pub async fn swap_indexes( if !search_rules.is_index_authorized(rhs) { unauthorized_indexes.insert(rhs.clone()); } - match index_scheduler.index(lhs) { - Ok(_) => (), - Err(index_scheduler::Error::IndexNotFound(_)) => { - unknown_indexes.insert(lhs.clone()); - } - Err(e) => return Err(e.into()), - } - match index_scheduler.index(rhs) { - Ok(_) => (), - Err(index_scheduler::Error::IndexNotFound(_)) => { - unknown_indexes.insert(rhs.clone()); - } - Err(e) => return Err(e.into()), - } swaps.push(IndexSwap { indexes: (lhs.clone(), rhs.clone()) }); @@ -83,19 +69,10 @@ pub async fn swap_indexes( if !unauthorized_indexes.is_empty() { return Err(AuthenticationError::InvalidToken.into()); } - if !unknown_indexes.is_empty() { - let unknown_indexes: Vec<_> = unknown_indexes.into_iter().collect(); - if let [index] = unknown_indexes.as_slice() { - return Err(index_scheduler::Error::IndexNotFound(index.clone()).into()); - } else { - return Err(MeilisearchHttpError::IndexesNotFound(unknown_indexes).into()); - } - } let task = KindWithContent::IndexSwap { swaps }; let task = index_scheduler.register(task)?; - let task_view = TaskView::from_task(&task); - - Ok(HttpResponse::Accepted().json(task_view)) + let task: SummarizedTaskView = task.into(); + Ok(HttpResponse::Accepted().json(task)) } diff --git a/meilisearch-http/tests/tasks/mod.rs b/meilisearch-http/tests/tasks/mod.rs index 1421f63a4..60a243bbb 100644 --- a/meilisearch-http/tests/tasks/mod.rs +++ b/meilisearch-http/tests/tasks/mod.rs @@ -677,21 +677,43 @@ async fn test_summarized_index_update() { } #[actix_web::test] -#[ignore] async fn test_summarized_index_swap() { let server = Server::new().await; - let (v, _) = server + server .index_swap(json!([ { "indexes": ["doggos", "cattos"] } ])) .await; - dbg!(&v); - assert_json_snapshot!(v, @r###" + server.wait_task(0).await; + let (task, _) = server.get_task(0).await; + assert_json_snapshot!(task, + { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }, + @r###" { - "message": "Indexes `cattos`, `doggos` not found.", - "code": "index_not_found", - "type": "invalid_request", - "link": "https://docs.meilisearch.com/errors#index_not_found" + "uid": 0, + "indexUid": null, + "status": "failed", + "type": "indexSwap", + "details": { + "swaps": [ + { + "indexes": [ + "doggos", + "cattos" + ] + } + ] + }, + "error": { + "message": "Index `doggos` not found.", + "code": "index_not_found", + "type": "invalid_request", + "link": "https://docs.meilisearch.com/errors#index_not_found" + }, + "duration": "[duration]", + "enqueuedAt": "[date]", + "startedAt": "[date]", + "finishedAt": "[date]" } "###); @@ -702,14 +724,13 @@ async fn test_summarized_index_swap() { { "indexes": ["doggos", "cattos"] } ])) .await; - dbg!(ret); - server.wait_task(2).await; - let (task, _) = server.get_task(2).await; + server.wait_task(3).await; + let (task, _) = server.get_task(3).await; assert_json_snapshot!(task, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }, @r###" { - "uid": 2, + "uid": 3, "indexUid": null, "status": "succeeded", "type": "indexSwap",