diff --git a/.travis.yml b/.travis.yml index f433fea5..f8032a1c 100644 --- a/.travis.yml +++ b/.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 \ No newline at end of file + tags: true diff --git a/README.md b/README.md index fa05e061..223d2ce0 100755 --- a/README.md +++ b/README.md @@ -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** diff --git a/src/app.rs b/src/app.rs index a7872c2c..e3e38b5c 100755 --- a/src/app.rs +++ b/src/app.rs @@ -226,3 +226,90 @@ pub fn new(db_sync_arbiter: Addr, config: Config) -> App { 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, + function_sources: Option, + ) -> 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); + } +} diff --git a/tests/fixtures/points.sql b/tests/fixtures/points.sql new file mode 100644 index 00000000..0cadd946 --- /dev/null +++ b/tests/fixtures/points.sql @@ -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)'));