martin/tests/pg_function_source_test.rs
Yuri Astrakhan e92722708f
PG TileJSON changes, add vector_layers (#584)
* make tilejson's `name` be the same as the ID of the source (even if
aliased)
* `/catalog` will always show ID, but now it will hide the `name` if it
is the same as the `id`
* make `description` be the longer version, e.g. `public.table.column`
format - not guaranteed to be stable
* make `vector_layers` have the fields auto-discovered in the PG table
* preserve the order of the serialized json fields

Fixes #583
2023-02-22 16:25:48 +00:00

64 lines
1.5 KiB
Rust

use ctor::ctor;
use indoc::indoc;
use itertools::Itertools;
use martin::Xyz;
pub mod utils;
pub use utils::*;
#[ctor]
fn init() {
let _ = env_logger::builder().is_test(true).try_init();
}
#[actix_rt::test]
async fn function_source_tilejson() {
let mock = mock_sources(mock_pgcfg("connection_string: $DATABASE_URL")).await;
assert_eq!(
source(&mock, "function_zxy_query").get_tilejson(),
serde_json::from_str(indoc! {r#"
{
"name": "function_zxy_query",
"description": "public.function_zxy_query",
"tilejson": "3.0.0",
"tiles": []
}
"#})
.unwrap()
);
}
#[actix_rt::test]
async fn function_source_tile() {
let mock = mock_sources(mock_pgcfg("connection_string: $DATABASE_URL")).await;
let src = source(&mock, "function_zxy_query");
let tile = src
.get_tile(&Xyz { z: 0, x: 0, y: 0 }, &None)
.await
.unwrap();
assert!(!tile.is_empty());
let src = source(&mock, "function_zxy_query_jsonb");
let tile = src
.get_tile(&Xyz { z: 0, x: 0, y: 0 }, &None)
.await
.unwrap();
assert!(!tile.is_empty());
}
#[actix_rt::test]
async fn function_source_schemas() {
let cfg = mock_pgcfg(indoc! {"
connection_string: $DATABASE_URL
auto_publish:
tables: false
functions:
from_schemas: MixedCase
"});
let sources = mock_sources(cfg).await.0;
assert_eq!(
sources.keys().sorted().collect::<Vec<_>>(),
vec!["function_Mixed_Name"],
);
}