2022-10-12 11:52:26 +03:00
|
|
|
use actix_http::Request;
|
|
|
|
use actix_web::http::StatusCode;
|
|
|
|
use actix_web::test::{call_and_read_body_json, call_service, read_body, TestRequest};
|
|
|
|
use martin::pg::dev::{
|
|
|
|
mock_default_function_sources, mock_default_table_sources, mock_function_sources, mock_state,
|
|
|
|
mock_table_sources,
|
|
|
|
};
|
2022-10-01 10:48:11 +03:00
|
|
|
use martin::pg::function_source::{FunctionSource, FunctionSources};
|
|
|
|
use martin::pg::table_source::{TableSource, TableSources};
|
2022-10-12 11:52:26 +03:00
|
|
|
use std::collections::HashMap;
|
2022-08-06 19:48:10 +03:00
|
|
|
use tilejson::{Bounds, TileJSON};
|
2019-10-26 20:37:49 +03:00
|
|
|
|
2020-06-02 09:49:21 +03:00
|
|
|
fn init() {
|
|
|
|
let _ = env_logger::builder().is_test(true).try_init();
|
|
|
|
}
|
|
|
|
|
2022-10-12 11:52:26 +03:00
|
|
|
macro_rules! create_app {
|
|
|
|
($tables:expr, $functions:expr) => {{
|
|
|
|
init();
|
|
|
|
let state = mock_state($tables, $functions).await;
|
|
|
|
let data = ::actix_web::web::Data::new(state);
|
|
|
|
::actix_web::test::init_service(
|
|
|
|
::actix_web::App::new()
|
|
|
|
.app_data(data)
|
|
|
|
.configure(::martin::srv::server::router),
|
|
|
|
)
|
|
|
|
.await
|
|
|
|
}};
|
|
|
|
}
|
2020-06-02 09:49:21 +03:00
|
|
|
|
2022-10-12 11:52:26 +03:00
|
|
|
fn test_get(path: &str) -> Request {
|
|
|
|
TestRequest::get().uri(path).to_request()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[actix_rt::test]
|
|
|
|
async fn get_table_sources_ok() {
|
|
|
|
let app = create_app!(Some(mock_default_table_sources()), None);
|
2020-06-02 09:49:21 +03:00
|
|
|
|
2022-10-12 11:52:26 +03:00
|
|
|
let req = test_get("/index.json");
|
|
|
|
let response = call_service(&app, req).await;
|
2020-06-02 09:49:21 +03:00
|
|
|
assert!(response.status().is_success());
|
|
|
|
|
2022-10-12 11:52:26 +03:00
|
|
|
let body = read_body(response).await;
|
2020-06-02 09:49:21 +03:00
|
|
|
let table_sources: TableSources = serde_json::from_slice(&body).unwrap();
|
|
|
|
assert!(table_sources.contains_key("public.table_source"));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[actix_rt::test]
|
2022-10-12 11:52:26 +03:00
|
|
|
async fn get_table_sources_watch_mode_ok() {
|
|
|
|
let app = create_app!(Some(mock_default_table_sources()), None);
|
2019-10-26 20:37:49 +03:00
|
|
|
|
2022-10-12 11:52:26 +03:00
|
|
|
let req = test_get("/index.json");
|
|
|
|
let response = call_service(&app, req).await;
|
2020-05-05 14:13:48 +03:00
|
|
|
assert!(response.status().is_success());
|
2019-10-26 20:37:49 +03:00
|
|
|
|
2022-10-12 11:52:26 +03:00
|
|
|
let body = read_body(response).await;
|
2020-05-05 14:13:48 +03:00
|
|
|
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]
|
2022-10-12 11:52:26 +03:00
|
|
|
async fn get_table_source_ok() {
|
2021-10-13 14:51:29 +03:00
|
|
|
let table_source = TableSource {
|
|
|
|
id: "public.table_source".to_owned(),
|
|
|
|
schema: "public".to_owned(),
|
|
|
|
table: "table_source".to_owned(),
|
|
|
|
id_column: None,
|
|
|
|
geometry_column: "geom".to_owned(),
|
2022-05-30 14:06:44 +03:00
|
|
|
bounds: Some(Bounds::MAX),
|
2021-10-13 14:51:29 +03:00
|
|
|
minzoom: Some(0),
|
|
|
|
maxzoom: Some(30),
|
|
|
|
srid: 4326,
|
|
|
|
extent: Some(4096),
|
|
|
|
buffer: Some(64),
|
|
|
|
clip_geom: Some(true),
|
|
|
|
geometry_type: None,
|
|
|
|
properties: HashMap::new(),
|
|
|
|
};
|
|
|
|
|
2022-10-12 11:52:26 +03:00
|
|
|
let app = create_app!(Some(mock_table_sources(&[table_source])), None);
|
2019-10-26 20:37:49 +03:00
|
|
|
|
2022-10-12 11:52:26 +03:00
|
|
|
let req = test_get("/public.non_existent.json");
|
|
|
|
let response = call_service(&app, req).await;
|
|
|
|
assert_eq!(response.status(), StatusCode::NOT_FOUND);
|
2019-10-26 20:37:49 +03:00
|
|
|
|
2022-10-12 11:52:26 +03:00
|
|
|
let req = TestRequest::get()
|
2021-10-15 18:19:36 +03:00
|
|
|
.uri("/public.table_source.json?token=martin")
|
2022-08-15 16:54:48 +03:00
|
|
|
.insert_header((
|
2021-10-15 18:19:36 +03:00
|
|
|
"x-rewrite-url",
|
|
|
|
"/tiles/public.table_source.json?token=martin",
|
2022-08-15 16:54:48 +03:00
|
|
|
))
|
2020-05-05 14:13:48 +03:00
|
|
|
.to_request();
|
2022-10-12 11:52:26 +03:00
|
|
|
let result: TileJSON = call_and_read_body_json(&app, req).await;
|
2021-10-13 14:51:29 +03:00
|
|
|
assert_eq!(result.name, Some(String::from("public.table_source")));
|
|
|
|
assert_eq!(
|
|
|
|
result.tiles,
|
2021-10-15 18:19:36 +03:00
|
|
|
vec!["http://localhost:8080/tiles/public.table_source/{z}/{x}/{y}.pbf?token=martin"]
|
2021-10-13 14:51:29 +03:00
|
|
|
);
|
|
|
|
assert_eq!(result.minzoom, Some(0));
|
|
|
|
assert_eq!(result.maxzoom, Some(30));
|
2022-05-30 14:06:44 +03:00
|
|
|
assert_eq!(result.bounds, Some(Bounds::MAX));
|
2019-10-26 20:37:49 +03:00
|
|
|
}
|
|
|
|
|
2020-04-26 17:57:13 +03:00
|
|
|
#[actix_rt::test]
|
2022-10-12 11:52:26 +03:00
|
|
|
async fn get_table_source_tile_ok() {
|
|
|
|
let app = create_app!(Some(mock_default_table_sources()), None);
|
2019-10-26 20:37:49 +03:00
|
|
|
|
2022-10-12 11:52:26 +03:00
|
|
|
let req = test_get("/public.non_existent/0/0/0.pbf");
|
|
|
|
let response = call_service(&app, req).await;
|
|
|
|
assert_eq!(response.status(), StatusCode::NOT_FOUND);
|
2021-04-24 20:19:37 +03:00
|
|
|
|
2022-10-12 11:52:26 +03:00
|
|
|
let req = test_get("/public.table_source/0/0/0.pbf");
|
|
|
|
let response = call_service(&app, req).await;
|
2020-05-05 14:13:48 +03:00
|
|
|
assert!(response.status().is_success());
|
2019-10-26 20:37:49 +03:00
|
|
|
}
|
|
|
|
|
2021-10-21 12:20:33 +03:00
|
|
|
#[actix_rt::test]
|
2022-10-12 11:52:26 +03:00
|
|
|
async fn get_table_source_multiple_geom_tile_ok() {
|
|
|
|
let app = create_app!(Some(mock_default_table_sources()), None);
|
2021-10-21 12:20:33 +03:00
|
|
|
|
2022-10-12 11:52:26 +03:00
|
|
|
let req = test_get("/public.table_source_multiple_geom.geom1/0/0/0.pbf");
|
|
|
|
let response = call_service(&app, req).await;
|
2021-10-21 12:20:33 +03:00
|
|
|
assert!(response.status().is_success());
|
|
|
|
|
2022-10-12 11:52:26 +03:00
|
|
|
let req = test_get("/public.table_source_multiple_geom.geom2/0/0/0.pbf");
|
|
|
|
let response = call_service(&app, req).await;
|
2021-10-21 12:20:33 +03:00
|
|
|
assert!(response.status().is_success());
|
|
|
|
}
|
|
|
|
|
2021-10-13 14:51:29 +03:00
|
|
|
#[actix_rt::test]
|
2022-10-12 11:52:26 +03:00
|
|
|
async fn get_table_source_tile_minmax_zoom_ok() {
|
2021-10-13 14:51:29 +03:00
|
|
|
init();
|
|
|
|
|
2022-10-12 11:52:26 +03:00
|
|
|
let table_source = TableSource {
|
|
|
|
id: "public.table_source".to_owned(),
|
2021-10-13 14:51:29 +03:00
|
|
|
schema: "public".to_owned(),
|
2022-10-12 11:52:26 +03:00
|
|
|
table: "table_source".to_owned(),
|
2021-10-13 14:51:29 +03:00
|
|
|
id_column: None,
|
|
|
|
geometry_column: "geom".to_owned(),
|
2022-05-30 14:06:44 +03:00
|
|
|
bounds: Some(Bounds::MAX),
|
2022-10-12 11:52:26 +03:00
|
|
|
minzoom: None,
|
|
|
|
maxzoom: Some(6),
|
2021-10-13 14:51:29 +03:00
|
|
|
srid: 4326,
|
|
|
|
extent: Some(4096),
|
|
|
|
buffer: Some(64),
|
|
|
|
clip_geom: Some(true),
|
|
|
|
geometry_type: None,
|
|
|
|
properties: HashMap::new(),
|
|
|
|
};
|
|
|
|
|
2022-10-12 11:52:26 +03:00
|
|
|
let points1 = TableSource {
|
|
|
|
id: "public.points1".to_owned(),
|
|
|
|
schema: "public".to_owned(),
|
|
|
|
table: "points1".to_owned(),
|
|
|
|
id_column: None,
|
|
|
|
geometry_column: "geom".to_owned(),
|
|
|
|
minzoom: Some(6),
|
|
|
|
maxzoom: Some(12),
|
|
|
|
geometry_type: None,
|
|
|
|
properties: HashMap::new(),
|
|
|
|
..table_source
|
|
|
|
};
|
|
|
|
|
2021-10-13 14:51:29 +03:00
|
|
|
let points2 = TableSource {
|
|
|
|
id: "public.points2".to_owned(),
|
|
|
|
schema: "public".to_owned(),
|
|
|
|
table: "points2".to_owned(),
|
|
|
|
id_column: None,
|
|
|
|
geometry_column: "geom".to_owned(),
|
|
|
|
minzoom: None,
|
|
|
|
maxzoom: None,
|
|
|
|
geometry_type: None,
|
|
|
|
properties: HashMap::new(),
|
2022-10-12 11:52:26 +03:00
|
|
|
..table_source
|
2021-10-13 14:51:29 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
let points3857 = TableSource {
|
|
|
|
id: "public.points3857".to_owned(),
|
|
|
|
schema: "public".to_owned(),
|
|
|
|
table: "points3857".to_owned(),
|
|
|
|
id_column: None,
|
|
|
|
geometry_column: "geom".to_owned(),
|
|
|
|
minzoom: Some(6),
|
|
|
|
maxzoom: None,
|
|
|
|
geometry_type: None,
|
|
|
|
properties: HashMap::new(),
|
2022-10-12 11:52:26 +03:00
|
|
|
..table_source
|
2021-10-13 14:51:29 +03:00
|
|
|
};
|
|
|
|
|
2022-10-12 11:52:26 +03:00
|
|
|
let tables = &[points1, points2, points3857, table_source];
|
|
|
|
let app = create_app!(Some(mock_table_sources(tables)), None);
|
2021-10-13 14:51:29 +03:00
|
|
|
|
|
|
|
// zoom = 0 (nothing)
|
2022-10-12 11:52:26 +03:00
|
|
|
let req = test_get("/public.points1/0/0/0.pbf");
|
|
|
|
let response = call_service(&app, req).await;
|
|
|
|
assert_eq!(response.status(), StatusCode::NOT_FOUND);
|
2021-10-13 14:51:29 +03:00
|
|
|
|
|
|
|
// zoom = 6 (public.points1)
|
2022-10-12 11:52:26 +03:00
|
|
|
let req = test_get("/public.points1/6/38/20.pbf");
|
|
|
|
let response = call_service(&app, req).await;
|
2021-10-13 14:51:29 +03:00
|
|
|
assert!(response.status().is_success());
|
|
|
|
|
|
|
|
// zoom = 12 (public.points1)
|
2022-10-12 11:52:26 +03:00
|
|
|
let req = test_get("/public.points1/12/2476/1280.pbf");
|
|
|
|
let response = call_service(&app, req).await;
|
2021-10-13 14:51:29 +03:00
|
|
|
assert!(response.status().is_success());
|
|
|
|
|
|
|
|
// zoom = 13 (nothing)
|
2022-10-12 11:52:26 +03:00
|
|
|
let req = test_get("/public.points1/13/4952/2560.pbf");
|
|
|
|
let response = call_service(&app, req).await;
|
|
|
|
assert_eq!(response.status(), StatusCode::NOT_FOUND);
|
2021-10-13 14:51:29 +03:00
|
|
|
|
|
|
|
// zoom = 0 (public.points2)
|
2022-10-12 11:52:26 +03:00
|
|
|
let req = test_get("/public.points2/0/0/0.pbf");
|
|
|
|
let response = call_service(&app, req).await;
|
2021-10-13 14:51:29 +03:00
|
|
|
assert!(response.status().is_success());
|
|
|
|
|
|
|
|
// zoom = 6 (public.points2)
|
2022-10-12 11:52:26 +03:00
|
|
|
let req = test_get("/public.points2/6/38/20.pbf");
|
|
|
|
let response = call_service(&app, req).await;
|
2021-10-13 14:51:29 +03:00
|
|
|
assert!(response.status().is_success());
|
|
|
|
|
|
|
|
// zoom = 12 (public.points2)
|
2022-10-12 11:52:26 +03:00
|
|
|
let req = test_get("/public.points2/12/2476/1280.pbf");
|
|
|
|
let response = call_service(&app, req).await;
|
2021-10-13 14:51:29 +03:00
|
|
|
assert!(response.status().is_success());
|
|
|
|
|
|
|
|
// zoom = 13 (public.points2)
|
2022-10-12 11:52:26 +03:00
|
|
|
let req = test_get("/public.points2/13/4952/2560.pbf");
|
|
|
|
let response = call_service(&app, req).await;
|
2021-10-13 14:51:29 +03:00
|
|
|
assert!(response.status().is_success());
|
|
|
|
|
|
|
|
// zoom = 0 (nothing)
|
2022-10-12 11:52:26 +03:00
|
|
|
let req = test_get("/public.points3857/0/0/0.pbf");
|
|
|
|
let response = call_service(&app, req).await;
|
|
|
|
assert_eq!(response.status(), StatusCode::NOT_FOUND);
|
2021-10-13 14:51:29 +03:00
|
|
|
|
|
|
|
// zoom = 12 (public.points3857)
|
2022-10-12 11:52:26 +03:00
|
|
|
let req = test_get("/public.points3857/12/2476/1280.pbf");
|
|
|
|
let response = call_service(&app, req).await;
|
2021-10-13 14:51:29 +03:00
|
|
|
assert!(response.status().is_success());
|
|
|
|
|
|
|
|
// zoom = 0 (public.table_source)
|
2022-10-12 11:52:26 +03:00
|
|
|
let req = test_get("/public.table_source/0/0/0.pbf");
|
|
|
|
let response = call_service(&app, req).await;
|
2021-10-13 14:51:29 +03:00
|
|
|
assert!(response.status().is_success());
|
|
|
|
|
|
|
|
// zoom = 12 (nothing)
|
2022-10-12 11:52:26 +03:00
|
|
|
let req = test_get("/public.table_source/12/2476/1280.pbf");
|
|
|
|
let response = call_service(&app, req).await;
|
|
|
|
assert_eq!(response.status(), StatusCode::NOT_FOUND);
|
2021-10-13 14:51:29 +03:00
|
|
|
}
|
|
|
|
|
2021-04-24 20:19:37 +03:00
|
|
|
#[actix_rt::test]
|
2022-10-12 11:52:26 +03:00
|
|
|
async fn get_composite_source_ok() {
|
|
|
|
let app = create_app!(Some(mock_default_table_sources()), None);
|
2021-04-24 20:19:37 +03:00
|
|
|
|
2022-10-12 11:52:26 +03:00
|
|
|
let req = test_get("/public.non_existent1,public.non_existent2.json");
|
|
|
|
let response = call_service(&app, req).await;
|
|
|
|
assert_eq!(response.status(), StatusCode::NOT_FOUND);
|
2021-04-24 20:19:37 +03:00
|
|
|
|
2022-10-12 11:52:26 +03:00
|
|
|
let req = test_get("/public.points1,public.points2,public.points3857.json");
|
|
|
|
let response = call_service(&app, req).await;
|
2021-04-24 20:19:37 +03:00
|
|
|
assert!(response.status().is_success());
|
|
|
|
}
|
|
|
|
|
|
|
|
#[actix_rt::test]
|
2022-10-12 11:52:26 +03:00
|
|
|
async fn get_composite_source_tile_ok() {
|
|
|
|
let app = create_app!(Some(mock_default_table_sources()), None);
|
2021-04-24 20:19:37 +03:00
|
|
|
|
2022-10-12 11:52:26 +03:00
|
|
|
let req = test_get("/public.non_existent1,public.non_existent2/0/0/0.pbf");
|
|
|
|
let response = call_service(&app, req).await;
|
|
|
|
assert_eq!(response.status(), StatusCode::NOT_FOUND);
|
2021-04-24 20:19:37 +03:00
|
|
|
|
2022-10-12 11:52:26 +03:00
|
|
|
let req = test_get("/public.points1,public.points2,public.points3857/0/0/0.pbf");
|
|
|
|
let response = call_service(&app, req).await;
|
2021-04-24 20:19:37 +03:00
|
|
|
assert!(response.status().is_success());
|
|
|
|
}
|
|
|
|
|
2021-10-13 14:51:29 +03:00
|
|
|
#[actix_rt::test]
|
2022-10-12 11:52:26 +03:00
|
|
|
async fn get_composite_source_tile_minmax_zoom_ok() {
|
2021-10-13 14:51:29 +03:00
|
|
|
init();
|
|
|
|
|
|
|
|
let public_points1 = TableSource {
|
|
|
|
id: "public.points1".to_owned(),
|
|
|
|
schema: "public".to_owned(),
|
|
|
|
table: "points1".to_owned(),
|
|
|
|
id_column: None,
|
|
|
|
geometry_column: "geom".to_owned(),
|
2022-05-30 14:06:44 +03:00
|
|
|
bounds: Some(Bounds::MAX),
|
2021-10-13 14:51:29 +03:00
|
|
|
minzoom: Some(6),
|
|
|
|
maxzoom: Some(13),
|
|
|
|
srid: 4326,
|
|
|
|
extent: Some(4096),
|
|
|
|
buffer: Some(64),
|
|
|
|
clip_geom: Some(true),
|
|
|
|
geometry_type: None,
|
|
|
|
properties: HashMap::new(),
|
|
|
|
};
|
|
|
|
|
|
|
|
let public_points2 = TableSource {
|
|
|
|
id: "public.points2".to_owned(),
|
|
|
|
schema: "public".to_owned(),
|
|
|
|
table: "points2".to_owned(),
|
|
|
|
id_column: None,
|
|
|
|
geometry_column: "geom".to_owned(),
|
2022-05-30 14:06:44 +03:00
|
|
|
bounds: Some(Bounds::MAX),
|
2021-10-13 14:51:29 +03:00
|
|
|
minzoom: Some(13),
|
|
|
|
maxzoom: Some(20),
|
|
|
|
srid: 4326,
|
|
|
|
extent: Some(4096),
|
|
|
|
buffer: Some(64),
|
|
|
|
clip_geom: Some(true),
|
|
|
|
geometry_type: None,
|
|
|
|
properties: HashMap::new(),
|
|
|
|
};
|
|
|
|
|
2022-10-12 11:52:26 +03:00
|
|
|
let tables = &[public_points1, public_points2];
|
|
|
|
let app = create_app!(Some(mock_table_sources(tables)), None);
|
2021-10-13 14:51:29 +03:00
|
|
|
|
|
|
|
// zoom = 0 (nothing)
|
2022-10-12 11:52:26 +03:00
|
|
|
let req = test_get("/public.points1,public.points2/0/0/0.pbf");
|
|
|
|
let response = call_service(&app, req).await;
|
|
|
|
assert_eq!(response.status(), StatusCode::NOT_FOUND);
|
2021-10-13 14:51:29 +03:00
|
|
|
|
|
|
|
// zoom = 6 (public.points1)
|
2022-10-12 11:52:26 +03:00
|
|
|
let req = test_get("/public.points1,public.points2/6/38/20.pbf");
|
|
|
|
let response = call_service(&app, req).await;
|
2021-10-13 14:51:29 +03:00
|
|
|
assert!(response.status().is_success());
|
|
|
|
|
|
|
|
// zoom = 12 (public.points1)
|
2022-10-12 11:52:26 +03:00
|
|
|
let req = test_get("/public.points1,public.points2/12/2476/1280.pbf");
|
|
|
|
let response = call_service(&app, req).await;
|
2021-10-13 14:51:29 +03:00
|
|
|
assert!(response.status().is_success());
|
|
|
|
|
|
|
|
// zoom = 13 (public.points1, public.points2)
|
2022-10-12 11:52:26 +03:00
|
|
|
let req = test_get("/public.points1,public.points2/13/4952/2560.pbf");
|
|
|
|
let response = call_service(&app, req).await;
|
2021-10-13 14:51:29 +03:00
|
|
|
assert!(response.status().is_success());
|
|
|
|
|
|
|
|
// zoom = 14 (public.points2)
|
2022-10-12 11:52:26 +03:00
|
|
|
let req = test_get("/public.points1,public.points2/14/9904/5121.pbf");
|
|
|
|
let response = call_service(&app, req).await;
|
2021-10-13 14:51:29 +03:00
|
|
|
assert!(response.status().is_success());
|
|
|
|
|
|
|
|
// zoom = 20 (public.points2)
|
2022-10-12 11:52:26 +03:00
|
|
|
let req = test_get("/public.points1,public.points2/20/633856/327787.pbf");
|
|
|
|
let response = call_service(&app, req).await;
|
2021-10-13 14:51:29 +03:00
|
|
|
assert!(response.status().is_success());
|
|
|
|
|
|
|
|
// zoom = 21 (nothing)
|
2022-10-12 11:52:26 +03:00
|
|
|
let req = test_get("/public.points1,public.points2/21/1267712/655574.pbf");
|
|
|
|
let response = call_service(&app, req).await;
|
|
|
|
assert_eq!(response.status(), StatusCode::NOT_FOUND);
|
2021-10-13 14:51:29 +03:00
|
|
|
}
|
|
|
|
|
2020-04-26 17:57:13 +03:00
|
|
|
#[actix_rt::test]
|
2022-10-12 11:52:26 +03:00
|
|
|
async fn get_function_sources_ok() {
|
|
|
|
let app = create_app!(None, Some(mock_default_function_sources()));
|
2020-06-02 09:49:21 +03:00
|
|
|
|
2022-10-12 11:52:26 +03:00
|
|
|
let req = test_get("/rpc/index.json");
|
|
|
|
let response = call_service(&app, req).await;
|
2020-06-02 09:49:21 +03:00
|
|
|
assert!(response.status().is_success());
|
|
|
|
|
2022-10-12 11:52:26 +03:00
|
|
|
let body = read_body(response).await;
|
2020-06-02 09:49:21 +03:00
|
|
|
let function_sources: FunctionSources = serde_json::from_slice(&body).unwrap();
|
|
|
|
assert!(function_sources.contains_key("public.function_source"));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[actix_rt::test]
|
2022-10-12 11:52:26 +03:00
|
|
|
async fn get_function_sources_watch_mode_ok() {
|
|
|
|
let app = create_app!(None, Some(mock_default_function_sources()));
|
2020-06-02 09:49:21 +03:00
|
|
|
|
2022-10-12 11:52:26 +03:00
|
|
|
let req = test_get("/rpc/index.json");
|
|
|
|
let response = call_service(&app, req).await;
|
2020-05-05 14:13:48 +03:00
|
|
|
assert!(response.status().is_success());
|
2019-10-26 20:37:49 +03:00
|
|
|
|
2022-10-12 11:52:26 +03:00
|
|
|
let body = read_body(response).await;
|
2020-05-05 14:13:48 +03:00
|
|
|
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]
|
2022-10-12 11:52:26 +03:00
|
|
|
async fn get_function_source_ok() {
|
|
|
|
let app = create_app!(None, Some(mock_default_function_sources()));
|
2020-06-02 09:49:21 +03:00
|
|
|
|
2022-10-12 11:52:26 +03:00
|
|
|
let req = test_get("/rpc/public.non_existent.json");
|
|
|
|
let response = call_service(&app, req).await;
|
|
|
|
assert_eq!(response.status(), StatusCode::NOT_FOUND);
|
2019-10-26 20:37:49 +03:00
|
|
|
|
2022-10-12 11:52:26 +03:00
|
|
|
let req = test_get("/rpc/public.function_source.json");
|
|
|
|
let response = call_service(&app, req).await;
|
2020-05-05 14:13:48 +03:00
|
|
|
assert!(response.status().is_success());
|
2021-10-15 18:19:36 +03:00
|
|
|
|
2022-10-12 11:52:26 +03:00
|
|
|
let req = TestRequest::get()
|
2021-10-15 18:19:36 +03:00
|
|
|
.uri("/rpc/public.function_source.json?token=martin")
|
2022-08-15 16:54:48 +03:00
|
|
|
.insert_header((
|
2021-10-15 18:19:36 +03:00
|
|
|
"x-rewrite-url",
|
|
|
|
"/tiles/rpc/public.function_source.json?token=martin",
|
2022-08-15 16:54:48 +03:00
|
|
|
))
|
2021-10-15 18:19:36 +03:00
|
|
|
.to_request();
|
2022-10-12 11:52:26 +03:00
|
|
|
let result: TileJSON = call_and_read_body_json(&app, req).await;
|
2021-10-15 18:19:36 +03:00
|
|
|
assert_eq!(
|
|
|
|
result.tiles,
|
|
|
|
vec!["http://localhost:8080/tiles/rpc/public.function_source/{z}/{x}/{y}.pbf?token=martin"]
|
|
|
|
);
|
2019-10-26 20:37:49 +03:00
|
|
|
}
|
|
|
|
|
2020-04-26 17:57:13 +03:00
|
|
|
#[actix_rt::test]
|
2022-10-12 11:52:26 +03:00
|
|
|
async fn get_function_source_tile_ok() {
|
|
|
|
let app = create_app!(None, Some(mock_default_function_sources()));
|
2019-10-26 20:37:49 +03:00
|
|
|
|
2022-10-12 11:52:26 +03:00
|
|
|
let req = test_get("/rpc/public.function_source/0/0/0.pbf");
|
|
|
|
let response = call_service(&app, req).await;
|
2020-05-05 14:13:48 +03:00
|
|
|
assert!(response.status().is_success());
|
2019-10-26 20:37:49 +03:00
|
|
|
}
|
2021-01-16 16:11:19 +03:00
|
|
|
|
2021-10-13 14:51:29 +03:00
|
|
|
#[actix_rt::test]
|
2022-10-12 11:52:26 +03:00
|
|
|
async fn get_function_source_tile_minmax_zoom_ok() {
|
2021-10-13 14:51:29 +03:00
|
|
|
let function_source1 = FunctionSource {
|
|
|
|
id: "public.function_source1".to_owned(),
|
|
|
|
schema: "public".to_owned(),
|
|
|
|
function: "function_source".to_owned(),
|
|
|
|
minzoom: None,
|
|
|
|
maxzoom: None,
|
2022-05-30 14:06:44 +03:00
|
|
|
bounds: Some(Bounds::MAX),
|
2021-10-13 14:51:29 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
let function_source2 = FunctionSource {
|
|
|
|
id: "public.function_source2".to_owned(),
|
|
|
|
schema: "public".to_owned(),
|
|
|
|
function: "function_source".to_owned(),
|
|
|
|
minzoom: Some(6),
|
|
|
|
maxzoom: Some(12),
|
2022-05-30 14:06:44 +03:00
|
|
|
bounds: Some(Bounds::MAX),
|
2021-10-13 14:51:29 +03:00
|
|
|
};
|
|
|
|
|
2022-10-12 11:52:26 +03:00
|
|
|
let funcs = &[function_source1, function_source2];
|
|
|
|
let app = create_app!(None, Some(mock_function_sources(funcs)));
|
2021-10-13 14:51:29 +03:00
|
|
|
|
|
|
|
// zoom = 0 (public.function_source1)
|
2022-10-12 11:52:26 +03:00
|
|
|
let req = test_get("/rpc/public.function_source1/0/0/0.pbf");
|
|
|
|
let response = call_service(&app, req).await;
|
2021-10-13 14:51:29 +03:00
|
|
|
assert!(response.status().is_success());
|
|
|
|
|
|
|
|
// zoom = 6 (public.function_source1)
|
2022-10-12 11:52:26 +03:00
|
|
|
let req = test_get("/rpc/public.function_source1/6/38/20.pbf");
|
|
|
|
let response = call_service(&app, req).await;
|
2021-10-13 14:51:29 +03:00
|
|
|
assert!(response.status().is_success());
|
|
|
|
|
|
|
|
// zoom = 12 (public.function_source1)
|
2022-10-12 11:52:26 +03:00
|
|
|
let req = test_get("/rpc/public.function_source1/12/2476/1280.pbf");
|
|
|
|
let response = call_service(&app, req).await;
|
2021-10-13 14:51:29 +03:00
|
|
|
assert!(response.status().is_success());
|
|
|
|
|
|
|
|
// zoom = 13 (public.function_source1)
|
2022-10-12 11:52:26 +03:00
|
|
|
let req = test_get("/rpc/public.function_source1/13/4952/2560.pbf");
|
|
|
|
let response = call_service(&app, req).await;
|
2021-10-13 14:51:29 +03:00
|
|
|
assert!(response.status().is_success());
|
|
|
|
|
|
|
|
// zoom = 0 (nothing)
|
2022-10-12 11:52:26 +03:00
|
|
|
let req = test_get("/rpc/public.function_source2/0/0/0.pbf");
|
|
|
|
let response = call_service(&app, req).await;
|
|
|
|
assert_eq!(response.status(), StatusCode::NOT_FOUND);
|
2021-10-13 14:51:29 +03:00
|
|
|
|
|
|
|
// zoom = 6 (public.function_source2)
|
2022-10-12 11:52:26 +03:00
|
|
|
let req = test_get("/rpc/public.function_source2/6/38/20.pbf");
|
|
|
|
let response = call_service(&app, req).await;
|
2021-10-13 14:51:29 +03:00
|
|
|
assert!(response.status().is_success());
|
|
|
|
|
|
|
|
// zoom = 12 (public.function_source2)
|
2022-10-12 11:52:26 +03:00
|
|
|
let req = test_get("/rpc/public.function_source2/12/2476/1280.pbf");
|
|
|
|
let response = call_service(&app, req).await;
|
2021-10-13 14:51:29 +03:00
|
|
|
assert!(response.status().is_success());
|
|
|
|
|
|
|
|
// zoom = 13 (nothing)
|
2022-10-12 11:52:26 +03:00
|
|
|
let req = test_get("/rpc/public.function_source2/13/4952/2560.pbf");
|
|
|
|
let response = call_service(&app, req).await;
|
|
|
|
assert_eq!(response.status(), StatusCode::NOT_FOUND);
|
2021-10-13 14:51:29 +03:00
|
|
|
}
|
|
|
|
|
2021-07-16 12:09:18 +03:00
|
|
|
#[actix_rt::test]
|
2022-10-12 11:52:26 +03:00
|
|
|
async fn get_function_source_query_params_ok() {
|
|
|
|
let app = create_app!(None, Some(mock_default_function_sources()));
|
2021-07-16 12:09:18 +03:00
|
|
|
|
2022-10-12 11:52:26 +03:00
|
|
|
let req = test_get("/rpc/public.function_source_query_params/0/0/0.pbf");
|
|
|
|
let response = call_service(&app, req).await;
|
2021-07-16 12:09:18 +03:00
|
|
|
println!("response.status = {:?}", response.status());
|
|
|
|
assert!(response.status().is_server_error());
|
|
|
|
|
2022-10-12 11:52:26 +03:00
|
|
|
let req = test_get("/rpc/public.function_source_query_params/0/0/0.pbf?token=martin");
|
|
|
|
let response = call_service(&app, req).await;
|
2021-07-16 12:09:18 +03:00
|
|
|
assert!(response.status().is_success());
|
|
|
|
}
|
|
|
|
|
2021-01-16 16:11:19 +03:00
|
|
|
#[actix_rt::test]
|
2022-10-12 11:52:26 +03:00
|
|
|
async fn get_health_returns_ok() {
|
|
|
|
let app = create_app!(None, Some(mock_default_function_sources()));
|
2021-01-16 16:11:19 +03:00
|
|
|
|
2022-10-12 11:52:26 +03:00
|
|
|
let req = test_get("/healthz");
|
|
|
|
let response = call_service(&app, req).await;
|
2021-01-16 16:11:19 +03:00
|
|
|
assert!(response.status().is_success());
|
|
|
|
}
|