serde ndjson fix

This commit is contained in:
jiangbo212
2022-12-21 11:27:15 +08:00
parent 9925309492
commit bf2a401a05
5 changed files with 148 additions and 34 deletions

View File

@ -25,8 +25,30 @@ impl Index<'_> {
pub async fn load_test_set(&self) -> u64 {
let url = format!("/indexes/{}/documents", urlencode(self.uid.as_ref()));
let (response, code) =
self.service.post_str(url, include_str!("../assets/test_set.json")).await;
let (response, code) = self
.service
.post_str(
url,
include_str!("../assets/test_set.json"),
("content-type", "application/json"),
)
.await;
assert_eq!(code, 202);
let update_id = response["taskUid"].as_i64().unwrap();
self.wait_task(update_id as u64).await;
update_id as u64
}
pub async fn load_test_set_ndjson(&self) -> u64 {
let url = format!("/indexes/{}/documents", urlencode(self.uid.as_ref()));
let (response, code) = self
.service
.post_str(
url,
include_str!("../assets/test_set.ndjson"),
("content-type", "application/x-ndjson"),
)
.await;
assert_eq!(code, 202);
let update_id = response["taskUid"].as_i64().unwrap();
self.wait_task(update_id as u64).await;

View File

@ -39,11 +39,12 @@ impl Service {
&self,
url: impl AsRef<str>,
body: impl AsRef<str>,
header: (&str, &str),
) -> (Value, StatusCode) {
let req = test::TestRequest::post()
.uri(url.as_ref())
.set_payload(body.as_ref().to_string())
.insert_header(("content-type", "application/json"));
.insert_header(header);
self.request(req).await
}