2021-10-13 14:51:29 +03:00
|
|
|
use std::collections::HashMap;
|
|
|
|
|
2022-08-15 16:54:48 +03:00
|
|
|
use actix_web::web::Data;
|
2019-10-26 20:37:49 +03:00
|
|
|
use actix_web::{http, test, App};
|
2021-10-13 14:51:29 +03:00
|
|
|
use martin::dev;
|
|
|
|
use martin::function_source::{FunctionSource, FunctionSources};
|
2019-10-26 20:37:49 +03:00
|
|
|
use martin::server::router;
|
2021-10-13 14:51:29 +03:00
|
|
|
use martin::table_source::{TableSource, TableSources};
|
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();
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
|
2022-08-15 16:54:48 +03:00
|
|
|
let state = dev::mock_state(Some(dev::mock_default_table_sources()), None, None).await;
|
|
|
|
let app = test::init_service(App::new().app_data(Data::new(state)).configure(router)).await;
|
2020-06-02 09:49:21 +03:00
|
|
|
|
|
|
|
let req = test::TestRequest::get().uri("/index.json").to_request();
|
2022-08-15 16:54:48 +03:00
|
|
|
let response = test::call_service(&app, req).await;
|
2020-06-02 09:49:21 +03:00
|
|
|
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();
|
|
|
|
|
2022-08-15 16:54:48 +03:00
|
|
|
let state = dev::mock_state(Some(dev::mock_default_table_sources()), None, None).await;
|
|
|
|
let app = test::init_service(App::new().app_data(Data::new(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();
|
2022-08-15 16:54:48 +03:00
|
|
|
let response = test::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
|
|
|
|
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();
|
|
|
|
|
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(),
|
|
|
|
};
|
|
|
|
|
|
|
|
let state = dev::mock_state(
|
|
|
|
Some(dev::mock_table_sources(vec![table_source])),
|
|
|
|
None,
|
2022-02-13 15:43:52 +03:00
|
|
|
None,
|
2022-08-15 16:54:48 +03:00
|
|
|
)
|
|
|
|
.await;
|
|
|
|
let app = test::init_service(App::new().app_data(Data::new(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
|
|
|
|
2022-08-15 16:54:48 +03:00
|
|
|
let response = test::call_service(&app, req).await;
|
2020-05-05 14:13:48 +03:00
|
|
|
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()
|
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();
|
2019-10-26 20:37:49 +03:00
|
|
|
|
2022-08-15 16:54:48 +03:00
|
|
|
let result: TileJSON = test::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]
|
|
|
|
async fn test_get_table_source_tile_ok() {
|
2020-06-02 09:49:21 +03:00
|
|
|
init();
|
|
|
|
|
2022-08-15 16:54:48 +03:00
|
|
|
let state = dev::mock_state(Some(dev::mock_default_table_sources()), None, None).await;
|
|
|
|
let app = test::init_service(App::new().app_data(Data::new(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();
|
|
|
|
|
2022-08-15 16:54:48 +03:00
|
|
|
let response = test::call_service(&app, req).await;
|
2021-04-24 20:19:37 +03:00
|
|
|
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
|
|
|
|
2022-08-15 16:54:48 +03:00
|
|
|
let response = test::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]
|
|
|
|
async fn test_get_table_source_multiple_geom_tile_ok() {
|
|
|
|
init();
|
|
|
|
|
2022-08-15 16:54:48 +03:00
|
|
|
let state = dev::mock_state(Some(dev::mock_default_table_sources()), None, None).await;
|
|
|
|
let app = test::init_service(App::new().app_data(Data::new(state)).configure(router)).await;
|
2021-10-21 12:20:33 +03:00
|
|
|
|
|
|
|
let req = test::TestRequest::get()
|
|
|
|
.uri("/public.table_source_multiple_geom.geom1/0/0/0.pbf")
|
|
|
|
.to_request();
|
|
|
|
|
2022-08-15 16:54:48 +03:00
|
|
|
let response = test::call_service(&app, req).await;
|
2021-10-21 12:20:33 +03:00
|
|
|
assert!(response.status().is_success());
|
|
|
|
|
|
|
|
let req = test::TestRequest::get()
|
|
|
|
.uri("/public.table_source_multiple_geom.geom2/0/0/0.pbf")
|
|
|
|
.to_request();
|
|
|
|
|
2022-08-15 16:54:48 +03:00
|
|
|
let response = test::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]
|
|
|
|
async fn test_get_table_source_tile_minmax_zoom_ok() {
|
|
|
|
init();
|
|
|
|
|
|
|
|
let 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(12),
|
|
|
|
srid: 4326,
|
|
|
|
extent: Some(4096),
|
|
|
|
buffer: Some(64),
|
|
|
|
clip_geom: Some(true),
|
|
|
|
geometry_type: None,
|
|
|
|
properties: HashMap::new(),
|
|
|
|
};
|
|
|
|
|
|
|
|
let 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: None,
|
|
|
|
maxzoom: None,
|
|
|
|
srid: 4326,
|
|
|
|
extent: Some(4096),
|
|
|
|
buffer: Some(64),
|
|
|
|
clip_geom: Some(true),
|
|
|
|
geometry_type: None,
|
|
|
|
properties: HashMap::new(),
|
|
|
|
};
|
|
|
|
|
|
|
|
let points3857 = TableSource {
|
|
|
|
id: "public.points3857".to_owned(),
|
|
|
|
schema: "public".to_owned(),
|
|
|
|
table: "points3857".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: None,
|
|
|
|
srid: 4326,
|
|
|
|
extent: Some(4096),
|
|
|
|
buffer: Some(64),
|
|
|
|
clip_geom: Some(true),
|
|
|
|
geometry_type: None,
|
|
|
|
properties: HashMap::new(),
|
|
|
|
};
|
|
|
|
|
|
|
|
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: None,
|
|
|
|
maxzoom: Some(6),
|
|
|
|
srid: 4326,
|
|
|
|
extent: Some(4096),
|
|
|
|
buffer: Some(64),
|
|
|
|
clip_geom: Some(true),
|
|
|
|
geometry_type: None,
|
|
|
|
properties: HashMap::new(),
|
|
|
|
};
|
|
|
|
|
|
|
|
let state = dev::mock_state(
|
|
|
|
Some(dev::mock_table_sources(vec![
|
|
|
|
points1,
|
|
|
|
points2,
|
|
|
|
points3857,
|
|
|
|
table_source,
|
|
|
|
])),
|
|
|
|
None,
|
2022-02-13 15:43:52 +03:00
|
|
|
None,
|
2022-08-15 16:54:48 +03:00
|
|
|
)
|
|
|
|
.await;
|
2021-10-13 14:51:29 +03:00
|
|
|
|
2022-08-15 16:54:48 +03:00
|
|
|
let app = test::init_service(App::new().app_data(Data::new(state)).configure(router)).await;
|
2021-10-13 14:51:29 +03:00
|
|
|
|
|
|
|
// zoom = 0 (nothing)
|
|
|
|
let req = test::TestRequest::get()
|
|
|
|
.uri("/public.points1/0/0/0.pbf")
|
|
|
|
.to_request();
|
|
|
|
|
2022-08-15 16:54:48 +03:00
|
|
|
let response = test::call_service(&app, req).await;
|
2021-10-13 14:51:29 +03:00
|
|
|
assert_eq!(response.status(), http::StatusCode::NOT_FOUND);
|
|
|
|
|
|
|
|
// zoom = 6 (public.points1)
|
|
|
|
let req = test::TestRequest::get()
|
|
|
|
.uri("/public.points1/6/38/20.pbf")
|
|
|
|
.to_request();
|
|
|
|
|
2022-08-15 16:54:48 +03:00
|
|
|
let response = test::call_service(&app, req).await;
|
2021-10-13 14:51:29 +03:00
|
|
|
assert!(response.status().is_success());
|
|
|
|
|
|
|
|
// zoom = 12 (public.points1)
|
|
|
|
let req = test::TestRequest::get()
|
|
|
|
.uri("/public.points1/12/2476/1280.pbf")
|
|
|
|
.to_request();
|
|
|
|
|
2022-08-15 16:54:48 +03:00
|
|
|
let response = test::call_service(&app, req).await;
|
2021-10-13 14:51:29 +03:00
|
|
|
assert!(response.status().is_success());
|
|
|
|
|
|
|
|
// zoom = 13 (nothing)
|
|
|
|
let req = test::TestRequest::get()
|
|
|
|
.uri("/public.points1/13/4952/2560.pbf")
|
|
|
|
.to_request();
|
|
|
|
|
2022-08-15 16:54:48 +03:00
|
|
|
let response = test::call_service(&app, req).await;
|
2021-10-13 14:51:29 +03:00
|
|
|
assert_eq!(response.status(), http::StatusCode::NOT_FOUND);
|
|
|
|
|
|
|
|
// zoom = 0 (public.points2)
|
|
|
|
let req = test::TestRequest::get()
|
|
|
|
.uri("/public.points2/0/0/0.pbf")
|
|
|
|
.to_request();
|
|
|
|
|
2022-08-15 16:54:48 +03:00
|
|
|
let response = test::call_service(&app, req).await;
|
2021-10-13 14:51:29 +03:00
|
|
|
assert!(response.status().is_success());
|
|
|
|
|
|
|
|
// zoom = 6 (public.points2)
|
|
|
|
let req = test::TestRequest::get()
|
|
|
|
.uri("/public.points2/6/38/20.pbf")
|
|
|
|
.to_request();
|
|
|
|
|
2022-08-15 16:54:48 +03:00
|
|
|
let response = test::call_service(&app, req).await;
|
2021-10-13 14:51:29 +03:00
|
|
|
assert!(response.status().is_success());
|
|
|
|
|
|
|
|
// zoom = 12 (public.points2)
|
|
|
|
let req = test::TestRequest::get()
|
|
|
|
.uri("/public.points2/12/2476/1280.pbf")
|
|
|
|
.to_request();
|
|
|
|
|
2022-08-15 16:54:48 +03:00
|
|
|
let response = test::call_service(&app, req).await;
|
2021-10-13 14:51:29 +03:00
|
|
|
assert!(response.status().is_success());
|
|
|
|
|
|
|
|
// zoom = 13 (public.points2)
|
|
|
|
let req = test::TestRequest::get()
|
|
|
|
.uri("/public.points2/13/4952/2560.pbf")
|
|
|
|
.to_request();
|
|
|
|
|
2022-08-15 16:54:48 +03:00
|
|
|
let response = test::call_service(&app, req).await;
|
2021-10-13 14:51:29 +03:00
|
|
|
assert!(response.status().is_success());
|
|
|
|
|
|
|
|
// zoom = 0 (nothing)
|
|
|
|
let req = test::TestRequest::get()
|
|
|
|
.uri("/public.points3857/0/0/0.pbf")
|
|
|
|
.to_request();
|
|
|
|
|
2022-08-15 16:54:48 +03:00
|
|
|
let response = test::call_service(&app, req).await;
|
2021-10-13 14:51:29 +03:00
|
|
|
assert_eq!(response.status(), http::StatusCode::NOT_FOUND);
|
|
|
|
|
|
|
|
// zoom = 12 (public.points3857)
|
|
|
|
let req = test::TestRequest::get()
|
|
|
|
.uri("/public.points3857/12/2476/1280.pbf")
|
|
|
|
.to_request();
|
|
|
|
|
2022-08-15 16:54:48 +03:00
|
|
|
let response = test::call_service(&app, req).await;
|
2021-10-13 14:51:29 +03:00
|
|
|
assert!(response.status().is_success());
|
|
|
|
|
|
|
|
// zoom = 0 (public.table_source)
|
|
|
|
let req = test::TestRequest::get()
|
|
|
|
.uri("/public.table_source/0/0/0.pbf")
|
|
|
|
.to_request();
|
|
|
|
|
2022-08-15 16:54:48 +03:00
|
|
|
let response = test::call_service(&app, req).await;
|
2021-10-13 14:51:29 +03:00
|
|
|
assert!(response.status().is_success());
|
|
|
|
|
|
|
|
// zoom = 12 (nothing)
|
|
|
|
let req = test::TestRequest::get()
|
|
|
|
.uri("/public.table_source/12/2476/1280.pbf")
|
|
|
|
.to_request();
|
|
|
|
|
2022-08-15 16:54:48 +03:00
|
|
|
let response = test::call_service(&app, req).await;
|
2021-10-13 14:51:29 +03:00
|
|
|
assert_eq!(response.status(), http::StatusCode::NOT_FOUND);
|
|
|
|
}
|
|
|
|
|
2021-04-24 20:19:37 +03:00
|
|
|
#[actix_rt::test]
|
|
|
|
async fn test_get_composite_source_ok() {
|
|
|
|
init();
|
|
|
|
|
2022-08-15 16:54:48 +03:00
|
|
|
let state = dev::mock_state(Some(dev::mock_default_table_sources()), None, None).await;
|
|
|
|
let app = test::init_service(App::new().app_data(Data::new(state)).configure(router)).await;
|
2021-04-24 20:19:37 +03:00
|
|
|
|
|
|
|
let req = test::TestRequest::get()
|
|
|
|
.uri("/public.non_existant1,public.non_existant2.json")
|
|
|
|
.to_request();
|
|
|
|
|
2022-08-15 16:54:48 +03:00
|
|
|
let response = test::call_service(&app, req).await;
|
2021-04-24 20:19:37 +03:00
|
|
|
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();
|
|
|
|
|
2022-08-15 16:54:48 +03:00
|
|
|
let response = test::call_service(&app, req).await;
|
2021-04-24 20:19:37 +03:00
|
|
|
assert!(response.status().is_success());
|
|
|
|
}
|
|
|
|
|
|
|
|
#[actix_rt::test]
|
|
|
|
async fn test_get_composite_source_tile_ok() {
|
|
|
|
init();
|
|
|
|
|
2022-08-15 16:54:48 +03:00
|
|
|
let state = dev::mock_state(Some(dev::mock_default_table_sources()), None, None).await;
|
|
|
|
let app = test::init_service(App::new().app_data(Data::new(state)).configure(router)).await;
|
2021-04-24 20:19:37 +03:00
|
|
|
|
|
|
|
let req = test::TestRequest::get()
|
|
|
|
.uri("/public.non_existant1,public.non_existant2/0/0/0.pbf")
|
|
|
|
.to_request();
|
|
|
|
|
2022-08-15 16:54:48 +03:00
|
|
|
let response = test::call_service(&app, req).await;
|
2021-04-24 20:19:37 +03:00
|
|
|
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();
|
|
|
|
|
2022-08-15 16:54:48 +03:00
|
|
|
let response = test::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]
|
|
|
|
async fn test_get_composite_source_tile_minmax_zoom_ok() {
|
|
|
|
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(),
|
|
|
|
};
|
|
|
|
|
|
|
|
let state = dev::mock_state(
|
|
|
|
Some(dev::mock_table_sources(vec![
|
|
|
|
public_points1,
|
|
|
|
public_points2,
|
|
|
|
])),
|
|
|
|
None,
|
2022-02-13 15:43:52 +03:00
|
|
|
None,
|
2022-08-15 16:54:48 +03:00
|
|
|
)
|
|
|
|
.await;
|
|
|
|
let app = test::init_service(App::new().app_data(Data::new(state)).configure(router)).await;
|
2021-10-13 14:51:29 +03:00
|
|
|
|
|
|
|
// zoom = 0 (nothing)
|
|
|
|
let req = test::TestRequest::get()
|
|
|
|
.uri("/public.points1,public.points2/0/0/0.pbf")
|
|
|
|
.to_request();
|
|
|
|
|
2022-08-15 16:54:48 +03:00
|
|
|
let response = test::call_service(&app, req).await;
|
2021-10-13 14:51:29 +03:00
|
|
|
assert_eq!(response.status(), http::StatusCode::NOT_FOUND);
|
|
|
|
|
|
|
|
// zoom = 6 (public.points1)
|
|
|
|
let req = test::TestRequest::get()
|
|
|
|
.uri("/public.points1,public.points2/6/38/20.pbf")
|
|
|
|
.to_request();
|
|
|
|
|
2022-08-15 16:54:48 +03:00
|
|
|
let response = test::call_service(&app, req).await;
|
2021-10-13 14:51:29 +03:00
|
|
|
assert!(response.status().is_success());
|
|
|
|
|
|
|
|
// zoom = 12 (public.points1)
|
|
|
|
let req = test::TestRequest::get()
|
|
|
|
.uri("/public.points1,public.points2/12/2476/1280.pbf")
|
|
|
|
.to_request();
|
|
|
|
|
2022-08-15 16:54:48 +03:00
|
|
|
let response = test::call_service(&app, req).await;
|
2021-10-13 14:51:29 +03:00
|
|
|
assert!(response.status().is_success());
|
|
|
|
|
|
|
|
// zoom = 13 (public.points1, public.points2)
|
|
|
|
let req = test::TestRequest::get()
|
|
|
|
.uri("/public.points1,public.points2/13/4952/2560.pbf")
|
|
|
|
.to_request();
|
|
|
|
|
2022-08-15 16:54:48 +03:00
|
|
|
let response = test::call_service(&app, req).await;
|
2021-10-13 14:51:29 +03:00
|
|
|
assert!(response.status().is_success());
|
|
|
|
|
|
|
|
// zoom = 14 (public.points2)
|
|
|
|
let req = test::TestRequest::get()
|
|
|
|
.uri("/public.points1,public.points2/14/9904/5121.pbf")
|
|
|
|
.to_request();
|
|
|
|
|
2022-08-15 16:54:48 +03:00
|
|
|
let response = test::call_service(&app, req).await;
|
2021-10-13 14:51:29 +03:00
|
|
|
assert!(response.status().is_success());
|
|
|
|
|
|
|
|
// zoom = 20 (public.points2)
|
|
|
|
let req = test::TestRequest::get()
|
|
|
|
.uri("/public.points1,public.points2/20/633856/327787.pbf")
|
|
|
|
.to_request();
|
|
|
|
|
2022-08-15 16:54:48 +03:00
|
|
|
let response = test::call_service(&app, req).await;
|
2021-10-13 14:51:29 +03:00
|
|
|
assert!(response.status().is_success());
|
|
|
|
|
|
|
|
// zoom = 21 (nothing)
|
|
|
|
let req = test::TestRequest::get()
|
|
|
|
.uri("/public.points1,public.points2/21/1267712/655574.pbf")
|
|
|
|
.to_request();
|
|
|
|
|
2022-08-15 16:54:48 +03:00
|
|
|
let response = test::call_service(&app, req).await;
|
2021-10-13 14:51:29 +03:00
|
|
|
assert_eq!(response.status(), http::StatusCode::NOT_FOUND);
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
|
2022-08-15 16:54:48 +03:00
|
|
|
let state = dev::mock_state(None, Some(dev::mock_default_function_sources()), None).await;
|
|
|
|
let app = test::init_service(App::new().app_data(Data::new(state)).configure(router)).await;
|
2020-06-02 09:49:21 +03:00
|
|
|
|
|
|
|
let req = test::TestRequest::get().uri("/rpc/index.json").to_request();
|
2022-08-15 16:54:48 +03:00
|
|
|
let response = test::call_service(&app, req).await;
|
2020-06-02 09:49:21 +03:00
|
|
|
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();
|
|
|
|
|
2022-08-15 16:54:48 +03:00
|
|
|
let state = dev::mock_state(None, Some(dev::mock_default_function_sources()), None).await;
|
|
|
|
let app = test::init_service(App::new().app_data(Data::new(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();
|
2022-08-15 16:54:48 +03:00
|
|
|
let response = test::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
|
|
|
|
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();
|
|
|
|
|
2022-08-15 16:54:48 +03:00
|
|
|
let state = dev::mock_state(None, Some(dev::mock_default_function_sources()), None).await;
|
|
|
|
let app = test::init_service(App::new().app_data(Data::new(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
|
|
|
|
2022-08-15 16:54:48 +03:00
|
|
|
let response = test::call_service(&app, req).await;
|
2020-05-05 14:13:48 +03:00
|
|
|
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
|
|
|
|
2022-08-15 16:54:48 +03:00
|
|
|
let response = test::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
|
|
|
|
|
|
|
let req = test::TestRequest::get()
|
|
|
|
.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-08-15 16:54:48 +03:00
|
|
|
let result: TileJSON = test::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]
|
|
|
|
async fn test_get_function_source_tile_ok() {
|
2020-06-02 09:49:21 +03:00
|
|
|
init();
|
|
|
|
|
2022-08-15 16:54:48 +03:00
|
|
|
let state = dev::mock_state(None, Some(dev::mock_default_function_sources()), None).await;
|
|
|
|
let app = test::init_service(App::new().app_data(Data::new(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
|
|
|
|
2022-08-15 16:54:48 +03:00
|
|
|
let response = test::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]
|
|
|
|
async fn test_get_function_source_tile_minmax_zoom_ok() {
|
|
|
|
init();
|
|
|
|
|
|
|
|
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
|
|
|
};
|
|
|
|
|
|
|
|
let state = dev::mock_state(
|
|
|
|
None,
|
|
|
|
Some(dev::mock_function_sources(vec![
|
|
|
|
function_source1,
|
|
|
|
function_source2,
|
|
|
|
])),
|
2022-02-13 15:43:52 +03:00
|
|
|
None,
|
2022-08-15 16:54:48 +03:00
|
|
|
)
|
|
|
|
.await;
|
2021-10-13 14:51:29 +03:00
|
|
|
|
2022-08-15 16:54:48 +03:00
|
|
|
let app = test::init_service(App::new().app_data(Data::new(state)).configure(router)).await;
|
2021-10-13 14:51:29 +03:00
|
|
|
|
|
|
|
// zoom = 0 (public.function_source1)
|
|
|
|
let req = test::TestRequest::get()
|
|
|
|
.uri("/rpc/public.function_source1/0/0/0.pbf")
|
|
|
|
.to_request();
|
|
|
|
|
2022-08-15 16:54:48 +03:00
|
|
|
let response = test::call_service(&app, req).await;
|
2021-10-13 14:51:29 +03:00
|
|
|
assert!(response.status().is_success());
|
|
|
|
|
|
|
|
// zoom = 6 (public.function_source1)
|
|
|
|
let req = test::TestRequest::get()
|
|
|
|
.uri("/rpc/public.function_source1/6/38/20.pbf")
|
|
|
|
.to_request();
|
|
|
|
|
2022-08-15 16:54:48 +03:00
|
|
|
let response = test::call_service(&app, req).await;
|
2021-10-13 14:51:29 +03:00
|
|
|
assert!(response.status().is_success());
|
|
|
|
|
|
|
|
// zoom = 12 (public.function_source1)
|
|
|
|
let req = test::TestRequest::get()
|
|
|
|
.uri("/rpc/public.function_source1/12/2476/1280.pbf")
|
|
|
|
.to_request();
|
|
|
|
|
2022-08-15 16:54:48 +03:00
|
|
|
let response = test::call_service(&app, req).await;
|
2021-10-13 14:51:29 +03:00
|
|
|
assert!(response.status().is_success());
|
|
|
|
|
|
|
|
// zoom = 13 (public.function_source1)
|
|
|
|
let req = test::TestRequest::get()
|
|
|
|
.uri("/rpc/public.function_source1/13/4952/2560.pbf")
|
|
|
|
.to_request();
|
|
|
|
|
2022-08-15 16:54:48 +03:00
|
|
|
let response = test::call_service(&app, req).await;
|
2021-10-13 14:51:29 +03:00
|
|
|
assert!(response.status().is_success());
|
|
|
|
|
|
|
|
// zoom = 0 (nothing)
|
|
|
|
let req = test::TestRequest::get()
|
|
|
|
.uri("/rpc/public.function_source2/0/0/0.pbf")
|
|
|
|
.to_request();
|
|
|
|
|
2022-08-15 16:54:48 +03:00
|
|
|
let response = test::call_service(&app, req).await;
|
2021-10-13 14:51:29 +03:00
|
|
|
assert_eq!(response.status(), http::StatusCode::NOT_FOUND);
|
|
|
|
|
|
|
|
// zoom = 6 (public.function_source2)
|
|
|
|
let req = test::TestRequest::get()
|
|
|
|
.uri("/rpc/public.function_source2/6/38/20.pbf")
|
|
|
|
.to_request();
|
|
|
|
|
2022-08-15 16:54:48 +03:00
|
|
|
let response = test::call_service(&app, req).await;
|
2021-10-13 14:51:29 +03:00
|
|
|
assert!(response.status().is_success());
|
|
|
|
|
|
|
|
// zoom = 12 (public.function_source2)
|
|
|
|
let req = test::TestRequest::get()
|
|
|
|
.uri("/rpc/public.function_source2/12/2476/1280.pbf")
|
|
|
|
.to_request();
|
|
|
|
|
2022-08-15 16:54:48 +03:00
|
|
|
let response = test::call_service(&app, req).await;
|
2021-10-13 14:51:29 +03:00
|
|
|
assert!(response.status().is_success());
|
|
|
|
|
|
|
|
// zoom = 13 (nothing)
|
|
|
|
let req = test::TestRequest::get()
|
|
|
|
.uri("/rpc/public.function_source2/13/4952/2560.pbf")
|
|
|
|
.to_request();
|
|
|
|
|
2022-08-15 16:54:48 +03:00
|
|
|
let response = test::call_service(&app, req).await;
|
2021-10-13 14:51:29 +03:00
|
|
|
assert_eq!(response.status(), http::StatusCode::NOT_FOUND);
|
|
|
|
}
|
|
|
|
|
2021-07-16 12:09:18 +03:00
|
|
|
#[actix_rt::test]
|
|
|
|
async fn test_get_function_source_query_params_ok() {
|
|
|
|
init();
|
|
|
|
|
2022-08-15 16:54:48 +03:00
|
|
|
let state = dev::mock_state(None, Some(dev::mock_default_function_sources()), None).await;
|
|
|
|
let app = test::init_service(App::new().app_data(Data::new(state)).configure(router)).await;
|
2021-07-16 12:09:18 +03:00
|
|
|
|
|
|
|
let req = test::TestRequest::get()
|
|
|
|
.uri("/rpc/public.function_source_query_params/0/0/0.pbf")
|
|
|
|
.to_request();
|
|
|
|
|
2022-08-15 16:54:48 +03:00
|
|
|
let response = test::call_service(&app, req).await;
|
2021-07-16 12:09:18 +03:00
|
|
|
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();
|
|
|
|
|
2022-08-15 16:54:48 +03:00
|
|
|
let response = test::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]
|
|
|
|
async fn test_get_health_returns_ok() {
|
|
|
|
init();
|
|
|
|
|
2022-08-15 16:54:48 +03:00
|
|
|
let state = dev::mock_state(None, Some(dev::mock_default_function_sources()), None).await;
|
|
|
|
let app = test::init_service(App::new().app_data(Data::new(state)).configure(router)).await;
|
2021-01-16 16:11:19 +03:00
|
|
|
|
|
|
|
let req = test::TestRequest::get().uri("/healthz").to_request();
|
2022-08-15 16:54:48 +03:00
|
|
|
let response = test::call_service(&app, req).await;
|
2021-01-16 16:11:19 +03:00
|
|
|
assert!(response.status().is_success());
|
|
|
|
}
|