mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2025-12-25 23:49:58 +00:00
feat: check database existence on http api (#764)
* feat: check database existance on http api * Update src/servers/src/http/handler.rs Co-authored-by: Ruihang Xia <waynestxia@gmail.com> * feat: use database not found status code * test: add assertion for status code Co-authored-by: Ruihang Xia <waynestxia@gmail.com>
This commit is contained in:
@@ -11,6 +11,7 @@ axum-test-helper = { git = "https://github.com/sunng87/axum-test-helper.git", br
|
||||
catalog = { path = "../src/catalog" }
|
||||
client = { path = "../src/client" }
|
||||
common-catalog = { path = "../src/common/catalog" }
|
||||
common-error = { path = "../src/common/error" }
|
||||
common-runtime = { path = "../src/common/runtime" }
|
||||
common-telemetry = { path = "../src/common/telemetry" }
|
||||
datanode = { path = "../src/datanode" }
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
|
||||
use axum::http::StatusCode;
|
||||
use axum_test_helper::TestClient;
|
||||
use common_error::status_code::StatusCode as ErrorCode;
|
||||
use serde_json::json;
|
||||
use servers::http::handler::HealthResponse;
|
||||
use servers::http::{JsonOutput, JsonResponse};
|
||||
@@ -192,6 +193,34 @@ pub async fn test_sql_api(store_type: StorageType) {
|
||||
assert!(body.execution_time_ms().is_some());
|
||||
assert!(body.error().unwrap().contains("not found"));
|
||||
|
||||
// test database given
|
||||
let res = client
|
||||
.get("/v1/sql?database=public&sql=select cpu, ts from demo limit 1")
|
||||
.send()
|
||||
.await;
|
||||
assert_eq!(res.status(), StatusCode::OK);
|
||||
|
||||
let body = serde_json::from_str::<JsonResponse>(&res.text().await).unwrap();
|
||||
assert!(body.success());
|
||||
assert!(body.execution_time_ms().is_some());
|
||||
let outputs = body.output().unwrap();
|
||||
assert_eq!(outputs.len(), 1);
|
||||
assert_eq!(
|
||||
outputs[0],
|
||||
serde_json::from_value::<JsonOutput>(json!({
|
||||
"records":{"schema":{"column_schemas":[{"name":"cpu","data_type":"Float64"},{"name":"ts","data_type":"TimestampMillisecond"}]},"rows":[[66.6,0]]}
|
||||
})).unwrap()
|
||||
);
|
||||
|
||||
// test database not found
|
||||
let res = client
|
||||
.get("/v1/sql?database=notfound&sql=select cpu, ts from demo limit 1")
|
||||
.send()
|
||||
.await;
|
||||
assert_eq!(res.status(), StatusCode::OK);
|
||||
let body = serde_json::from_str::<JsonResponse>(&res.text().await).unwrap();
|
||||
assert_eq!(body.code(), ErrorCode::DatabaseNotFound as u32);
|
||||
|
||||
guard.remove_all().await;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user