diff --git a/meilisearch-auth/src/store.rs b/meilisearch-auth/src/store.rs index e6e30d18d..28ec8b5e4 100644 --- a/meilisearch-auth/src/store.rs +++ b/meilisearch-auth/src/store.rs @@ -129,6 +129,9 @@ impl HeedAuthStore { Action::DumpsAll => { actions.insert(Action::DumpsCreate); } + Action::SnapshotsAll => { + actions.insert(Action::SnapshotsCreate); + } Action::TasksAll => { actions.extend([Action::TasksGet, Action::TasksDelete, Action::TasksCancel]); } diff --git a/meilisearch-types/src/keys.rs b/meilisearch-types/src/keys.rs index cfeb3aa8f..f7d80bbcb 100644 --- a/meilisearch-types/src/keys.rs +++ b/meilisearch-types/src/keys.rs @@ -257,6 +257,12 @@ pub enum Action { #[serde(rename = "dumps.create")] #[deserr(rename = "dumps.create")] DumpsCreate, + #[serde(rename = "snapshots.*")] + #[deserr(rename = "snapshots.*")] + SnapshotsAll, + #[serde(rename = "snapshots.create")] + #[deserr(rename = "snapshots.create")] + SnapshotsCreate, #[serde(rename = "version")] #[deserr(rename = "version")] Version, @@ -309,6 +315,7 @@ impl Action { METRICS_GET => Some(Self::MetricsGet), DUMPS_ALL => Some(Self::DumpsAll), DUMPS_CREATE => Some(Self::DumpsCreate), + SNAPSHOTS_CREATE => Some(Self::SnapshotsCreate), VERSION => Some(Self::Version), KEYS_CREATE => Some(Self::KeysAdd), KEYS_GET => Some(Self::KeysGet), @@ -353,6 +360,7 @@ pub mod actions { pub const METRICS_GET: u8 = MetricsGet.repr(); pub const DUMPS_ALL: u8 = DumpsAll.repr(); pub const DUMPS_CREATE: u8 = DumpsCreate.repr(); + pub const SNAPSHOTS_CREATE: u8 = SnapshotsCreate.repr(); pub const VERSION: u8 = Version.repr(); pub const KEYS_CREATE: u8 = KeysAdd.repr(); pub const KEYS_GET: u8 = KeysGet.repr(); diff --git a/meilisearch/src/routes/mod.rs b/meilisearch/src/routes/mod.rs index 69bc44160..0e5623b09 100644 --- a/meilisearch/src/routes/mod.rs +++ b/meilisearch/src/routes/mod.rs @@ -24,6 +24,7 @@ pub mod features; pub mod indexes; mod metrics; mod multi_search; +mod snapshot; mod swap_indexes; pub mod tasks; @@ -32,6 +33,7 @@ pub fn configure(cfg: &mut web::ServiceConfig) { .service(web::resource("/health").route(web::get().to(get_health))) .service(web::scope("/keys").configure(api_key::configure)) .service(web::scope("/dumps").configure(dump::configure)) + .service(web::scope("/snapshots").configure(snapshot::configure)) .service(web::resource("/stats").route(web::get().to(get_stats))) .service(web::resource("/version").route(web::get().to(get_version))) .service(web::scope("/indexes").configure(indexes::configure)) diff --git a/meilisearch/src/routes/snapshot.rs b/meilisearch/src/routes/snapshot.rs new file mode 100644 index 000000000..7fa22658a --- /dev/null +++ b/meilisearch/src/routes/snapshot.rs @@ -0,0 +1,32 @@ +use actix_web::web::Data; +use actix_web::{web, HttpRequest, HttpResponse}; +use index_scheduler::IndexScheduler; +use log::debug; +use meilisearch_types::error::ResponseError; +use meilisearch_types::tasks::KindWithContent; +use serde_json::json; + +use crate::analytics::Analytics; +use crate::extractors::authentication::policies::*; +use crate::extractors::authentication::GuardedData; +use crate::extractors::sequential_extractor::SeqHandler; +use crate::routes::SummarizedTaskView; + +pub fn configure(cfg: &mut web::ServiceConfig) { + cfg.service(web::resource("").route(web::post().to(SeqHandler(create_snapshot)))); +} + +pub async fn create_snapshot( + index_scheduler: GuardedData, Data>, + req: HttpRequest, + analytics: web::Data, +) -> Result { + analytics.publish("Snapshot Created".to_string(), json!({}), Some(&req)); + + let task = KindWithContent::SnapshotCreation; + let task: SummarizedTaskView = + tokio::task::spawn_blocking(move || index_scheduler.register(task)).await??.into(); + + debug!("returns: {:?}", task); + Ok(HttpResponse::Accepted().json(task)) +} diff --git a/meilisearch/tests/auth/api_keys.rs b/meilisearch/tests/auth/api_keys.rs index a356a4dd6..253929428 100644 --- a/meilisearch/tests/auth/api_keys.rs +++ b/meilisearch/tests/auth/api_keys.rs @@ -1,8 +1,7 @@ use std::{thread, time}; -use serde_json::{json, Value}; - -use crate::common::Server; +use crate::common::{Server, Value}; +use crate::json; #[actix_rt::test] async fn add_valid_api_key() { @@ -162,7 +161,7 @@ async fn add_valid_api_key_null_description() { server.use_api_key("MASTER_KEY"); let content = json!({ - "description": Value::Null, + "description": json!(null), "indexes": ["products"], "actions": ["documents.add"], "expiresAt": "2050-11-13T00:00:00" @@ -365,7 +364,7 @@ async fn error_add_api_key_invalid_index_uids() { server.use_api_key("MASTER_KEY"); let content = json!({ - "description": Value::Null, + "description": json!(null), "indexes": ["invalid index # / \\name with spaces"], "actions": [ "documents.add" @@ -422,7 +421,7 @@ async fn error_add_api_key_invalid_parameters_actions() { meili_snap::snapshot!(code, @"400 Bad Request"); meili_snap::snapshot!(meili_snap::json_string!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]" }), @r###" { - "message": "Unknown value `doc.add` at `.actions[0]`: expected one of `*`, `search`, `documents.*`, `documents.add`, `documents.get`, `documents.delete`, `indexes.*`, `indexes.create`, `indexes.get`, `indexes.update`, `indexes.delete`, `indexes.swap`, `tasks.*`, `tasks.cancel`, `tasks.delete`, `tasks.get`, `settings.*`, `settings.get`, `settings.update`, `stats.*`, `stats.get`, `metrics.*`, `metrics.get`, `dumps.*`, `dumps.create`, `version`, `keys.create`, `keys.get`, `keys.update`, `keys.delete`, `experimental.get`, `experimental.update`", + "message": "Unknown value `doc.add` at `.actions[0]`: expected one of `*`, `search`, `documents.*`, `documents.add`, `documents.get`, `documents.delete`, `indexes.*`, `indexes.create`, `indexes.get`, `indexes.update`, `indexes.delete`, `indexes.swap`, `tasks.*`, `tasks.cancel`, `tasks.delete`, `tasks.get`, `settings.*`, `settings.get`, `settings.update`, `stats.*`, `stats.get`, `metrics.*`, `metrics.get`, `dumps.*`, `dumps.create`, `snapshots.*`, `snapshots.create`, `version`, `keys.create`, `keys.get`, `keys.update`, `keys.delete`, `experimental.get`, `experimental.update`", "code": "invalid_api_key_actions", "type": "invalid_request", "link": "https://docs.meilisearch.com/errors#invalid_api_key_actions" @@ -507,7 +506,7 @@ async fn error_add_api_key_invalid_parameters_uid() { async fn error_add_api_key_parameters_uid_already_exist() { let mut server = Server::new_auth().await; server.use_api_key("MASTER_KEY"); - let content = json!({ + let content: Value = json!({ "uid": "4bc0887a-0e41-4f3b-935d-0c451dcee9c8", "indexes": ["products"], "actions": ["search"], @@ -1146,7 +1145,7 @@ async fn patch_api_key_description() { meili_snap::snapshot!(code, @"200 OK"); // Remove the description - let content = json!({ "description": serde_json::Value::Null }); + let content = json!({ "description": null }); let (response, code) = server.patch_api_key(&uid, content).await; meili_snap::snapshot!(meili_snap::json_string!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]", ".uid" => "[ignored]", ".key" => "[ignored]" }), @r###" diff --git a/meilisearch/tests/auth/authorization.rs b/meilisearch/tests/auth/authorization.rs index 5af214e5f..883c23267 100644 --- a/meilisearch/tests/auth/authorization.rs +++ b/meilisearch/tests/auth/authorization.rs @@ -3,10 +3,10 @@ use std::collections::{HashMap, HashSet}; use ::time::format_description::well_known::Rfc3339; use maplit::{hashmap, hashset}; use once_cell::sync::Lazy; -use serde_json::{json, Value}; use time::{Duration, OffsetDateTime}; -use crate::common::Server; +use crate::common::{Server, Value}; +use crate::json; pub static AUTHORIZATIONS: Lazy>> = Lazy::new(|| { @@ -54,6 +54,7 @@ pub static AUTHORIZATIONS: Lazy hashset!{"stats.get", "stats.*", "*"}, ("GET", "/stats") => hashset!{"stats.get", "stats.*", "*"}, ("POST", "/dumps") => hashset!{"dumps.create", "dumps.*", "*"}, + ("POST", "/snapshots") => hashset!{"snapshots.create", "snapshots.*", "*"}, ("GET", "/version") => hashset!{"version", "*"}, ("GET", "/metrics") => hashset!{"metrics.get", "metrics.*", "*"}, ("PATCH", "/keys/mykey/") => hashset!{"keys.update", "*"}, diff --git a/meilisearch/tests/auth/errors.rs b/meilisearch/tests/auth/errors.rs index f81574abd..581243a0a 100644 --- a/meilisearch/tests/auth/errors.rs +++ b/meilisearch/tests/auth/errors.rs @@ -1,8 +1,8 @@ use meili_snap::*; -use serde_json::json; use uuid::Uuid; use crate::common::Server; +use crate::json; #[actix_rt::test] async fn create_api_key_bad_description() { @@ -90,7 +90,7 @@ async fn create_api_key_bad_actions() { snapshot!(code, @"400 Bad Request"); snapshot!(json_string!(response), @r###" { - "message": "Unknown value `doggo` at `.actions[0]`: expected one of `*`, `search`, `documents.*`, `documents.add`, `documents.get`, `documents.delete`, `indexes.*`, `indexes.create`, `indexes.get`, `indexes.update`, `indexes.delete`, `indexes.swap`, `tasks.*`, `tasks.cancel`, `tasks.delete`, `tasks.get`, `settings.*`, `settings.get`, `settings.update`, `stats.*`, `stats.get`, `metrics.*`, `metrics.get`, `dumps.*`, `dumps.create`, `version`, `keys.create`, `keys.get`, `keys.update`, `keys.delete`, `experimental.get`, `experimental.update`", + "message": "Unknown value `doggo` at `.actions[0]`: expected one of `*`, `search`, `documents.*`, `documents.add`, `documents.get`, `documents.delete`, `indexes.*`, `indexes.create`, `indexes.get`, `indexes.update`, `indexes.delete`, `indexes.swap`, `tasks.*`, `tasks.cancel`, `tasks.delete`, `tasks.get`, `settings.*`, `settings.get`, `settings.update`, `stats.*`, `stats.get`, `metrics.*`, `metrics.get`, `dumps.*`, `dumps.create`, `snapshots.*`, `snapshots.create`, `version`, `keys.create`, `keys.get`, `keys.update`, `keys.delete`, `experimental.get`, `experimental.update`", "code": "invalid_api_key_actions", "type": "invalid_request", "link": "https://docs.meilisearch.com/errors#invalid_api_key_actions" diff --git a/meilisearch/tests/auth/mod.rs b/meilisearch/tests/auth/mod.rs index 2d88bf87e..781b2dcc0 100644 --- a/meilisearch/tests/auth/mod.rs +++ b/meilisearch/tests/auth/mod.rs @@ -7,9 +7,9 @@ mod tenant_token; mod tenant_token_multi_search; use actix_web::http::StatusCode; -use serde_json::{json, Value}; -use crate::common::Server; +use crate::common::{Server, Value}; +use crate::json; impl Server { pub fn use_api_key(&mut self, api_key: impl AsRef) { diff --git a/meilisearch/tests/auth/tenant_token.rs b/meilisearch/tests/auth/tenant_token.rs index 3992a9aed..ba3b0b234 100644 --- a/meilisearch/tests/auth/tenant_token.rs +++ b/meilisearch/tests/auth/tenant_token.rs @@ -3,11 +3,11 @@ use std::collections::HashMap; use ::time::format_description::well_known::Rfc3339; use maplit::hashmap; use once_cell::sync::Lazy; -use serde_json::{json, Value}; use time::{Duration, OffsetDateTime}; use super::authorization::{ALL_ACTIONS, AUTHORIZATIONS}; -use crate::common::Server; +use crate::common::{Server, Value}; +use crate::json; fn generate_tenant_token( parent_uid: impl AsRef, @@ -233,31 +233,31 @@ async fn search_authorized_simple_token() { }, hashmap! { "searchRules" => json!({"*": {}}), - "exp" => Value::Null + "exp" => json!(null) }, hashmap! { - "searchRules" => json!({"*": Value::Null}), - "exp" => Value::Null + "searchRules" => json!({"*": null}), + "exp" => json!(null) }, hashmap! { "searchRules" => json!(["*"]), - "exp" => Value::Null + "exp" => json!(null) }, hashmap! { "searchRules" => json!({"sales": {}}), - "exp" => Value::Null + "exp" => json!(null) }, hashmap! { - "searchRules" => json!({"sales": Value::Null}), - "exp" => Value::Null + "searchRules" => json!({"sales": null}), + "exp" => json!(null) }, hashmap! { "searchRules" => json!(["sales"]), - "exp" => Value::Null + "exp" => json!(null) }, hashmap! { "searchRules" => json!(["sa*"]), - "exp" => Value::Null + "exp" => json!(null) }, ]; @@ -386,7 +386,7 @@ async fn error_search_token_forbidden_parent_key() { "exp" => json!((OffsetDateTime::now_utc() + Duration::hours(1)).unix_timestamp()) }, hashmap! { - "searchRules" => json!({"*": Value::Null}), + "searchRules" => json!({"*": null}), "exp" => json!((OffsetDateTime::now_utc() + Duration::hours(1)).unix_timestamp()) }, hashmap! { @@ -398,7 +398,7 @@ async fn error_search_token_forbidden_parent_key() { "exp" => json!((OffsetDateTime::now_utc() + Duration::hours(1)).unix_timestamp()) }, hashmap! { - "searchRules" => json!({"sales": Value::Null}), + "searchRules" => json!({"sales": null}), "exp" => json!((OffsetDateTime::now_utc() + Duration::hours(1)).unix_timestamp()) }, hashmap! { @@ -428,15 +428,15 @@ async fn error_search_forbidden_token() { }, hashmap! { "searchRules" => json!({"products": {}}), - "exp" => Value::Null + "exp" => json!(null) }, hashmap! { - "searchRules" => json!({"products": Value::Null}), - "exp" => Value::Null + "searchRules" => json!({"products": null}), + "exp" => json!(null) }, hashmap! { "searchRules" => json!(["products"]), - "exp" => Value::Null + "exp" => json!(null) }, // expired token hashmap! { @@ -444,7 +444,7 @@ async fn error_search_forbidden_token() { "exp" => json!((OffsetDateTime::now_utc() - Duration::hours(1)).unix_timestamp()) }, hashmap! { - "searchRules" => json!({"*": Value::Null}), + "searchRules" => json!({"*": null}), "exp" => json!((OffsetDateTime::now_utc() - Duration::hours(1)).unix_timestamp()) }, hashmap! { @@ -456,7 +456,7 @@ async fn error_search_forbidden_token() { "exp" => json!((OffsetDateTime::now_utc() - Duration::hours(1)).unix_timestamp()) }, hashmap! { - "searchRules" => json!({"sales": Value::Null}), + "searchRules" => json!({"sales": null}), "exp" => json!((OffsetDateTime::now_utc() - Duration::hours(1)).unix_timestamp()) }, hashmap! { diff --git a/meilisearch/tests/auth/tenant_token_multi_search.rs b/meilisearch/tests/auth/tenant_token_multi_search.rs index ef206ea3d..09b5dbbcc 100644 --- a/meilisearch/tests/auth/tenant_token_multi_search.rs +++ b/meilisearch/tests/auth/tenant_token_multi_search.rs @@ -3,11 +3,11 @@ use std::collections::HashMap; use ::time::format_description::well_known::Rfc3339; use maplit::hashmap; use once_cell::sync::Lazy; -use serde_json::{json, Value}; use time::{Duration, OffsetDateTime}; use super::authorization::ALL_ACTIONS; -use crate::common::Server; +use crate::common::{Server, Value}; +use crate::json; fn generate_tenant_token( parent_uid: impl AsRef, @@ -512,31 +512,31 @@ async fn single_search_authorized_simple_token() { }, hashmap! { "searchRules" => json!({"*": {}}), - "exp" => Value::Null + "exp" => json!(null), }, hashmap! { - "searchRules" => json!({"*": Value::Null}), - "exp" => Value::Null + "searchRules" => json!({"*": null}), + "exp" => json!(null), }, hashmap! { "searchRules" => json!(["*"]), - "exp" => Value::Null + "exp" => json!(null), }, hashmap! { "searchRules" => json!({"sales": {}}), - "exp" => Value::Null + "exp" => json!(null), }, hashmap! { - "searchRules" => json!({"sales": Value::Null}), - "exp" => Value::Null + "searchRules" => json!({"sales": null}), + "exp" => json!(null), }, hashmap! { "searchRules" => json!(["sales"]), - "exp" => Value::Null + "exp" => json!(null), }, hashmap! { "searchRules" => json!(["sa*"]), - "exp" => Value::Null + "exp" => json!(null), }, ]; @@ -564,31 +564,31 @@ async fn multi_search_authorized_simple_token() { }, hashmap! { "searchRules" => json!({"*": {}}), - "exp" => Value::Null + "exp" => json!(null), }, hashmap! { - "searchRules" => json!({"*": Value::Null}), - "exp" => Value::Null + "searchRules" => json!({"*": null}), + "exp" => json!(null), }, hashmap! { "searchRules" => json!(["*"]), - "exp" => Value::Null + "exp" => json!(null), }, hashmap! { "searchRules" => json!({"sales": {}, "products": {}}), - "exp" => Value::Null + "exp" => json!(null), }, hashmap! { - "searchRules" => json!({"sales": Value::Null, "products": Value::Null}), - "exp" => Value::Null + "searchRules" => json!({"sales": null, "products": null}), + "exp" => json!(null), }, hashmap! { "searchRules" => json!(["sales", "products"]), - "exp" => Value::Null + "exp" => json!(null), }, hashmap! { "searchRules" => json!(["sa*", "pro*"]), - "exp" => Value::Null + "exp" => json!(null), }, ]; @@ -823,7 +823,7 @@ async fn error_single_search_token_forbidden_parent_key() { "exp" => json!((OffsetDateTime::now_utc() + Duration::hours(1)).unix_timestamp()) }, hashmap! { - "searchRules" => json!({"*": Value::Null}), + "searchRules" => json!({"*": null}), "exp" => json!((OffsetDateTime::now_utc() + Duration::hours(1)).unix_timestamp()) }, hashmap! { @@ -835,7 +835,7 @@ async fn error_single_search_token_forbidden_parent_key() { "exp" => json!((OffsetDateTime::now_utc() + Duration::hours(1)).unix_timestamp()) }, hashmap! { - "searchRules" => json!({"sales": Value::Null}), + "searchRules" => json!({"sales": null}), "exp" => json!((OffsetDateTime::now_utc() + Duration::hours(1)).unix_timestamp()) }, hashmap! { @@ -864,7 +864,7 @@ async fn error_multi_search_token_forbidden_parent_key() { "exp" => json!((OffsetDateTime::now_utc() + Duration::hours(1)).unix_timestamp()) }, hashmap! { - "searchRules" => json!({"*": Value::Null}), + "searchRules" => json!({"*": null}), "exp" => json!((OffsetDateTime::now_utc() + Duration::hours(1)).unix_timestamp()) }, hashmap! { @@ -876,7 +876,7 @@ async fn error_multi_search_token_forbidden_parent_key() { "exp" => json!((OffsetDateTime::now_utc() + Duration::hours(1)).unix_timestamp()) }, hashmap! { - "searchRules" => json!({"sales": Value::Null, "products": Value::Null}), + "searchRules" => json!({"sales": null, "products": null}), "exp" => json!((OffsetDateTime::now_utc() + Duration::hours(1)).unix_timestamp()) }, hashmap! { @@ -919,15 +919,15 @@ async fn error_single_search_forbidden_token() { }, hashmap! { "searchRules" => json!({"products": {}}), - "exp" => Value::Null + "exp" => json!(null), }, hashmap! { - "searchRules" => json!({"products": Value::Null}), - "exp" => Value::Null + "searchRules" => json!({"products": null}), + "exp" => json!(null), }, hashmap! { "searchRules" => json!(["products"]), - "exp" => Value::Null + "exp" => json!(null), }, // expired token hashmap! { @@ -935,7 +935,7 @@ async fn error_single_search_forbidden_token() { "exp" => json!((OffsetDateTime::now_utc() - Duration::hours(1)).unix_timestamp()) }, hashmap! { - "searchRules" => json!({"*": Value::Null}), + "searchRules" => json!({"*": null}), "exp" => json!((OffsetDateTime::now_utc() - Duration::hours(1)).unix_timestamp()) }, hashmap! { @@ -947,7 +947,7 @@ async fn error_single_search_forbidden_token() { "exp" => json!((OffsetDateTime::now_utc() - Duration::hours(1)).unix_timestamp()) }, hashmap! { - "searchRules" => json!({"sales": Value::Null}), + "searchRules" => json!({"sales": null}), "exp" => json!((OffsetDateTime::now_utc() - Duration::hours(1)).unix_timestamp()) }, hashmap! { @@ -978,15 +978,15 @@ async fn error_multi_search_forbidden_token() { }, hashmap! { "searchRules" => json!({"products": {}}), - "exp" => Value::Null + "exp" => json!(null), }, hashmap! { - "searchRules" => json!({"products": Value::Null}), - "exp" => Value::Null + "searchRules" => json!({"products": null}), + "exp" => json!(null), }, hashmap! { "searchRules" => json!(["products"]), - "exp" => Value::Null + "exp" => json!(null), }, hashmap! { "searchRules" => json!({"sales": {}}), @@ -998,15 +998,15 @@ async fn error_multi_search_forbidden_token() { }, hashmap! { "searchRules" => json!({"sales": {}}), - "exp" => Value::Null + "exp" => json!(null), }, hashmap! { - "searchRules" => json!({"sales": Value::Null}), - "exp" => Value::Null + "searchRules" => json!({"sales": null}), + "exp" => json!(null), }, hashmap! { "searchRules" => json!(["sales"]), - "exp" => Value::Null + "exp" => json!(null), }, // expired token hashmap! { @@ -1014,7 +1014,7 @@ async fn error_multi_search_forbidden_token() { "exp" => json!((OffsetDateTime::now_utc() - Duration::hours(1)).unix_timestamp()) }, hashmap! { - "searchRules" => json!({"*": Value::Null}), + "searchRules" => json!({"*": null}), "exp" => json!((OffsetDateTime::now_utc() - Duration::hours(1)).unix_timestamp()) }, hashmap! { @@ -1026,7 +1026,7 @@ async fn error_multi_search_forbidden_token() { "exp" => json!((OffsetDateTime::now_utc() - Duration::hours(1)).unix_timestamp()) }, hashmap! { - "searchRules" => json!({"sales": Value::Null, "products": {}}), + "searchRules" => json!({"sales": null, "products": {}}), "exp" => json!((OffsetDateTime::now_utc() - Duration::hours(1)).unix_timestamp()) }, hashmap! { diff --git a/meilisearch/tests/common/index.rs b/meilisearch/tests/common/index.rs index 1bb4345e8..4992eeb13 100644 --- a/meilisearch/tests/common/index.rs +++ b/meilisearch/tests/common/index.rs @@ -3,12 +3,13 @@ use std::panic::{catch_unwind, resume_unwind, UnwindSafe}; use std::time::Duration; use actix_web::http::StatusCode; -use serde_json::{json, Value}; use tokio::time::sleep; use urlencoding::encode as urlencode; use super::encoder::Encoder; use super::service::Service; +use super::Value; +use crate::json; pub struct Index<'a> { pub uid: String, @@ -242,7 +243,9 @@ impl Index<'_> { pub async fn delete_batch(&self, ids: Vec) -> (Value, StatusCode) { let url = format!("/indexes/{}/documents/delete-batch", urlencode(self.uid.as_ref())); - self.service.post_encoded(url, serde_json::to_value(&ids).unwrap(), self.encoder).await + self.service + .post_encoded(url, serde_json::to_value(&ids).unwrap().into(), self.encoder) + .await } pub async fn delete_batch_raw(&self, body: Value) -> (Value, StatusCode) { diff --git a/meilisearch/tests/common/mod.rs b/meilisearch/tests/common/mod.rs index cb8f576ce..9ee9b755e 100644 --- a/meilisearch/tests/common/mod.rs +++ b/meilisearch/tests/common/mod.rs @@ -3,9 +3,83 @@ pub mod index; pub mod server; pub mod service; +use std::fmt::{self, Display}; + pub use index::{GetAllDocumentsOptions, GetDocumentOptions}; +use meili_snap::json_string; +use serde::{Deserialize, Serialize}; pub use server::{default_settings, Server}; +#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq, Eq)] +pub struct Value(pub serde_json::Value); + +impl Value { + pub fn uid(&self) -> u64 { + if let Some(uid) = self["uid"].as_u64() { + uid + } else if let Some(uid) = self["taskUid"].as_u64() { + uid + } else { + panic!("Didn't find any task id in: {self}"); + } + } +} + +impl From for Value { + fn from(value: serde_json::Value) -> Self { + Value(value) + } +} + +impl std::ops::Deref for Value { + type Target = serde_json::Value; + + fn deref(&self) -> &Self::Target { + &self.0 + } +} + +impl PartialEq for Value { + fn eq(&self, other: &serde_json::Value) -> bool { + &self.0 == other + } +} + +impl PartialEq for serde_json::Value { + fn eq(&self, other: &Value) -> bool { + self == &other.0 + } +} + +impl PartialEq<&str> for Value { + fn eq(&self, other: &&str) -> bool { + self.0.eq(other) + } +} + +impl Display for Value { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!( + f, + "{}", + json_string!(self, { ".enqueuedAt" => "[date]", ".processedAt" => "[date]", ".finishedAt" => "[date]", ".duration" => "[duration]" }) + ) + } +} + +impl From> for Value { + fn from(value: Vec) -> Self { + Self(value.into_iter().map(|value| value.0).collect::()) + } +} + +#[macro_export] +macro_rules! json { + ($($json:tt)+) => { + $crate::common::Value(serde_json::json!($($json)+)) + }; +} + /// Performs a search test on both post and get routes #[macro_export] macro_rules! test_post_get_search { diff --git a/meilisearch/tests/common/server.rs b/meilisearch/tests/common/server.rs index 40d8e8366..c5d2cd85c 100644 --- a/meilisearch/tests/common/server.rs +++ b/meilisearch/tests/common/server.rs @@ -11,13 +11,14 @@ use clap::Parser; use meilisearch::option::{IndexerOpts, MaxMemory, Opt}; use meilisearch::{analytics, create_app, setup_meilisearch}; use once_cell::sync::Lazy; -use serde_json::{json, Value}; use tempfile::TempDir; use tokio::time::sleep; use super::index::Index; use super::service::Service; use crate::common::encoder::Encoder; +use crate::common::Value; +use crate::json; pub struct Server { pub service: Service, @@ -156,6 +157,10 @@ impl Server { self.service.post("/dumps", json!(null)).await } + pub async fn create_snapshot(&self) -> (Value, StatusCode) { + self.service.post("/snapshots", json!(null)).await + } + pub async fn index_swap(&self, value: Value) -> (Value, StatusCode) { self.service.post("/swap-indexes", value).await } diff --git a/meilisearch/tests/common/service.rs b/meilisearch/tests/common/service.rs index 2ff474157..078ddb6e5 100644 --- a/meilisearch/tests/common/service.rs +++ b/meilisearch/tests/common/service.rs @@ -7,9 +7,9 @@ use actix_web::test::TestRequest; use index_scheduler::IndexScheduler; use meilisearch::{analytics, create_app, Opt}; use meilisearch_auth::AuthController; -use serde_json::Value; use crate::common::encoder::Encoder; +use crate::common::Value; pub struct Service { pub index_scheduler: Arc, diff --git a/meilisearch/tests/content_type.rs b/meilisearch/tests/content_type.rs index e16a83c06..0fc5b26ac 100644 --- a/meilisearch/tests/content_type.rs +++ b/meilisearch/tests/content_type.rs @@ -3,9 +3,8 @@ mod common; use actix_web::test; -use serde_json::{json, Value}; -use crate::common::Server; +use crate::common::{Server, Value}; enum HttpVerb { Put, diff --git a/meilisearch/tests/documents/add_documents.rs b/meilisearch/tests/documents/add_documents.rs index 11a5e0fc8..b2904691f 100644 --- a/meilisearch/tests/documents/add_documents.rs +++ b/meilisearch/tests/documents/add_documents.rs @@ -1,11 +1,11 @@ use actix_web::test; use meili_snap::{json_string, snapshot}; -use serde_json::{json, Value}; use time::format_description::well_known::Rfc3339; use time::OffsetDateTime; use crate::common::encoder::Encoder; -use crate::common::{GetAllDocumentsOptions, Server}; +use crate::common::{GetAllDocumentsOptions, Server, Value}; +use crate::json; /// This is the basic usage of our API and every other tests uses the content-type application/json #[actix_rt::test] diff --git a/meilisearch/tests/documents/delete_documents.rs b/meilisearch/tests/documents/delete_documents.rs index 8f6ae1985..760ebbaa8 100644 --- a/meilisearch/tests/documents/delete_documents.rs +++ b/meilisearch/tests/documents/delete_documents.rs @@ -1,7 +1,7 @@ use meili_snap::{json_string, snapshot}; -use serde_json::json; use crate::common::{GetAllDocumentsOptions, Server}; +use crate::json; #[actix_rt::test] async fn delete_one_document_unexisting_index() { diff --git a/meilisearch/tests/documents/errors.rs b/meilisearch/tests/documents/errors.rs index 7dab16a25..bd06aabce 100644 --- a/meilisearch/tests/documents/errors.rs +++ b/meilisearch/tests/documents/errors.rs @@ -1,8 +1,8 @@ use meili_snap::*; -use serde_json::json; use urlencoding::encode; use crate::common::Server; +use crate::json; #[actix_rt::test] async fn get_all_documents_bad_offset() { diff --git a/meilisearch/tests/documents/get_documents.rs b/meilisearch/tests/documents/get_documents.rs index 7e6c5a2a9..3b0629fcb 100644 --- a/meilisearch/tests/documents/get_documents.rs +++ b/meilisearch/tests/documents/get_documents.rs @@ -1,11 +1,11 @@ use actix_web::test; use http::header::ACCEPT_ENCODING; use meili_snap::*; -use serde_json::{json, Value}; use urlencoding::encode as urlencode; use crate::common::encoder::Encoder; -use crate::common::{GetAllDocumentsOptions, GetDocumentOptions, Server}; +use crate::common::{GetAllDocumentsOptions, GetDocumentOptions, Server, Value}; +use crate::json; // TODO: partial test since we are testing error, amd error is not yet fully implemented in // transplant @@ -40,7 +40,7 @@ async fn get_document() { let server = Server::new().await; let index = server.index("test"); index.create(None).await; - let documents = serde_json::json!([ + let documents = json!([ { "id": 0, "nested": { "content": "foobar" }, @@ -53,7 +53,7 @@ async fn get_document() { assert_eq!(code, 200); assert_eq!( response, - serde_json::json!({ + json!({ "id": 0, "nested": { "content": "foobar" }, }) @@ -64,7 +64,7 @@ async fn get_document() { assert_eq!(code, 200); assert_eq!( response, - serde_json::json!({ + json!({ "id": 0, }) ); @@ -75,7 +75,7 @@ async fn get_document() { assert_eq!(code, 200); assert_eq!( response, - serde_json::json!({ + json!({ "nested": { "content": "foobar" }, }) ); @@ -122,7 +122,7 @@ async fn get_all_documents_no_options() { assert_eq!(code, 200); let arr = response["results"].as_array().unwrap(); assert_eq!(arr.len(), 20); - let first = serde_json::json!({ + let first = json!({ "id":0, "isActive":false, "balance":"$2,668.55", diff --git a/meilisearch/tests/documents/update_documents.rs b/meilisearch/tests/documents/update_documents.rs index 688605861..b4f61bf99 100644 --- a/meilisearch/tests/documents/update_documents.rs +++ b/meilisearch/tests/documents/update_documents.rs @@ -1,7 +1,8 @@ -use serde_json::json; +use meili_snap::snapshot; use crate::common::encoder::Encoder; use crate::common::{GetAllDocumentsOptions, Server}; +use crate::json; #[actix_rt::test] async fn error_document_update_create_index_bad_uid() { @@ -84,7 +85,13 @@ async fn update_document() { let (response, code) = index.get_document(1, None).await; assert_eq!(code, 200); - assert_eq!(response.to_string(), r##"{"doc_id":1,"content":"foo","other":"bar"}"##); + snapshot!(response, @r###" + { + "doc_id": 1, + "content": "foo", + "other": "bar" + } + "###); } #[actix_rt::test] @@ -122,7 +129,13 @@ async fn update_document_gzip_encoded() { let (response, code) = index.get_document(1, None).await; assert_eq!(code, 200); - assert_eq!(response.to_string(), r##"{"doc_id":1,"content":"foo","other":"bar"}"##); + snapshot!(response, @r###" + { + "doc_id": 1, + "content": "foo", + "other": "bar" + } + "###); } #[actix_rt::test] diff --git a/meilisearch/tests/dumps/mod.rs b/meilisearch/tests/dumps/mod.rs index 7e426cf54..e60893d4e 100644 --- a/meilisearch/tests/dumps/mod.rs +++ b/meilisearch/tests/dumps/mod.rs @@ -2,10 +2,10 @@ mod data; use meili_snap::{json_string, snapshot}; use meilisearch::Opt; -use serde_json::json; use self::data::GetDump; use crate::common::{default_settings, GetAllDocumentsOptions, Server}; +use crate::json; // all the following test are ignored on windows. See #2364 #[actix_rt::test] diff --git a/meilisearch/tests/features/mod.rs b/meilisearch/tests/features/mod.rs index 045440f49..348deb5e2 100644 --- a/meilisearch/tests/features/mod.rs +++ b/meilisearch/tests/features/mod.rs @@ -1,6 +1,5 @@ -use serde_json::json; - use crate::common::Server; +use crate::json; /// Feature name to test against. /// This will have to be changed by a different one when that feature is stabilized. diff --git a/meilisearch/tests/index/create_index.rs b/meilisearch/tests/index/create_index.rs index 48a07b67f..7ce56d440 100644 --- a/meilisearch/tests/index/create_index.rs +++ b/meilisearch/tests/index/create_index.rs @@ -2,10 +2,10 @@ use actix_web::http::header::ContentType; use actix_web::test; use http::header::ACCEPT_ENCODING; use meili_snap::{json_string, snapshot}; -use serde_json::{json, Value}; use crate::common::encoder::Encoder; -use crate::common::Server; +use crate::common::{Server, Value}; +use crate::json; #[actix_rt::test] async fn create_index_no_primary_key() { @@ -21,7 +21,7 @@ async fn create_index_no_primary_key() { assert_eq!(response["status"], "succeeded"); assert_eq!(response["type"], "indexCreation"); - assert_eq!(response["details"]["primaryKey"], Value::Null); + assert_eq!(response["details"]["primaryKey"], json!(null)); } #[actix_rt::test] @@ -38,7 +38,7 @@ async fn create_index_with_gzip_encoded_request() { assert_eq!(response["status"], "succeeded"); assert_eq!(response["type"], "indexCreation"); - assert_eq!(response["details"]["primaryKey"], Value::Null); + assert_eq!(response["details"]["primaryKey"], json!(null)); } #[actix_rt::test] @@ -86,7 +86,7 @@ async fn create_index_with_zlib_encoded_request() { assert_eq!(response["status"], "succeeded"); assert_eq!(response["type"], "indexCreation"); - assert_eq!(response["details"]["primaryKey"], Value::Null); + assert_eq!(response["details"]["primaryKey"], json!(null)); } #[actix_rt::test] @@ -103,7 +103,7 @@ async fn create_index_with_brotli_encoded_request() { assert_eq!(response["status"], "succeeded"); assert_eq!(response["type"], "indexCreation"); - assert_eq!(response["details"]["primaryKey"], Value::Null); + assert_eq!(response["details"]["primaryKey"], json!(null)); } #[actix_rt::test] @@ -136,7 +136,7 @@ async fn create_index_with_invalid_primary_key() { let (response, code) = index.get().await; assert_eq!(code, 200); - assert_eq!(response["primaryKey"], Value::Null); + assert_eq!(response["primaryKey"], json!(null)); } #[actix_rt::test] diff --git a/meilisearch/tests/index/delete_index.rs b/meilisearch/tests/index/delete_index.rs index b6efc7a68..e404a6003 100644 --- a/meilisearch/tests/index/delete_index.rs +++ b/meilisearch/tests/index/delete_index.rs @@ -1,6 +1,5 @@ -use serde_json::json; - use crate::common::Server; +use crate::json; #[actix_rt::test] async fn create_and_delete_index() { diff --git a/meilisearch/tests/index/errors.rs b/meilisearch/tests/index/errors.rs index ae17a68f1..01273fc88 100644 --- a/meilisearch/tests/index/errors.rs +++ b/meilisearch/tests/index/errors.rs @@ -1,7 +1,7 @@ use meili_snap::*; -use serde_json::json; use crate::common::Server; +use crate::json; #[actix_rt::test] async fn get_indexes_bad_offset() { diff --git a/meilisearch/tests/index/stats.rs b/meilisearch/tests/index/stats.rs index 813f05b4a..d0b0a56b9 100644 --- a/meilisearch/tests/index/stats.rs +++ b/meilisearch/tests/index/stats.rs @@ -1,6 +1,5 @@ -use serde_json::json; - use crate::common::Server; +use crate::json; #[actix_rt::test] async fn stats() { diff --git a/meilisearch/tests/index/update_index.rs b/meilisearch/tests/index/update_index.rs index 3c283407c..36ec27306 100644 --- a/meilisearch/tests/index/update_index.rs +++ b/meilisearch/tests/index/update_index.rs @@ -1,9 +1,9 @@ -use serde_json::json; use time::format_description::well_known::Rfc3339; use time::OffsetDateTime; use crate::common::encoder::Encoder; use crate::common::Server; +use crate::json; #[actix_rt::test] async fn update_primary_key() { diff --git a/meilisearch/tests/search/errors.rs b/meilisearch/tests/search/errors.rs index 0745aa7d6..8be70d162 100644 --- a/meilisearch/tests/search/errors.rs +++ b/meilisearch/tests/search/errors.rs @@ -1,8 +1,8 @@ use meili_snap::*; -use serde_json::json; use super::DOCUMENTS; use crate::common::Server; +use crate::json; #[actix_rt::test] async fn search_unexisting_index() { diff --git a/meilisearch/tests/search/facet_search.rs b/meilisearch/tests/search/facet_search.rs index 446396856..1b06f1b98 100644 --- a/meilisearch/tests/search/facet_search.rs +++ b/meilisearch/tests/search/facet_search.rs @@ -1,8 +1,8 @@ use meili_snap::snapshot; use once_cell::sync::Lazy; -use serde_json::{json, Value}; -use crate::common::Server; +use crate::common::{Server, Value}; +use crate::json; pub(self) static DOCUMENTS: Lazy = Lazy::new(|| { json!([ diff --git a/meilisearch/tests/search/formatted.rs b/meilisearch/tests/search/formatted.rs index 6347a90ca..90c81f949 100644 --- a/meilisearch/tests/search/formatted.rs +++ b/meilisearch/tests/search/formatted.rs @@ -1,8 +1,8 @@ use insta::{allow_duplicates, assert_json_snapshot}; -use serde_json::json; use super::*; use crate::common::Server; +use crate::json; #[actix_rt::test] async fn formatted_contain_wildcard() { diff --git a/meilisearch/tests/search/geo.rs b/meilisearch/tests/search/geo.rs index 5eec5857a..67a4ca7df 100644 --- a/meilisearch/tests/search/geo.rs +++ b/meilisearch/tests/search/geo.rs @@ -1,8 +1,8 @@ use meili_snap::{json_string, snapshot}; use once_cell::sync::Lazy; -use serde_json::{json, Value}; -use crate::common::Server; +use crate::common::{Server, Value}; +use crate::json; pub(self) static DOCUMENTS: Lazy = Lazy::new(|| { json!([ diff --git a/meilisearch/tests/search/mod.rs b/meilisearch/tests/search/mod.rs index 6fcc33309..43304b223 100644 --- a/meilisearch/tests/search/mod.rs +++ b/meilisearch/tests/search/mod.rs @@ -10,9 +10,9 @@ mod pagination; mod restrict_searchable; use once_cell::sync::Lazy; -use serde_json::{json, Value}; -use crate::common::Server; +use crate::common::{Server, Value}; +use crate::json; pub(self) static DOCUMENTS: Lazy = Lazy::new(|| { json!([ diff --git a/meilisearch/tests/search/multi.rs b/meilisearch/tests/search/multi.rs index 7cff42f3d..0e2e5158d 100644 --- a/meilisearch/tests/search/multi.rs +++ b/meilisearch/tests/search/multi.rs @@ -1,8 +1,8 @@ use meili_snap::{json_string, snapshot}; -use serde_json::json; use super::{DOCUMENTS, NESTED_DOCUMENTS}; use crate::common::Server; +use crate::json; #[actix_rt::test] async fn search_empty_list() { diff --git a/meilisearch/tests/search/pagination.rs b/meilisearch/tests/search/pagination.rs index bc4a68f98..ff3b50d04 100644 --- a/meilisearch/tests/search/pagination.rs +++ b/meilisearch/tests/search/pagination.rs @@ -1,6 +1,5 @@ -use serde_json::json; - use crate::common::Server; +use crate::json; use crate::search::DOCUMENTS; #[actix_rt::test] diff --git a/meilisearch/tests/search/restrict_searchable.rs b/meilisearch/tests/search/restrict_searchable.rs index 219c747ed..cfdff95ee 100644 --- a/meilisearch/tests/search/restrict_searchable.rs +++ b/meilisearch/tests/search/restrict_searchable.rs @@ -1,9 +1,9 @@ use meili_snap::{json_string, snapshot}; use once_cell::sync::Lazy; -use serde_json::{json, Value}; use crate::common::index::Index; -use crate::common::Server; +use crate::common::{Server, Value}; +use crate::json; async fn index_with_documents<'a>(server: &'a Server, documents: &Value) -> Index<'a> { let index = server.index("test"); diff --git a/meilisearch/tests/settings/distinct.rs b/meilisearch/tests/settings/distinct.rs index a60792329..42c5d38bd 100644 --- a/meilisearch/tests/settings/distinct.rs +++ b/meilisearch/tests/settings/distinct.rs @@ -1,6 +1,5 @@ -use serde_json::json; - use crate::common::Server; +use crate::json; #[actix_rt::test] async fn set_and_reset_distinct_attribute() { diff --git a/meilisearch/tests/settings/errors.rs b/meilisearch/tests/settings/errors.rs index 52dadcf98..687cef1f8 100644 --- a/meilisearch/tests/settings/errors.rs +++ b/meilisearch/tests/settings/errors.rs @@ -1,7 +1,7 @@ use meili_snap::*; -use serde_json::json; use crate::common::Server; +use crate::json; #[actix_rt::test] async fn settings_bad_displayed_attributes() { diff --git a/meilisearch/tests/settings/get_settings.rs b/meilisearch/tests/settings/get_settings.rs index f62957a32..b5c4644a5 100644 --- a/meilisearch/tests/settings/get_settings.rs +++ b/meilisearch/tests/settings/get_settings.rs @@ -1,16 +1,16 @@ use std::collections::HashMap; use once_cell::sync::Lazy; -use serde_json::{json, Value}; -use crate::common::Server; +use crate::common::{Server, Value}; +use crate::json; static DEFAULT_SETTINGS_VALUES: Lazy> = Lazy::new(|| { let mut map = HashMap::new(); map.insert("displayed_attributes", json!(["*"])); map.insert("searchable_attributes", json!(["*"])); map.insert("filterable_attributes", json!([])); - map.insert("distinct_attribute", json!(Value::Null)); + map.insert("distinct_attribute", json!(null)); map.insert( "ranking_rules", json!(["words", "typo", "proximity", "attribute", "sort", "exactness"]), @@ -229,7 +229,7 @@ macro_rules! test_setting_routes { .chars() .map(|c| if c == '_' { '-' } else { c }) .collect::()); - let (response, code) = server.service.$write_method(url, serde_json::Value::Null).await; + let (response, code) = server.service.$write_method(url, serde_json::Value::Null.into()).await; assert_eq!(code, 202, "{}", response); server.index("").wait_task(0).await; let (response, code) = server.index("test").get().await; diff --git a/meilisearch/tests/settings/tokenizer_customization.rs b/meilisearch/tests/settings/tokenizer_customization.rs index fc5d8a880..4602e31f7 100644 --- a/meilisearch/tests/settings/tokenizer_customization.rs +++ b/meilisearch/tests/settings/tokenizer_customization.rs @@ -1,7 +1,7 @@ use meili_snap::{json_string, snapshot}; -use serde_json::json; use crate::common::Server; +use crate::json; #[actix_rt::test] async fn set_and_reset() { diff --git a/meilisearch/tests/snapshot/mod.rs b/meilisearch/tests/snapshot/mod.rs index 97db3db8d..1312aa9ca 100644 --- a/meilisearch/tests/snapshot/mod.rs +++ b/meilisearch/tests/snapshot/mod.rs @@ -1,11 +1,13 @@ use std::time::Duration; use actix_rt::time::sleep; +use meili_snap::{json_string, snapshot}; use meilisearch::option::ScheduleSnapshot; use meilisearch::Opt; use crate::common::server::default_settings; use crate::common::{GetAllDocumentsOptions, Server}; +use crate::json; macro_rules! verify_snapshot { ( @@ -44,7 +46,7 @@ async fn perform_snapshot() { let index = server.index("test"); index - .update_settings(serde_json::json! ({ + .update_settings(json! ({ "searchableAttributes": [], })) .await; @@ -90,3 +92,95 @@ async fn perform_snapshot() { server.index("test1").settings(), ); } + +#[actix_rt::test] +async fn perform_on_demand_snapshot() { + let temp = tempfile::tempdir().unwrap(); + let snapshot_dir = tempfile::tempdir().unwrap(); + + let options = + Opt { snapshot_dir: snapshot_dir.path().to_owned(), ..default_settings(temp.path()) }; + + let server = Server::new_with_options(options).await.unwrap(); + + let index = server.index("catto"); + index + .update_settings(json! ({ + "searchableAttributes": [], + })) + .await; + + index.load_test_set().await; + + server.index("doggo").create(Some("bone")).await; + index.wait_task(2).await; + + server.index("doggo").create(Some("bone")).await; + index.wait_task(2).await; + + let (task, code) = server.create_snapshot().await; + snapshot!(code, @"202 Accepted"); + snapshot!(json_string!(task, { ".enqueuedAt" => "[date]" }), @r###" + { + "taskUid": 4, + "indexUid": null, + "status": "enqueued", + "type": "snapshotCreation", + "enqueuedAt": "[date]" + } + "###); + let task = index.wait_task(task.uid()).await; + snapshot!(json_string!(task, { ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]", ".duration" => "[duration]" }), @r###" + { + "uid": 4, + "indexUid": null, + "status": "succeeded", + "type": "snapshotCreation", + "canceledBy": null, + "error": null, + "duration": "[duration]", + "enqueuedAt": "[date]", + "startedAt": "[date]", + "finishedAt": "[date]" + } + "###); + + let temp = tempfile::tempdir().unwrap(); + + let snapshots: Vec = std::fs::read_dir(&snapshot_dir) + .unwrap() + .map(|entry| entry.unwrap().path().file_name().unwrap().to_str().unwrap().to_string()) + .collect(); + meili_snap::snapshot!(format!("{snapshots:?}"), @r###"["db.snapshot"]"###); + + let snapshot_path = snapshot_dir.path().to_owned().join("db.snapshot"); + #[cfg_attr(windows, allow(unused))] + let snapshot_meta = std::fs::metadata(&snapshot_path).unwrap(); + + #[cfg(unix)] + { + use std::os::unix::fs::PermissionsExt; + let mode = snapshot_meta.permissions().mode(); + // rwxrwxrwx + meili_snap::snapshot!(format!("{:b}", mode), @"1000000100100100"); + } + + let options = Opt { import_snapshot: Some(snapshot_path), ..default_settings(temp.path()) }; + + let snapshot_server = Server::new_with_options(options).await.unwrap(); + + verify_snapshot!(server, snapshot_server, |server| => + server.list_indexes(None, None), + // for some reason the db sizes differ. this may be due to the compaction options we have + // set when performing the snapshot + //server.stats(), + + // The original instance contains the snapshotCreation task, while the snapshotted-instance does not. For this reason we need to compare the task queue **after** the task 4 + server.tasks_filter("?from=2"), + + server.index("catto").get_all_documents(GetAllDocumentsOptions::default()), + server.index("catto").settings(), + server.index("doggo").get_all_documents(GetAllDocumentsOptions::default()), + server.index("doggo").settings(), + ); +} diff --git a/meilisearch/tests/stats/mod.rs b/meilisearch/tests/stats/mod.rs index 152e4f625..a02a48a87 100644 --- a/meilisearch/tests/stats/mod.rs +++ b/meilisearch/tests/stats/mod.rs @@ -1,8 +1,8 @@ -use serde_json::json; use time::format_description::well_known::Rfc3339; use time::OffsetDateTime; use crate::common::Server; +use crate::json; #[actix_rt::test] async fn get_settings_unexisting_index() { diff --git a/meilisearch/tests/swap_indexes/errors.rs b/meilisearch/tests/swap_indexes/errors.rs index 03625fd08..d8fa85b3a 100644 --- a/meilisearch/tests/swap_indexes/errors.rs +++ b/meilisearch/tests/swap_indexes/errors.rs @@ -1,7 +1,7 @@ use meili_snap::*; -use serde_json::json; use crate::common::Server; +use crate::json; #[actix_rt::test] async fn swap_indexes_bad_format() { diff --git a/meilisearch/tests/swap_indexes/mod.rs b/meilisearch/tests/swap_indexes/mod.rs index 4d01995b5..7f2b1623c 100644 --- a/meilisearch/tests/swap_indexes/mod.rs +++ b/meilisearch/tests/swap_indexes/mod.rs @@ -1,9 +1,9 @@ mod errors; use meili_snap::{json_string, snapshot}; -use serde_json::json; use crate::common::{GetAllDocumentsOptions, Server}; +use crate::json; #[actix_rt::test] async fn swap_indexes() { diff --git a/meilisearch/tests/tasks/mod.rs b/meilisearch/tests/tasks/mod.rs index 4ac134871..7a5fa6388 100644 --- a/meilisearch/tests/tasks/mod.rs +++ b/meilisearch/tests/tasks/mod.rs @@ -1,11 +1,11 @@ mod errors; use meili_snap::insta::assert_json_snapshot; -use serde_json::json; use time::format_description::well_known::Rfc3339; use time::OffsetDateTime; use crate::common::Server; +use crate::json; #[actix_rt::test] async fn error_get_unexisting_task_status() { @@ -33,7 +33,7 @@ async fn get_task_status() { index.create(None).await; index .add_documents( - serde_json::json!([{ + json!([{ "id": 1, "content": "foobar", }]),