mirror of
https://github.com/maplibre/martin.git
synced 2024-12-19 04:41:46 +03:00
test: add sources_not_found_test
This commit is contained in:
parent
0a4adbbdc5
commit
ccc986d037
21
.travis.yml
21
.travis.yml
@ -5,27 +5,26 @@ sudo: required
|
||||
|
||||
branches:
|
||||
except:
|
||||
- "/^v[0-9]/"
|
||||
- "/^v[0-9]/"
|
||||
|
||||
services:
|
||||
- postgresql
|
||||
- postgresql
|
||||
|
||||
addons:
|
||||
postgresql: 9.6
|
||||
|
||||
env:
|
||||
- DATABASE_URL=postgres://postgres@localhost/test
|
||||
- DATABASE_URL=postgres://postgres@localhost/test
|
||||
|
||||
before_script:
|
||||
- sudo apt-get -qq update
|
||||
- sudo apt-get install -y postgresql-9.6-postgis-2.4
|
||||
- psql -U postgres -c 'create database test'
|
||||
- psql -U postgres -d test -c 'create extension postgis'
|
||||
# - psql -U postgres -d test -f tests/fixtures/points.sql
|
||||
- sudo apt-get -qq update
|
||||
- sudo apt-get install -y postgresql-9.6-postgis-2.4
|
||||
- psql -U postgres -c 'create database test'
|
||||
- psql -U postgres -d test -c 'create extension postgis'
|
||||
- psql -U postgres -d test -f tests/fixtures/points.sql
|
||||
|
||||
script:
|
||||
- true
|
||||
# - cargo test --verbose --all
|
||||
- cargo test --verbose --all
|
||||
|
||||
deploy:
|
||||
provider: releases
|
||||
@ -35,4 +34,4 @@ deploy:
|
||||
file: "martin-${TRAVIS_TAG}-${TRAVIS_OS_NAME}.*"
|
||||
skip_cleanup: true
|
||||
on:
|
||||
tags: true
|
||||
tags: true
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
[![Build Status](https://travis-ci.org/urbica/martin.svg?branch=master)](https://travis-ci.org/urbica/martin)
|
||||
|
||||
PostGIS [Mapbox Vector Tiles](https://github.com/mapbox/vector-tile-spec) server.
|
||||
Martin is a PostGIS [Mapbox Vector Tiles](https://github.com/mapbox/vector-tile-spec) server written in Rust using [Actix](https://github.com/actix/actix-web) web framework.
|
||||
|
||||
**Warning: this is experimental**
|
||||
|
||||
|
87
src/app.rs
87
src/app.rs
@ -226,3 +226,90 @@ pub fn new(db_sync_arbiter: Addr<DbExecutor>, config: Config) -> App<State> {
|
||||
r.method(http::Method::GET).f(get_function_source_tile)
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
extern crate env_logger;
|
||||
|
||||
use super::super::db::setup_connection_pool;
|
||||
use super::super::db_executor::DbExecutor;
|
||||
use super::*;
|
||||
use actix::SyncArbiter;
|
||||
use actix_web::{http, test};
|
||||
use std::env;
|
||||
|
||||
fn build_test_server(
|
||||
table_sources: Option<TableSources>,
|
||||
function_sources: Option<FunctionSources>,
|
||||
) -> test::TestServer {
|
||||
test::TestServer::build_with_state(move || {
|
||||
let pool_size = 20;
|
||||
let conn_string: String = env::var("DATABASE_URL").unwrap();
|
||||
let pool = setup_connection_pool(&conn_string, pool_size).unwrap();
|
||||
let db_sync_arbiter = SyncArbiter::start(3, move || DbExecutor(pool.clone()));
|
||||
|
||||
State {
|
||||
db: db_sync_arbiter,
|
||||
table_sources: table_sources.clone(),
|
||||
function_sources: function_sources.clone(),
|
||||
}
|
||||
}).start(|app| {
|
||||
app.resource("/index.json", |r| {
|
||||
r.method(http::Method::GET).f(get_table_sources)
|
||||
}).resource("/{source_id}.json", |r| {
|
||||
r.method(http::Method::GET).f(get_table_source)
|
||||
})
|
||||
.resource("/{source_id}/{z}/{x}/{y}.pbf", |r| {
|
||||
r.method(http::Method::GET).f(get_table_source_tile)
|
||||
})
|
||||
.resource("/rpc/index.json", |r| {
|
||||
r.method(http::Method::GET).f(get_function_sources)
|
||||
})
|
||||
.resource("/rpc/{source_id}.json", |r| {
|
||||
r.method(http::Method::GET).f(get_function_source)
|
||||
})
|
||||
.resource("/rpc/{source_id}/{z}/{x}/{y}.pbf", |r| {
|
||||
r.method(http::Method::GET).f(get_function_source_tile)
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sources_not_found_test() {
|
||||
let mut srv = build_test_server(None, None);
|
||||
|
||||
// test table sources
|
||||
let request = srv
|
||||
.client(http::Method::GET, "/index.json")
|
||||
.finish()
|
||||
.unwrap();
|
||||
|
||||
let response = srv.execute(request.send()).unwrap();
|
||||
assert_eq!(response.status().as_u16(), 404);
|
||||
|
||||
let request = srv
|
||||
.client(http::Method::GET, "/public.points.json")
|
||||
.finish()
|
||||
.unwrap();
|
||||
|
||||
let response = srv.execute(request.send()).unwrap();
|
||||
assert_eq!(response.status().as_u16(), 404);
|
||||
|
||||
// test function sources
|
||||
let request = srv
|
||||
.client(http::Method::GET, "/rpc/index.json")
|
||||
.finish()
|
||||
.unwrap();
|
||||
|
||||
let response = srv.execute(request.send()).unwrap();
|
||||
assert_eq!(response.status().as_u16(), 404);
|
||||
|
||||
let request = srv
|
||||
.client(http::Method::GET, "/rpc/public.points.json")
|
||||
.finish()
|
||||
.unwrap();
|
||||
|
||||
let response = srv.execute(request.send()).unwrap();
|
||||
assert_eq!(response.status().as_u16(), 404);
|
||||
}
|
||||
}
|
||||
|
4
tests/fixtures/points.sql
vendored
Normal file
4
tests/fixtures/points.sql
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
DROP TABLE IF EXISTS points;
|
||||
CREATE TABLE points(gid serial PRIMARY KEY, geom geometry);
|
||||
INSERT INTO points(geom) values (GeomFromEWKT('SRID=4326;POINT(0 0)'));
|
||||
INSERT INTO points(geom) values (GeomFromEWKT('SRID=4326;POINT(-2 2)'));
|
Loading…
Reference in New Issue
Block a user