2019-10-26 20:37:49 +03:00
|
|
|
extern crate log;
|
|
|
|
|
|
|
|
use actix_web::{http, test, App};
|
|
|
|
|
|
|
|
use martin::dev::{mock_function_sources, mock_state, mock_table_sources};
|
|
|
|
use martin::function_source::FunctionSources;
|
|
|
|
use martin::server::router;
|
|
|
|
use martin::table_source::TableSources;
|
|
|
|
|
2020-06-02 09:49:21 +03:00
|
|
|
fn init() {
|
|
|
|
let _ = env_logger::builder().is_test(true).try_init();
|
|
|
|
}
|
|
|
|
|
2020-04-26 17:57:13 +03:00
|
|
|
#[actix_rt::test]
|
|
|
|
async fn test_get_table_sources_ok() {
|
2020-06-02 09:49:21 +03:00
|
|
|
init();
|
|
|
|
|
|
|
|
let state = mock_state(mock_table_sources(), None, false);
|
|
|
|
let mut app = test::init_service(App::new().data(state).configure(router)).await;
|
|
|
|
|
|
|
|
let req = test::TestRequest::get().uri("/index.json").to_request();
|
|
|
|
let response = test::call_service(&mut app, req).await;
|
|
|
|
assert!(response.status().is_success());
|
|
|
|
|
|
|
|
let body = test::read_body(response).await;
|
|
|
|
let table_sources: TableSources = serde_json::from_slice(&body).unwrap();
|
|
|
|
assert!(table_sources.contains_key("public.table_source"));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[actix_rt::test]
|
|
|
|
async fn test_get_table_sources_watch_mode_ok() {
|
|
|
|
init();
|
|
|
|
|
|
|
|
let state = mock_state(mock_table_sources(), None, true);
|
2020-05-05 14:13:48 +03:00
|
|
|
let mut app = test::init_service(App::new().data(state).configure(router)).await;
|
2019-10-26 20:37:49 +03:00
|
|
|
|
2020-05-05 14:13:48 +03:00
|
|
|
let req = test::TestRequest::get().uri("/index.json").to_request();
|
|
|
|
let response = test::call_service(&mut app, req).await;
|
|
|
|
assert!(response.status().is_success());
|
2019-10-26 20:37:49 +03:00
|
|
|
|
2020-05-05 14:13:48 +03:00
|
|
|
let body = test::read_body(response).await;
|
|
|
|
let table_sources: TableSources = serde_json::from_slice(&body).unwrap();
|
|
|
|
assert!(table_sources.contains_key("public.table_source"));
|
2019-10-26 20:37:49 +03:00
|
|
|
}
|
|
|
|
|
2020-04-26 17:57:13 +03:00
|
|
|
#[actix_rt::test]
|
|
|
|
async fn test_get_table_source_ok() {
|
2020-06-02 09:49:21 +03:00
|
|
|
init();
|
|
|
|
|
|
|
|
let state = mock_state(mock_table_sources(), None, false);
|
2020-05-05 14:13:48 +03:00
|
|
|
let mut app = test::init_service(App::new().data(state).configure(router)).await;
|
2019-10-26 20:37:49 +03:00
|
|
|
|
2020-05-05 14:13:48 +03:00
|
|
|
let req = test::TestRequest::get()
|
|
|
|
.uri("/public.non_existant.json")
|
|
|
|
.to_request();
|
2019-10-26 20:37:49 +03:00
|
|
|
|
2020-05-05 14:13:48 +03:00
|
|
|
let response = test::call_service(&mut app, req).await;
|
|
|
|
assert_eq!(response.status(), http::StatusCode::NOT_FOUND);
|
2019-10-26 20:37:49 +03:00
|
|
|
|
2020-05-05 14:13:48 +03:00
|
|
|
let req = test::TestRequest::get()
|
|
|
|
.uri("/public.table_source.json")
|
|
|
|
.to_request();
|
2019-10-26 20:37:49 +03:00
|
|
|
|
2020-05-05 14:13:48 +03:00
|
|
|
let response = test::call_service(&mut app, req).await;
|
|
|
|
assert!(response.status().is_success());
|
2019-10-26 20:37:49 +03:00
|
|
|
}
|
|
|
|
|
2020-04-26 17:57:13 +03:00
|
|
|
#[actix_rt::test]
|
|
|
|
async fn test_get_table_source_tile_ok() {
|
2020-06-02 09:49:21 +03:00
|
|
|
init();
|
|
|
|
|
|
|
|
let state = mock_state(mock_table_sources(), None, false);
|
2020-05-05 14:13:48 +03:00
|
|
|
let mut app = test::init_service(App::new().data(state).configure(router)).await;
|
2019-10-26 20:37:49 +03:00
|
|
|
|
2021-04-24 20:19:37 +03:00
|
|
|
let req = test::TestRequest::get()
|
|
|
|
.uri("/public.non_existant/0/0/0.pbf")
|
|
|
|
.to_request();
|
|
|
|
|
|
|
|
let response = test::call_service(&mut app, req).await;
|
|
|
|
assert_eq!(response.status(), http::StatusCode::NOT_FOUND);
|
|
|
|
|
2020-05-05 14:13:48 +03:00
|
|
|
let req = test::TestRequest::get()
|
|
|
|
.uri("/public.table_source/0/0/0.pbf")
|
|
|
|
.to_request();
|
2019-10-26 20:37:49 +03:00
|
|
|
|
2020-05-05 14:13:48 +03:00
|
|
|
let response = test::call_service(&mut app, req).await;
|
|
|
|
assert!(response.status().is_success());
|
2019-10-26 20:37:49 +03:00
|
|
|
}
|
|
|
|
|
2021-04-24 20:19:37 +03:00
|
|
|
#[actix_rt::test]
|
|
|
|
async fn test_get_composite_source_ok() {
|
|
|
|
init();
|
|
|
|
|
|
|
|
let state = mock_state(mock_table_sources(), None, false);
|
|
|
|
let mut app = test::init_service(App::new().data(state).configure(router)).await;
|
|
|
|
|
|
|
|
let req = test::TestRequest::get()
|
|
|
|
.uri("/public.non_existant1,public.non_existant2.json")
|
|
|
|
.to_request();
|
|
|
|
|
|
|
|
let response = test::call_service(&mut app, req).await;
|
|
|
|
assert_eq!(response.status(), http::StatusCode::NOT_FOUND);
|
|
|
|
|
|
|
|
let req = test::TestRequest::get()
|
2021-10-10 12:09:56 +03:00
|
|
|
.uri("/public.points1,public.points2,public.points3857.json")
|
2021-04-24 20:19:37 +03:00
|
|
|
.to_request();
|
|
|
|
|
|
|
|
let response = test::call_service(&mut app, req).await;
|
|
|
|
assert!(response.status().is_success());
|
|
|
|
}
|
|
|
|
|
|
|
|
#[actix_rt::test]
|
|
|
|
async fn test_get_composite_source_tile_ok() {
|
|
|
|
init();
|
|
|
|
|
|
|
|
let state = mock_state(mock_table_sources(), None, false);
|
|
|
|
let mut app = test::init_service(App::new().data(state).configure(router)).await;
|
|
|
|
|
|
|
|
let req = test::TestRequest::get()
|
|
|
|
.uri("/public.non_existant1,public.non_existant2/0/0/0.pbf")
|
|
|
|
.to_request();
|
|
|
|
|
|
|
|
let response = test::call_service(&mut app, req).await;
|
|
|
|
assert_eq!(response.status(), http::StatusCode::NOT_FOUND);
|
|
|
|
|
|
|
|
let req = test::TestRequest::get()
|
2021-10-10 12:09:56 +03:00
|
|
|
.uri("/public.points1,public.points2,public.points3857/0/0/0.pbf")
|
2021-04-24 20:19:37 +03:00
|
|
|
.to_request();
|
|
|
|
|
|
|
|
let response = test::call_service(&mut app, req).await;
|
|
|
|
assert!(response.status().is_success());
|
|
|
|
}
|
|
|
|
|
2020-04-26 17:57:13 +03:00
|
|
|
#[actix_rt::test]
|
|
|
|
async fn test_get_function_sources_ok() {
|
2020-06-02 09:49:21 +03:00
|
|
|
init();
|
|
|
|
|
|
|
|
let state = mock_state(None, mock_function_sources(), false);
|
|
|
|
let mut app = test::init_service(App::new().data(state).configure(router)).await;
|
|
|
|
|
|
|
|
let req = test::TestRequest::get().uri("/rpc/index.json").to_request();
|
|
|
|
let response = test::call_service(&mut app, req).await;
|
|
|
|
assert!(response.status().is_success());
|
|
|
|
|
|
|
|
let body = test::read_body(response).await;
|
|
|
|
let function_sources: FunctionSources = serde_json::from_slice(&body).unwrap();
|
|
|
|
assert!(function_sources.contains_key("public.function_source"));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[actix_rt::test]
|
|
|
|
async fn test_get_function_sources_watch_mode_ok() {
|
|
|
|
init();
|
|
|
|
|
|
|
|
let state = mock_state(None, mock_function_sources(), true);
|
2020-05-05 14:13:48 +03:00
|
|
|
let mut app = test::init_service(App::new().data(state).configure(router)).await;
|
2019-10-26 20:37:49 +03:00
|
|
|
|
2020-05-05 14:13:48 +03:00
|
|
|
let req = test::TestRequest::get().uri("/rpc/index.json").to_request();
|
|
|
|
let response = test::call_service(&mut app, req).await;
|
|
|
|
assert!(response.status().is_success());
|
2019-10-26 20:37:49 +03:00
|
|
|
|
2020-05-05 14:13:48 +03:00
|
|
|
let body = test::read_body(response).await;
|
|
|
|
let function_sources: FunctionSources = serde_json::from_slice(&body).unwrap();
|
|
|
|
assert!(function_sources.contains_key("public.function_source"));
|
2019-10-26 20:37:49 +03:00
|
|
|
}
|
|
|
|
|
2020-04-26 17:57:13 +03:00
|
|
|
#[actix_rt::test]
|
|
|
|
async fn test_get_function_source_ok() {
|
2020-06-02 09:49:21 +03:00
|
|
|
init();
|
|
|
|
|
|
|
|
let state = mock_state(None, mock_function_sources(), false);
|
2020-05-05 14:13:48 +03:00
|
|
|
let mut app = test::init_service(App::new().data(state).configure(router)).await;
|
2019-10-26 20:37:49 +03:00
|
|
|
|
2020-05-05 14:13:48 +03:00
|
|
|
let req = test::TestRequest::get()
|
|
|
|
.uri("/rpc/public.non_existant.json")
|
|
|
|
.to_request();
|
2019-10-26 20:37:49 +03:00
|
|
|
|
2020-05-05 14:13:48 +03:00
|
|
|
let response = test::call_service(&mut app, req).await;
|
|
|
|
assert_eq!(response.status(), http::StatusCode::NOT_FOUND);
|
2019-10-26 20:37:49 +03:00
|
|
|
|
2020-05-05 14:13:48 +03:00
|
|
|
let req = test::TestRequest::get()
|
|
|
|
.uri("/rpc/public.function_source.json")
|
|
|
|
.to_request();
|
2019-10-26 20:37:49 +03:00
|
|
|
|
2020-05-05 14:13:48 +03:00
|
|
|
let response = test::call_service(&mut app, req).await;
|
|
|
|
assert!(response.status().is_success());
|
2019-10-26 20:37:49 +03:00
|
|
|
}
|
|
|
|
|
2020-04-26 17:57:13 +03:00
|
|
|
#[actix_rt::test]
|
|
|
|
async fn test_get_function_source_tile_ok() {
|
2020-06-02 09:49:21 +03:00
|
|
|
init();
|
|
|
|
|
|
|
|
let state = mock_state(None, mock_function_sources(), false);
|
2020-05-05 14:13:48 +03:00
|
|
|
let mut app = test::init_service(App::new().data(state).configure(router)).await;
|
2019-10-26 20:37:49 +03:00
|
|
|
|
2020-05-05 14:13:48 +03:00
|
|
|
let req = test::TestRequest::get()
|
|
|
|
.uri("/rpc/public.function_source/0/0/0.pbf")
|
|
|
|
.to_request();
|
2019-10-26 20:37:49 +03:00
|
|
|
|
2020-05-05 14:13:48 +03:00
|
|
|
let response = test::call_service(&mut app, req).await;
|
|
|
|
assert!(response.status().is_success());
|
2019-10-26 20:37:49 +03:00
|
|
|
}
|
2021-01-16 16:11:19 +03:00
|
|
|
|
2021-07-16 12:09:18 +03:00
|
|
|
#[actix_rt::test]
|
|
|
|
async fn test_get_function_source_query_params_ok() {
|
|
|
|
init();
|
|
|
|
|
|
|
|
let state = mock_state(None, mock_function_sources(), false);
|
|
|
|
let mut app = test::init_service(App::new().data(state).configure(router)).await;
|
|
|
|
|
|
|
|
let req = test::TestRequest::get()
|
|
|
|
.uri("/rpc/public.function_source_query_params/0/0/0.pbf")
|
|
|
|
.to_request();
|
|
|
|
|
|
|
|
let response = test::call_service(&mut app, req).await;
|
|
|
|
println!("response.status = {:?}", response.status());
|
|
|
|
assert!(response.status().is_server_error());
|
|
|
|
|
|
|
|
let req = test::TestRequest::get()
|
|
|
|
.uri("/rpc/public.function_source_query_params/0/0/0.pbf?token=martin")
|
|
|
|
.to_request();
|
|
|
|
|
|
|
|
let response = test::call_service(&mut app, req).await;
|
|
|
|
assert!(response.status().is_success());
|
|
|
|
}
|
|
|
|
|
2021-01-16 16:11:19 +03:00
|
|
|
#[actix_rt::test]
|
|
|
|
async fn test_get_health_returns_ok() {
|
|
|
|
init();
|
|
|
|
|
|
|
|
let state = mock_state(None, mock_function_sources(), false);
|
|
|
|
let mut app = test::init_service(App::new().data(state).configure(router)).await;
|
|
|
|
|
|
|
|
let req = test::TestRequest::get().uri("/healthz").to_request();
|
|
|
|
let response = test::call_service(&mut app, req).await;
|
|
|
|
assert!(response.status().is_success());
|
|
|
|
}
|