From dd6519b64fbc7d8aa297f17f04f0ee76efc46122 Mon Sep 17 00:00:00 2001 From: Louis Dureuil Date: Thu, 6 Jul 2023 14:22:29 +0200 Subject: [PATCH] Dump tests --- dump/src/lib.rs | 14 +++++- dump/src/reader/mod.rs | 49 +++++++++++++++++++- dump/src/writer.rs | 1 + dump/tests/assets/v6-with-experimental.dump | Bin 0 -> 1297 bytes 4 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 dump/tests/assets/v6-with-experimental.dump diff --git a/dump/src/lib.rs b/dump/src/lib.rs index 1e21eed05..33bd8c63b 100644 --- a/dump/src/lib.rs +++ b/dump/src/lib.rs @@ -210,6 +210,7 @@ pub(crate) mod test { use big_s::S; use maplit::{btreemap, btreeset}; use meilisearch_types::facet_values_sort::FacetValuesSort; + use meilisearch_types::features::RuntimeTogglableFeatures; use meilisearch_types::index_uid_pattern::IndexUidPattern; use meilisearch_types::keys::{Action, Key}; use meilisearch_types::milli; @@ -418,7 +419,10 @@ pub(crate) mod test { } keys.flush().unwrap(); - // ========== TODO: create features here + // ========== experimental features + let features = create_test_features(); + + dump.create_experimental_features(features).unwrap(); // create the dump let mut file = tempfile::tempfile().unwrap(); @@ -428,6 +432,10 @@ pub(crate) mod test { file } + fn create_test_features() -> RuntimeTogglableFeatures { + RuntimeTogglableFeatures { vector_store: true, ..Default::default() } + } + #[test] fn test_creating_and_read_dump() { let mut file = create_test_dump(); @@ -472,5 +480,9 @@ pub(crate) mod test { for (key, expected) in dump.keys().unwrap().zip(create_test_api_keys()) { assert_eq!(key.unwrap(), expected); } + + // ==== checking the features + let expected = create_test_features(); + assert_eq!(dump.features().unwrap().unwrap(), expected); } } diff --git a/dump/src/reader/mod.rs b/dump/src/reader/mod.rs index 0899579f8..af02888d2 100644 --- a/dump/src/reader/mod.rs +++ b/dump/src/reader/mod.rs @@ -195,8 +195,53 @@ pub(crate) mod test { use meili_snap::insta; use super::*; + use crate::reader::v6::RuntimeTogglableFeatures; - // TODO: add `features` to tests + #[test] + fn import_dump_v6_experimental() { + let dump = File::open("tests/assets/v6-with-experimental.dump").unwrap(); + let mut dump = DumpReader::open(dump).unwrap(); + + // top level infos + insta::assert_display_snapshot!(dump.date().unwrap(), @"2023-07-06 7:10:27.21958 +00:00:00"); + insta::assert_debug_snapshot!(dump.instance_uid().unwrap(), @"None"); + + // tasks + let tasks = dump.tasks().unwrap().collect::>>().unwrap(); + let (tasks, update_files): (Vec<_>, Vec<_>) = tasks.into_iter().unzip(); + meili_snap::snapshot_hash!(meili_snap::json_string!(tasks), @"d45cd8571703e58ae53c7bd7ce3f5c22"); + assert_eq!(update_files.len(), 2); + assert!(update_files[0].is_none()); // the dump creation + assert!(update_files[1].is_none()); // the processed document addition + + // keys + let keys = dump.keys().unwrap().collect::>>().unwrap(); + meili_snap::snapshot_hash!(meili_snap::json_string!(keys), @"13c2da155e9729c2344688cab29af71d"); + + // indexes + let mut indexes = dump.indexes().unwrap().collect::>>().unwrap(); + // the index are not ordered in any way by default + indexes.sort_by_key(|index| index.metadata().uid.to_string()); + + let mut test = indexes.pop().unwrap(); + assert!(indexes.is_empty()); + + insta::assert_json_snapshot!(test.metadata(), @r###" + { + "uid": "test", + "primaryKey": "id", + "createdAt": "2023-07-06T07:07:41.364694Z", + "updatedAt": "2023-07-06T07:07:41.396114Z" + } + "###); + + assert_eq!(test.documents().unwrap().count(), 1); + + assert_eq!( + dump.features().unwrap().unwrap(), + RuntimeTogglableFeatures { vector_store: true, ..Default::default() } + ); + } #[test] fn import_dump_v5() { @@ -274,6 +319,8 @@ pub(crate) mod test { let documents = spells.documents().unwrap().collect::>>().unwrap(); assert_eq!(documents.len(), 10); meili_snap::snapshot_hash!(format!("{:#?}", documents), @"235016433dd04262c7f2da01d1e808ce"); + + assert_eq!(dump.features().unwrap(), None); } #[test] diff --git a/dump/src/writer.rs b/dump/src/writer.rs index 695610f78..3c8126876 100644 --- a/dump/src/writer.rs +++ b/dump/src/writer.rs @@ -292,6 +292,7 @@ pub(crate) mod test { │ ├---- update_files/ │ │ └---- 1.jsonl │ └---- queue.jsonl + ├---- experimental-features.json ├---- instance_uid.uuid ├---- keys.jsonl └---- metadata.json diff --git a/dump/tests/assets/v6-with-experimental.dump b/dump/tests/assets/v6-with-experimental.dump new file mode 100644 index 0000000000000000000000000000000000000000..ac6833dc3b21f3036a9752c8dfbdc37d1f903c55 GIT binary patch literal 1297 zcmV+s1@8JEiwFP!00000|Ls~`liD^E7Fvt2yd#%Ew`g@{w<0-wTvU5s&d;C2&3fwmS4WNqu znW9p4PJ}1K-;3P1jei5!j{jLIl5#=0lKnrW;92LH0O{;T7(W_+F9;sSAIFgYjSS)s z9{&|$DH?fQ#L0r95mGZI9rzGO&j=?i7rCQ^lgwx`chrn1hu-J3V0xO6%$ZW6%7RMg zP84&8z^PnOm{KWPzv{I3{;`w)3#v#;6fx=Fc{Uu){|N8pe-OlN{x^UXD)j>Z>G-2A z$|18!vHX=Tp$!gnQBpvP)AU?HgYWu5&y9O-bmhh)_+YOeL^vAaPheT*>0!%Z<4ZBH-HsNnane?)QPJKHYs5ypwaK>HTt8ABqc>M zBa@7N<=~WMiWYkZ^=YC|Uu!Q2pTqq6SZ3A@kcL#klS3_YVIDr>o-LSK!ak`_Mb;f` z=sigkr&5|LQzHM(oNjwua>17i__bPh^)10XPSmDxAn zP!%QZq6OpH=_UJ{z7@q4SZj|+aH{vwCD#DonYGM zg52MbtfcY-E#B&OU}3InZ`S;_M}J;wjdG3schg zaM$1PgxzLyy_(H6od0g0=!J9Und}#pQ-gk8ym|YP4Dt$oi zJ$K~Cecu~~gO=OBILzttnbp319Layr+voq#)UN-V0OUWFNx^bUC(*T}4pUn4v)tdA z7GeRyAJscX+d~_z@PbZBnJMSeTAqJ+=V;-eTS*G(B%UP6!0W{W6811ANpIqjxEF(D zkobdi=n>8Cfz(6SW<6lL)bzeumTuM>KvNkI(=kysm9KOO)ACSm2uD8d!)zK3hFikK zantpyM}}i63Wx9|h@<@0s-Pf|a-l#bt%gYejW(3L@4O+U-ucP75XJ_sU064Q!wGpg z$yjn=IL}j9hU|@IM1l}_an!?PfO|Ohg5F^2CA}~pbT}NwNsK4Eqxt&T1~Lree>slE zvXy>c4iu5|(^h|`b|Er`WJsAx= z!vFjL@995&7`6IO6R7GxZp9R?w~IkAGO7gXfMl5@l|N)geF-g?#AXy#)g*|7H0G(EwqxZ$Nd4%a>1x+aX3_NAigYj*d&~B^tO1YW+hbmmK9PvNd0V$5u!u%lA zmQ%)=oE-qUGBVj()^K#edK!VlUQ5<>k;RM^LOuio+NwCV)ciW{%ixw?fJdS?=7OL?- H05AXmAUBim literal 0 HcmV?d00001