martin/tests/function_source_test.rs

64 lines
1.8 KiB
Rust
Raw Normal View History

use ctor::ctor;
use log::info;
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
#[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]
async fn get_function_sources() {
let pool = mock_pool().await;
let sources = get_sources(&pool, &FunctionInfoSources::default())
.await
.unwrap();
2021-10-23 17:02:18 +03:00
info!("sources = {sources:#?}");
2021-10-23 17:02:18 +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]
async fn function_source_tilejson() {
let sources = mock_sources(None, None).await;
let source = sources.get("function_zxy_query").unwrap();
let tilejson = source.get_tilejson();
2021-10-23 17:02:18 +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()));
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]
async fn function_source_tile() {
let sources = mock_sources(None, None).await;
let source = sources.get("function_zxy_query").unwrap();
let tile = source
.get_tile(&Xyz { x: 0, y: 0, z: 0 }, &None)
.await
2021-10-23 17:02:18 +03:00
.unwrap();
assert!(!tile.is_empty());
}