Skip to content

Commit 1a93539

Browse files
committed
Updated tests
1 parent eb71ad0 commit 1a93539

File tree

1 file changed

+34
-34
lines changed

1 file changed

+34
-34
lines changed

tests/index_api.rs

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@ use manticoresearch::{
77
use std::collections::HashMap;
88

99
#[tokio::test]
10-
async fn index_api_basic_insert() {
10+
async fn index_api_basic_bulk() {
1111
let api_config = Arc::new(Configuration::new());
1212
let utils_api = UtilsApiClient::new(api_config.clone());
1313
let index_api = IndexApiClient::new(api_config.clone());
1414

1515
// Drop the table if it exists
1616
let _ = utils_api.sql("DROP TABLE IF EXISTS products", Some(true)).await;
1717
assert!(res.is_ok(), "DROP TABLE failed: {:?}", res.err());
18+
tokio::time::delay_for(tokio::time::Duration::from_millis(1000));
1819

1920
// Create table
2021
let res = utils_api
@@ -25,38 +26,32 @@ async fn index_api_basic_insert() {
2526
.await;
2627
assert!(res.is_ok(), "Failed to create table: {:?}", res.err());
2728

28-
// Prepare document
29-
let mut doc = HashMap::new();
30-
doc.insert("title".to_string(), serde_json::json!("test"));
31-
doc.insert("tags1".to_string(), serde_json::json!([1, 2, 4, 5]));
32-
33-
// Insert without specifying ID
34-
let insert_req = InsertDocumentRequest::new("products".to_string(), serde_json::json!(doc));
35-
let res = index_api.insert(insert_req).await;
36-
assert!(res.is_ok(), "Failed to insert document without ID: {:?}", res.err());
37-
38-
// Insert with specific ID
39-
let mut insert_req = InsertDocumentRequest::new("products".to_string(), serde_json::json!(doc));
40-
insert_req.id = Some(100);
41-
let res = index_api.insert(insert_req).await;
42-
assert!(res.is_ok(), "Failed to insert document with ID: {:?}", res.err());
43-
44-
let insert_response = res.unwrap();
45-
println!("Insert response with ID 100: {:?}", insert_response);
29+
// Bulk insert
30+
let insert_body = r#"{"insert": {"table": "products", "id": 3, "doc": {"title": "Crossbody \"Bag with Tassel", "price": 19.85}}}
31+
{"insert": {"table": "products", "id": 4, "doc": {"title": "microfiber sheet set", "price": 19.99}}}
32+
{"insert": {"table": "products", "id": 5, "doc": {"title": "CPet Hair Remover Glove", "price": 7.99}}}
33+
"#;
34+
let res = index_api.bulk(insert_body).await;
35+
assert!(res.is_ok(), "Bulk insert failed: {:?}", res.err());
4636

37+
// Bulk update
38+
let update_body = r#"{"update": { "table" : "products", "doc": { "coeff" : 1000 }, "query": { "range": { "price": { "gte": 1000 } } } } }
39+
{ "update" : { "table" : "products", "doc": { "coeff" : 0 }, "query": { "range": { "price": { "lt": 1000 } } } } }
40+
"#;
41+
let res = index_api.bulk(update_body).await;
42+
assert!(res.is_ok(), "Bulk update failed: {:?}", res.err());
4743
}
4844

4945

5046
#[tokio::test]
51-
async fn index_api_basic_bulk() {
47+
async fn index_api_basic_insert() {
5248
let api_config = Arc::new(Configuration::new());
5349
let utils_api = UtilsApiClient::new(api_config.clone());
5450
let index_api = IndexApiClient::new(api_config.clone());
5551

5652
// Drop the table if it exists
5753
let _ = utils_api.sql("DROP TABLE IF EXISTS products", Some(true)).await;
5854
assert!(res.is_ok(), "DROP TABLE failed: {:?}", res.err());
59-
tokio::time::delay_for(tokio::time::Duration::from_millis(1000));
6055

6156
// Create table
6257
let res = utils_api
@@ -67,18 +62,23 @@ async fn index_api_basic_bulk() {
6762
.await;
6863
assert!(res.is_ok(), "Failed to create table: {:?}", res.err());
6964

70-
// Bulk insert
71-
let insert_body = r#"{"insert": {"table": "products", "id": 3, "doc": {"title": "Crossbody \"Bag with Tassel", "price": 19.85}}}
72-
{"insert": {"table": "products", "id": 4, "doc": {"title": "microfiber sheet set", "price": 19.99}}}
73-
{"insert": {"table": "products", "id": 5, "doc": {"title": "CPet Hair Remover Glove", "price": 7.99}}}
74-
"#;
75-
let res = index_api.bulk(insert_body).await;
76-
assert!(res.is_ok(), "Bulk insert failed: {:?}", res.err());
65+
// Prepare document
66+
let mut doc = HashMap::new();
67+
doc.insert("title".to_string(), serde_json::json!("test"));
68+
doc.insert("tags1".to_string(), serde_json::json!([1, 2, 4, 5]));
69+
70+
// Insert without specifying ID
71+
let insert_req = InsertDocumentRequest::new("products".to_string(), serde_json::json!(doc));
72+
let res = index_api.insert(insert_req).await;
73+
assert!(res.is_ok(), "Failed to insert document without ID: {:?}", res.err());
74+
75+
// Insert with specific ID
76+
let mut insert_req = InsertDocumentRequest::new("products".to_string(), serde_json::json!(doc));
77+
insert_req.id = Some(100);
78+
let res = index_api.insert(insert_req).await;
79+
assert!(res.is_ok(), "Failed to insert document with ID: {:?}", res.err());
80+
81+
let insert_response = res.unwrap();
82+
println!("Insert response with ID 100: {:?}", insert_response);
7783

78-
// Bulk update
79-
let update_body = r#"{"update": { "table" : "products", "doc": { "coeff" : 1000 }, "query": { "range": { "price": { "gte": 1000 } } } } }
80-
{ "update" : { "table" : "products", "doc": { "coeff" : 0 }, "query": { "range": { "price": { "lt": 1000 } } } } }
81-
"#;
82-
let res = index_api.bulk(update_body).await;
83-
assert!(res.is_ok(), "Bulk update failed: {:?}", res.err());
8484
}

0 commit comments

Comments
 (0)