Refactor snapshot tests

This commit is contained in:
Loïc Lecrenier 2022-08-03 16:24:28 +02:00
parent 334098a7e0
commit ef889ade5d
5 changed files with 827 additions and 329 deletions

View File

@ -55,7 +55,6 @@ insta = "1.17.1"
maplit = "1.0.2"
md5 = "0.7.0"
rand = "0.8.5"
regex = "1.6.0"
[features]
default = []

View File

@ -1183,13 +1183,12 @@ pub(crate) mod tests {
use big_s::S;
use heed::{EnvOpenOptions, RwTxn};
use maplit::btreemap;
use tempfile::TempDir;
use crate::documents::DocumentsBatchReader;
use crate::index::{DEFAULT_MIN_WORD_LEN_ONE_TYPO, DEFAULT_MIN_WORD_LEN_TWO_TYPOS};
use crate::update::{self, IndexDocuments, IndexDocumentsConfig, IndexerConfig, Settings};
use crate::Index;
use crate::{db_snap, Index};
pub(crate) struct TempIndex {
pub inner: Index,
@ -1288,17 +1287,30 @@ pub(crate) mod tests {
]))
.unwrap();
let rtxn = index.read_txn().unwrap();
let field_distribution = index.field_distribution(&rtxn).unwrap();
assert_eq!(
field_distribution,
btreemap! {
"id".to_string() => 2,
"name".to_string() => 2,
"age".to_string() => 1,
}
db_snap!(index, field_distribution, 1);
db_snap!(index, word_docids,
@r###"
1 [0, ]
2 [1, ]
20 [1, ]
bob [1, ]
kevin [0, ]
"###
);
db_snap!(index, field_distribution);
db_snap!(index, field_distribution,
@"
age 1
id 2
name 2
"
);
// snapshot_index!(&index, "1", include: "^field_distribution$");
// we add all the documents a second time. we are supposed to get the same
// field_distribution in the end
index
@ -1309,16 +1321,12 @@ pub(crate) mod tests {
]))
.unwrap();
let rtxn = index.read_txn().unwrap();
let field_distribution = index.field_distribution(&rtxn).unwrap();
assert_eq!(
field_distribution,
btreemap! {
"id".to_string() => 2,
"name".to_string() => 2,
"age".to_string() => 1,
}
db_snap!(index, field_distribution,
@r###"
age 1
id 2
name 2
"###
);
// then we update a document by removing one field and another by adding one field
@ -1329,16 +1337,12 @@ pub(crate) mod tests {
]))
.unwrap();
let rtxn = index.read_txn().unwrap();
let field_distribution = index.field_distribution(&rtxn).unwrap();
assert_eq!(
field_distribution,
btreemap! {
"id".to_string() => 2,
"name".to_string() => 2,
"has_dog".to_string() => 1,
}
db_snap!(index, field_distribution,
@r###"
has_dog 1
id 2
name 2
"###
);
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,7 @@
---
source: milli/src/index.rs
---
age 1
id 2
name 2

View File

@ -0,0 +1,7 @@
---
source: milli/src/index.rs
---
age 1
id 2
name 2