test index update

This commit is contained in:
mpostma 2021-02-18 20:28:10 +01:00
parent 68692a256e
commit 4c5effe714
No known key found for this signature in database
GPG Key ID: CBC8A7C1D7A28C3A
5 changed files with 29 additions and 20 deletions

View File

@ -1,13 +1,13 @@
use std::ops::Deref;
use milli::update::{IndexDocumentsMethod, UpdateFormat};
use async_compression::tokio_02::write::GzipEncoder;
use futures_util::stream::StreamExt;
use milli::update::{IndexDocumentsMethod, UpdateFormat};
use tokio::io::AsyncWriteExt;
use super::Data;
use crate::index_controller::{IndexController, Settings, IndexSettings, IndexMetadata};
use crate::index_controller::UpdateStatus;
use crate::index_controller::{IndexController, Settings, IndexSettings, IndexMetadata};
use super::Data;
impl Data {
pub async fn add_documents<B, E>(

View File

@ -24,4 +24,13 @@ impl Index<'_> {
});
self.service.post("/indexes", body).await
}
pub async fn update(&self, primary_key: Option<&str>) -> (Value, StatusCode) {
let body = json!({
"primaryKey": primary_key,
});
let url = format!("/indexes/{}", self.uid);
self.service.put(url, body).await
}
}

View File

@ -165,23 +165,6 @@ impl Server {
//(response, status_code)
//}
//pub async fn put_request(&mut self, url: &str, body: Value) -> (Value, StatusCode) {
//eprintln!("put_request: {}", url);
//let mut app =
//test::init_service(meilisearch_http::create_app(&self.data, true).wrap(NormalizePath)).await;
//let req = test::TestRequest::put()
//.uri(url)
//.set_json(&body)
//.to_request();
//let res = test::call_service(&mut app, req).await;
//let status_code = res.status();
//let body = test::read_body(res).await;
//let response = serde_json::from_slice(&body).unwrap_or_default();
//(response, status_code)
//}
//pub async fn put_request_async(&mut self, url: &str, body: Value) -> (Value, StatusCode) {
//eprintln!("put_request_async: {}", url);

View File

@ -35,5 +35,21 @@ impl Service {
let response = serde_json::from_slice(&body).unwrap_or_default();
(response, status_code)
}
pub async fn put(&self, url: impl AsRef<str>, body: Value) -> (Value, StatusCode) {
let mut app =
test::init_service(meilisearch_http::create_app(&self.0, true).wrap(NormalizePath)).await;
let req = test::TestRequest::put()
.uri(url.as_ref())
.set_json(&body)
.to_request();
let res = test::call_service(&mut app, req).await;
let status_code = res.status();
let body = test::read_body(res).await;
let response = serde_json::from_slice(&body).unwrap_or_default();
(response, status_code)
}
}

View File

@ -1,2 +1,3 @@
mod create_index;
mod get_index;
mod update_index;