2021-04-01 21:54:37 +03:00
|
|
|
use serde_json::json;
|
|
|
|
|
2021-03-15 19:08:19 +01:00
|
|
|
use crate::common::Server;
|
|
|
|
|
|
|
|
#[actix_rt::test]
|
|
|
|
async fn get_settings_unexisting_index() {
|
|
|
|
let server = Server::new().await;
|
|
|
|
let (response, code) = server.version().await;
|
|
|
|
assert_eq!(code, 200);
|
|
|
|
let version = response.as_object().unwrap();
|
|
|
|
assert!(version.get("commitSha").is_some());
|
2021-04-09 09:03:25 +03:00
|
|
|
assert!(version.get("commitDate").is_some());
|
2021-03-15 19:08:19 +01:00
|
|
|
assert!(version.get("pkgVersion").is_some());
|
|
|
|
}
|
2021-03-16 17:42:01 +01:00
|
|
|
|
|
|
|
#[actix_rt::test]
|
|
|
|
async fn test_healthyness() {
|
|
|
|
let server = Server::new().await;
|
|
|
|
|
|
|
|
let (response, status_code) = server.service.get("/health").await;
|
|
|
|
assert_eq!(status_code, 200);
|
|
|
|
assert_eq!(response["status"], "available");
|
2021-03-24 11:29:11 +01:00
|
|
|
}
|
2021-04-01 21:54:37 +03:00
|
|
|
|
|
|
|
#[actix_rt::test]
|
|
|
|
async fn stats() {
|
|
|
|
let server = Server::new().await;
|
|
|
|
let index = server.index("test");
|
|
|
|
let (_, code) = index.create(Some("id")).await;
|
|
|
|
|
2021-07-05 11:21:02 +02:00
|
|
|
assert_eq!(code, 201);
|
2021-04-01 21:54:37 +03:00
|
|
|
|
|
|
|
let (response, code) = server.stats().await;
|
|
|
|
|
|
|
|
assert_eq!(code, 200);
|
|
|
|
assert!(response.get("databaseSize").is_some());
|
|
|
|
assert!(response.get("lastUpdate").is_some());
|
|
|
|
assert!(response["indexes"].get("test").is_some());
|
|
|
|
assert_eq!(response["indexes"]["test"]["numberOfDocuments"], 0);
|
2021-06-17 18:50:18 +02:00
|
|
|
assert!(response["indexes"]["test"]["isIndexing"] == false);
|
2021-04-01 21:54:37 +03:00
|
|
|
|
|
|
|
let documents = json!([
|
|
|
|
{
|
|
|
|
"id": 1,
|
|
|
|
"name": "Alexey",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"id": 2,
|
|
|
|
"age": 45,
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
|
|
|
|
let (response, code) = index.add_documents(documents, None).await;
|
2021-06-10 12:03:16 +02:00
|
|
|
assert_eq!(code, 202, "{}", response);
|
2021-04-01 21:54:37 +03:00
|
|
|
assert_eq!(response["updateId"], 0);
|
|
|
|
|
2021-06-23 16:21:32 +02:00
|
|
|
let response = index.wait_update_id(0).await;
|
|
|
|
println!("response: {}", response);
|
2021-04-01 21:54:37 +03:00
|
|
|
|
|
|
|
let (response, code) = server.stats().await;
|
|
|
|
|
|
|
|
assert_eq!(code, 200);
|
|
|
|
assert!(response["databaseSize"].as_u64().unwrap() > 0);
|
2021-06-15 22:21:52 +02:00
|
|
|
assert!(response.get("lastUpdate").is_some());
|
2021-04-01 21:54:37 +03:00
|
|
|
assert_eq!(response["indexes"]["test"]["numberOfDocuments"], 2);
|
2021-06-17 18:50:18 +02:00
|
|
|
assert!(response["indexes"]["test"]["isIndexing"] == false);
|
2021-06-21 16:59:27 +02:00
|
|
|
assert_eq!(response["indexes"]["test"]["fieldDistribution"]["id"], 2);
|
|
|
|
assert_eq!(response["indexes"]["test"]["fieldDistribution"]["name"], 1);
|
|
|
|
assert_eq!(response["indexes"]["test"]["fieldDistribution"]["age"], 1);
|
2021-04-01 21:54:37 +03:00
|
|
|
}
|