|
| 1 | +// Copyright 2023 Greptime Team |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +use std::sync::Arc; |
| 16 | + |
| 17 | +use async_trait::async_trait; |
| 18 | +use axum::Router; |
| 19 | +use axum_test_helper::TestClient; |
| 20 | +use common_query::Output; |
| 21 | +use datatypes::schema::Schema; |
| 22 | +use servers::error::{Error, Result}; |
| 23 | +use servers::http::{HttpOptions, HttpServer}; |
| 24 | +use servers::query_handler::sql::SqlQueryHandler; |
| 25 | +use session::context::QueryContextRef; |
| 26 | + |
| 27 | +pub struct DummyInstance {} |
| 28 | + |
| 29 | +#[async_trait] |
| 30 | +impl SqlQueryHandler for DummyInstance { |
| 31 | + type Error = Error; |
| 32 | + |
| 33 | + async fn do_query(&self, _: &str, _: QueryContextRef) -> Vec<Result<Output>> { |
| 34 | + unimplemented!() |
| 35 | + } |
| 36 | + |
| 37 | + async fn do_promql_query( |
| 38 | + &self, |
| 39 | + _: &str, |
| 40 | + _: QueryContextRef, |
| 41 | + ) -> Vec<std::result::Result<Output, Self::Error>> { |
| 42 | + unimplemented!() |
| 43 | + } |
| 44 | + |
| 45 | + async fn do_statement_query( |
| 46 | + &self, |
| 47 | + _stmt: sql::statements::statement::Statement, |
| 48 | + _query_ctx: QueryContextRef, |
| 49 | + ) -> Result<Output> { |
| 50 | + unimplemented!() |
| 51 | + } |
| 52 | + |
| 53 | + fn do_describe( |
| 54 | + &self, |
| 55 | + _stmt: sql::statements::statement::Statement, |
| 56 | + _query_ctx: QueryContextRef, |
| 57 | + ) -> Result<Option<Schema>> { |
| 58 | + unimplemented!() |
| 59 | + } |
| 60 | + |
| 61 | + fn is_valid_schema(&self, _catalog: &str, _schema: &str) -> Result<bool> { |
| 62 | + Ok(true) |
| 63 | + } |
| 64 | +} |
| 65 | + |
| 66 | +fn make_test_app() -> Router { |
| 67 | + let instance = Arc::new(DummyInstance {}); |
| 68 | + let server = HttpServer::new(instance, HttpOptions::default()); |
| 69 | + server.make_app() |
| 70 | +} |
| 71 | + |
| 72 | +#[tokio::test] |
| 73 | +async fn test_api_and_doc() { |
| 74 | + let app = make_test_app(); |
| 75 | + let client = TestClient::new(app); |
| 76 | + let result = client.get("/v1/private/api.json").send().await; |
| 77 | + assert_eq!(result.status(), 200); |
| 78 | + let result = client.get("/v1/private/docs").send().await; |
| 79 | + assert_eq!(result.status(), 200); |
| 80 | +} |
0 commit comments