test index_update

This commit is contained in:
ad hoc 2022-06-06 10:49:58 +02:00
parent 0333bad057
commit 354f7fb2bf
No known key found for this signature in database
GPG Key ID: 4F00A782990CC643

View File

@ -472,7 +472,9 @@ mod real {
mod test { mod test {
use crate::index::IndexStats; use crate::index::IndexStats;
use super::{index_store::MockIndexStore, meta_store::MockIndexMetaStore, *}; use super::index_store::MockIndexStore;
use super::meta_store::MockIndexMetaStore;
use super::*;
use futures::future::ok; use futures::future::ok;
use milli::FieldDistribution; use milli::FieldDistribution;
@ -707,6 +709,55 @@ mod test {
assert!(matches!(task.events[0], TaskEvent::Succeeded { .. })); assert!(matches!(task.events[0], TaskEvent::Succeeded { .. }));
} }
#[actix_rt::test]
async fn test_index_update() {
let mut meta_store = MockIndexMetaStore::new();
meta_store.expect_get().once().returning(|_| {
Box::pin(ok((
"test".to_string(),
Some(IndexMeta {
uuid: Uuid::new_v4(),
creation_task_id: 1,
}),
)))
});
let mut index_store = MockIndexStore::new();
index_store.expect_get().once().returning(|_| {
let mocker = Mocker::default();
mocker
.when::<String, IndexResult<crate::index::IndexMeta>>("update_primary_key")
.once()
.then(|_| {
Ok(crate::index::IndexMeta {
created_at: OffsetDateTime::now_utc(),
updated_at: OffsetDateTime::now_utc(),
primary_key: Some("key".to_string()),
})
});
Box::pin(ok(Some(Index::mock(mocker))))
});
let mocker = Mocker::default();
let file_store = UpdateFileStore::mock(mocker);
let index_resolver = IndexResolver::new(meta_store, index_store, file_store);
let mut task = Task {
id: 1,
content: TaskContent::IndexUpdate {
primary_key: Some("key".to_string()),
index_uid: IndexUid::new_unchecked("test"),
},
events: Vec::new(),
};
index_resolver.process_task(&mut task).await;
assert!(matches!(task.events[0], TaskEvent::Succeeded { .. }));
}
// TODO: ignoring this test, it has become too complex to maintain, and rather implement // TODO: ignoring this test, it has become too complex to maintain, and rather implement
// handler logic test. // handler logic test.
// proptest! { // proptest! {