mirror of
https://github.com/maplibre/martin.git
synced 2024-12-21 05:41:55 +03:00
ba65e34bef
Merge after #548 Adds a new [.pmtiles](https://protomaps.com/docs/pmtiles/) backend. Supports all formats like png, vector, etc. From CLI, can be as easy as adding a path to a directory that contains a .pmtiles file: ```bash # All *.pmtiles files in this dir will be published. # The filename will be used as the source ID martin ./tests/fixtures ``` From configuration file, the path can be specified in a number of ways: ```yaml pmtiles: paths: # scan this whole dir, matching all *.pmtiles files - /dir-path # specific pmtiles file will be published as pmtiles2 source - /path/to/pmtiles2.pmtiles sources: # named source matching source name to a single file pm-src1: /tmp/pmtiles.pmtiles # named source, where the filename is explicitly set. This way we will be able to add more options later pm-src2: path: /tmp/pmtiles.pmtiles ``` Fixes #508
72 lines
2.1 KiB
Rust
72 lines
2.1 KiB
Rust
use actix_http::Request;
|
|
use actix_web::test::{call_service, read_body, read_body_json, TestRequest};
|
|
use ctor::ctor;
|
|
use indoc::indoc;
|
|
use martin::srv::IndexEntry;
|
|
use tilejson::TileJSON;
|
|
|
|
pub mod utils;
|
|
pub use utils::*;
|
|
|
|
#[ctor]
|
|
fn init() {
|
|
let _ = env_logger::builder().is_test(true).try_init();
|
|
}
|
|
|
|
macro_rules! create_app {
|
|
($sources:expr) => {{
|
|
let sources = mock_sources(mock_cfg($sources)).await.0;
|
|
let state = crate::utils::mock_app_data(sources).await;
|
|
::actix_web::test::init_service(
|
|
::actix_web::App::new()
|
|
.app_data(state)
|
|
.configure(::martin::srv::router),
|
|
)
|
|
.await
|
|
}};
|
|
}
|
|
|
|
fn test_get(path: &str) -> Request {
|
|
TestRequest::get().uri(path).to_request()
|
|
}
|
|
|
|
#[actix_rt::test]
|
|
async fn pmt_get_catalog_ok() {
|
|
let app = create_app! { "pmtiles: tests/fixtures/stamen_toner__raster_CC-BY+ODbL_z3.pmtiles" };
|
|
|
|
let req = test_get("/catalog");
|
|
let response = call_service(&app, req).await;
|
|
assert!(response.status().is_success());
|
|
let body = read_body(response).await;
|
|
let sources: Vec<IndexEntry> = serde_json::from_slice(&body).unwrap();
|
|
|
|
let expected = "stamen_toner__raster_CC-BY-ODbL_z3";
|
|
assert_eq!(sources.iter().filter(|v| v.id == expected).count(), 1);
|
|
}
|
|
|
|
#[actix_rt::test]
|
|
async fn pmt_get_raster() {
|
|
let app = create_app! { indoc!{"
|
|
pmtiles:
|
|
sources:
|
|
pmt: tests/fixtures/stamen_toner__raster_CC-BY+ODbL_z3.pmtiles
|
|
"} };
|
|
|
|
let req = test_get("/pmt/0/0/0");
|
|
let response = call_service(&app, req).await;
|
|
assert!(response.status().is_success());
|
|
assert_eq!(response.headers().get("content-type").unwrap(), "image/png");
|
|
let body = read_body(response).await;
|
|
assert_eq!(body.len(), 18404);
|
|
|
|
let req = test_get("/pmt");
|
|
let response = call_service(&app, req).await;
|
|
assert!(response.status().is_success());
|
|
assert_eq!(
|
|
response.headers().get("content-type").unwrap(),
|
|
"application/json"
|
|
);
|
|
let body: TileJSON = read_body_json(response).await;
|
|
assert_eq!(body.maxzoom, Some(3));
|
|
}
|