-
-
Notifications
You must be signed in to change notification settings - Fork 225
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fc9170d
commit afb02c8
Showing
1 changed file
with
128 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
use std::collections::HashMap; | ||
|
||
extern crate log; | ||
|
||
use martin::dev; | ||
use martin::source::{Source, Xyz}; | ||
use martin::table_source::get_table_sources; | ||
|
||
fn init() { | ||
let _ = env_logger::builder().is_test(true).try_init(); | ||
} | ||
|
||
#[actix_rt::test] | ||
async fn test_get_table_sources_ok() { | ||
init(); | ||
|
||
let mut connection = dev::make_pool().get().unwrap(); | ||
let table_sources = get_table_sources(&mut connection).unwrap(); | ||
|
||
log::info!("table_sources = {:#?}", table_sources); | ||
|
||
assert!(!table_sources.is_empty()); | ||
assert!(table_sources.contains_key("public.table_source")); | ||
|
||
let table_source = table_sources.get("public.table_source").unwrap(); | ||
assert_eq!(table_source.schema, "public"); | ||
assert_eq!(table_source.table, "table_source"); | ||
assert_eq!(table_source.srid, 4326); | ||
assert_eq!(table_source.geometry_column, "geom"); | ||
assert_eq!(table_source.id_column, None); | ||
assert_eq!(table_source.minzoom, None); | ||
assert_eq!(table_source.maxzoom, None); | ||
assert_eq!(table_source.bounds, Some(vec![-2.0, 0.0, 3.0, 3.0,])); | ||
assert_eq!(table_source.extent, Some(4096)); | ||
assert_eq!(table_source.buffer, Some(64)); | ||
assert_eq!(table_source.clip_geom, Some(true)); | ||
assert_eq!(table_source.geometry_type, Some("GEOMETRY".to_owned())); | ||
|
||
let mut properties = HashMap::new(); | ||
properties.insert("gid".to_owned(), "int4".to_owned()); | ||
assert_eq!(table_source.properties, properties); | ||
} | ||
|
||
#[actix_rt::test] | ||
async fn test_table_source_tilejson_ok() { | ||
init(); | ||
|
||
let mut connection = dev::make_pool().get().unwrap(); | ||
let table_sources = get_table_sources(&mut connection).unwrap(); | ||
|
||
let table_source = table_sources.get("public.table_source").unwrap(); | ||
let tilejson = table_source.get_tilejson().unwrap(); | ||
|
||
log::info!("tilejson = {:#?}", tilejson); | ||
|
||
assert_eq!(tilejson.tilejson, "2.2.0"); | ||
assert_eq!(tilejson.version, Some("1.0.0".to_owned())); | ||
assert_eq!(tilejson.name, Some("public.table_source".to_owned())); | ||
assert_eq!(tilejson.scheme, Some("xyz".to_owned())); | ||
assert_eq!(tilejson.minzoom, Some(0)); | ||
assert_eq!(tilejson.maxzoom, Some(30)); | ||
assert_eq!(tilejson.bounds, Some(vec![-2.0, 0.0, 3.0, 3.0,],)); | ||
assert!(tilejson.tiles.is_empty()); | ||
} | ||
|
||
#[actix_rt::test] | ||
async fn test_table_source_tile_ok() { | ||
init(); | ||
|
||
let mut connection = dev::make_pool().get().unwrap(); | ||
let table_sources = get_table_sources(&mut connection).unwrap(); | ||
|
||
let table_source = table_sources.get("public.table_source").unwrap(); | ||
let tile = table_source | ||
.get_tile(&mut connection, &Xyz { x: 0, y: 0, z: 0 }, &None) | ||
.unwrap(); | ||
|
||
assert!(!tile.is_empty()); | ||
} | ||
|
||
#[actix_rt::test] | ||
async fn test_table_source_srid_ok() { | ||
init(); | ||
|
||
let mut connection = dev::make_pool().get().unwrap(); | ||
let table_sources = get_table_sources(&mut connection).unwrap(); | ||
|
||
assert!(table_sources.contains_key("public.points1")); | ||
let points1 = table_sources.get("public.points1").unwrap(); | ||
assert_eq!(points1.srid, 4326); | ||
|
||
assert!(table_sources.contains_key("public.points2")); | ||
let points2 = table_sources.get("public.points2").unwrap(); | ||
assert_eq!(points2.srid, 4326); | ||
|
||
assert!(table_sources.contains_key("public.points3857")); | ||
let points3857 = table_sources.get("public.points3857").unwrap(); | ||
assert_eq!(points3857.srid, 3857); | ||
} | ||
|
||
#[actix_rt::test] | ||
async fn test_table_source_multiple_geom_ok() { | ||
init(); | ||
|
||
let mut connection = dev::make_pool().get().unwrap(); | ||
let table_sources = get_table_sources(&mut connection).unwrap(); | ||
|
||
assert!(table_sources.contains_key("public.table_source_multiple_geom")); | ||
let table_source_multiple_geom = table_sources | ||
.get("public.table_source_multiple_geom") | ||
.unwrap(); | ||
|
||
assert_eq!(table_source_multiple_geom.geometry_column, "geom1"); | ||
|
||
assert!(table_sources.contains_key("public.table_source_multiple_geom.geom1")); | ||
let table_source_multiple_geom1 = table_sources | ||
.get("public.table_source_multiple_geom.geom1") | ||
.unwrap(); | ||
|
||
assert_eq!(table_source_multiple_geom1.geometry_column, "geom1"); | ||
|
||
assert!(table_sources.contains_key("public.table_source_multiple_geom.geom2")); | ||
let table_source_multiple_geom2 = table_sources | ||
.get("public.table_source_multiple_geom.geom2") | ||
.unwrap(); | ||
|
||
assert_eq!(table_source_multiple_geom2.geometry_column, "geom2"); | ||
} |