2022-11-26 12:46:40 +03:00
|
|
|
use ctor::ctor;
|
2022-10-12 11:52:26 +03:00
|
|
|
use log::info;
|
2022-11-26 12:46:40 +03:00
|
|
|
use martin::pg::config::FunctionInfoSources;
|
|
|
|
use martin::pg::function_source::get_function_sources as get_sources;
|
|
|
|
use martin::source::Xyz;
|
2021-10-23 17:02:18 +03:00
|
|
|
|
2022-11-26 12:46:40 +03:00
|
|
|
#[path = "utils.rs"]
|
|
|
|
mod utils;
|
|
|
|
use utils::*;
|
|
|
|
|
|
|
|
#[ctor]
|
2021-10-23 17:02:18 +03:00
|
|
|
fn init() {
|
|
|
|
let _ = env_logger::builder().is_test(true).try_init();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[actix_rt::test]
|
2022-11-26 12:46:40 +03:00
|
|
|
async fn get_function_sources() {
|
|
|
|
let pool = mock_pool().await;
|
2022-11-30 19:57:27 +03:00
|
|
|
let sources = get_sources(&pool, &FunctionInfoSources::default())
|
2022-11-26 12:46:40 +03:00
|
|
|
.await
|
|
|
|
.unwrap();
|
2021-10-23 17:02:18 +03:00
|
|
|
|
2022-11-30 19:57:27 +03:00
|
|
|
info!("sources = {sources:#?}");
|
2021-10-23 17:02:18 +03:00
|
|
|
|
2022-11-30 19:57:27 +03:00
|
|
|
assert!(!sources.is_empty());
|
|
|
|
let source = single(&sources, |v| v.function == "function_zxy_query")
|
|
|
|
.expect("function_zxy_query not found");
|
|
|
|
assert_eq!(source.schema, "public");
|
|
|
|
assert_eq!(source.function, "function_zxy_query");
|
|
|
|
assert_eq!(source.minzoom, None);
|
|
|
|
assert_eq!(source.maxzoom, None);
|
|
|
|
assert_eq!(source.bounds, None);
|
2021-10-23 17:02:18 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[actix_rt::test]
|
2022-11-26 12:46:40 +03:00
|
|
|
async fn function_source_tilejson() {
|
|
|
|
let sources = mock_sources(None, None).await;
|
2022-11-30 19:57:27 +03:00
|
|
|
let source = sources.get("function_zxy_query").unwrap();
|
2022-11-26 12:46:40 +03:00
|
|
|
let tilejson = source.get_tilejson();
|
2021-10-23 17:02:18 +03:00
|
|
|
|
2022-10-12 11:52:26 +03:00
|
|
|
info!("tilejson = {tilejson:#?}");
|
2021-10-23 17:02:18 +03:00
|
|
|
|
|
|
|
assert_eq!(tilejson.tilejson, "2.2.0");
|
|
|
|
assert_eq!(tilejson.version, Some("1.0.0".to_owned()));
|
2022-11-30 19:57:27 +03:00
|
|
|
assert_eq!(tilejson.name, Some("public.function_zxy_query".to_owned()));
|
2021-10-23 17:02:18 +03:00
|
|
|
assert_eq!(tilejson.scheme, Some("xyz".to_owned()));
|
|
|
|
assert_eq!(tilejson.minzoom, Some(0));
|
|
|
|
assert_eq!(tilejson.maxzoom, Some(30));
|
|
|
|
assert!(tilejson.bounds.is_some());
|
|
|
|
assert!(tilejson.tiles.is_empty());
|
|
|
|
}
|
|
|
|
|
|
|
|
#[actix_rt::test]
|
2022-11-26 12:46:40 +03:00
|
|
|
async fn function_source_tile() {
|
|
|
|
let sources = mock_sources(None, None).await;
|
2022-11-30 19:57:27 +03:00
|
|
|
let source = sources.get("function_zxy_query").unwrap();
|
2022-11-26 12:46:40 +03:00
|
|
|
let tile = source
|
|
|
|
.get_tile(&Xyz { x: 0, y: 0, z: 0 }, &None)
|
2022-08-15 16:54:48 +03:00
|
|
|
.await
|
2021-10-23 17:02:18 +03:00
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
assert!(!tile.is_empty());
|
|
|
|
}
|