martin/tests/pg_function_source_test.rs
Yuri Astrakhan 9e5ed2fc02
Add .mbtiles support (#549)
Adds a new [.mbtiles](https://github.com/mapbox/mbtiles-spec/blob/master/1.3/spec.md)
backend, without the grid support. Uses extensive tile content
detection, i.e. if the content is gzipped, png, jpeg, gif, webp.

From CLI, can be as easy as adding a path to a directory that contains a
.mbtiles file (works just like pmtiles support)

```bash
# All *.mbtiles 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
(same as pmtiles)

```yaml
mbtiles:
  paths:
    # scan this whole dir, matching all *.mbtiles files
    - /dir-path
    # specific mbtiles file will be published as mbtiles2 source
    - /path/to/mbtiles2.mbtiles
  sources:
      # named source matching source name to a single file
      pm-src1: /tmp/mbtiles.mbtiles
      # named source, where the filename is explicitly set. This way we will be able to add more options later
      pm-src2:
        path: /tmp/mbtiles.mbtiles
```

Fixes #494
2023-01-09 00:10:23 -05:00

78 lines
2.2 KiB
Rust

use ctor::ctor;
use indoc::indoc;
use itertools::Itertools;
use martin::pg::get_function_sources;
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 get_function_sources_ok() {
let pool = mock_pool().await;
let sources = get_function_sources(&pool).await.unwrap();
assert!(!sources.is_empty());
let funcs = sources.get("public").unwrap();
let source = funcs.get("function_zxy_query").unwrap();
assert_eq!(source.1.schema, "public");
assert_eq!(source.1.function, "function_zxy_query");
assert_eq!(source.1.minzoom, None);
assert_eq!(source.1.maxzoom, None);
assert_eq!(source.1.bounds, None);
let source = funcs.get("function_zxy_query_jsonb").unwrap();
assert_eq!(source.1.schema, "public");
assert_eq!(source.1.function, "function_zxy_query_jsonb");
}
#[actix_rt::test]
async fn function_source_tilejson() {
let mock = mock_sources(mock_pgcfg("connection_string: $DATABASE_URL")).await;
let tilejson = source(&mock, "function_zxy_query").get_tilejson();
assert_eq!(tilejson.tilejson, "3.0.0");
assert_eq!(tilejson.name, some("public.function_zxy_query"));
assert!(tilejson.tiles.is_empty());
}
#[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"],
);
}