kopia lustrzana https://github.com/openmaptiles/openmaptiles
Framework for SQL-based unit tests for import and updates (#1249)
This PR adds the ability to create SQL tests that ensure that OSM data is properly imported and updated in the OpenMapTiles data schema. The tests work by injecting test OSM data and updates into the database and checking to ensure that the data is properly loaded into the database using standard SQL statements. With this framework in place, developers can now write small tests to inject known data into the database and ensure that imports and updates are working correctly. In addition to the framework, basic tests are provided for four layers. These initial tests are in no way comprehensive, but they provide a structure and framework for developers to add their own tests or expand the existing ones to cover more cases. Usage: `make clean && make sql-test` ## How it works The SQL tests consist of the following parts: 1. **Test import data**, located in `tests/import`. This test data is in the [OSM XML](https://wiki.openstreetmap.org/wiki/OSM_XML) format and contains the data that should be initially injected into the database. The files are numbered in order to ensure that each test data file contains OSM id numbers that are distinct from the other files. For example, the file starting with `100` will use node ids from 100000-199999, way ids from 1000-1999, and relation ids from 100-199. 1. **Test update data**, located in `tests/update`. This test data is in the [osmChange XML](https://wiki.openstreetmap.org/wiki/OsmChange) format, and contains the data that will be used to update the test import data (in order to verify that the update process is working correctly. These files are also numbered using the same scheme as the test import data. 1. **Import SQL test script**, located at `tests/test-post-import.sql`. This script is executed after the test import data has been injected, and runs SQL-based checks to ensure that the import data was properly imported. If there are failures in the tests, an entry will be added to the table `omt_test_failures`, with one record per error that occurs during the import process. A test failure will also fail the build. To inspect the test failure messages, run `make psql` and issue the comment `SELECT * FROM omt_test_failures`. 1. **Update SQL test script**, located at `tests/test-post-update.sql`. This script performs the same function as the import test script, except that it occurs after the test update data has been applied to the database. Note that script will only run if the import script passes all tests.pull/1266/head^2
rodzic
5833e8ce6e
commit
be37f3a565
|
@ -0,0 +1,22 @@
|
|||
# Workflow to run unit tests on OMT`s new Pull Requests and commits pushed into OMT repo
|
||||
|
||||
name: OpenMapTiles SQL Test CI
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ master, master-tools ]
|
||||
pull_request:
|
||||
|
||||
jobs:
|
||||
|
||||
unit_tests:
|
||||
name: Run unit test
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
|
||||
- name: Checkout the changes
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Run unit tests
|
||||
run: |
|
||||
make clean && make test-sql
|
|
@ -41,3 +41,7 @@ When you modify import data rules in `mapping.yaml` or `*.sql`, please update:
|
|||
5. check if OMT styles are affected by the PR and if there is a need for style updates
|
||||
|
||||
When you are making PR that adds new spatial features to OpenMapTiles schema, please make also PR for at least one of our GL styles to show it on the map. Visual check is crucial.
|
||||
|
||||
# Testing
|
||||
|
||||
It is recommended that you create a [unit test](TESTING.md) when modifying the behavior of the SQL layer. This will ensure that your changes are working as expected when importing or updating OSM data into an OpenMapTiles database.
|
||||
|
|
47
Makefile
47
Makefile
|
@ -184,6 +184,7 @@ Hints for developers:
|
|||
make generate-qa # statistics for a given layer's field
|
||||
make generate-tiles-pg # generate vector tiles based on .env settings using PostGIS ST_MVT()
|
||||
make generate-tiles # generate vector tiles based on .env settings using Mapnik (obsolete)
|
||||
make test-sql # run unit tests on the OpenMapTiles SQL schema
|
||||
cat .env # list PG database and MIN_ZOOM and MAX_ZOOM information
|
||||
cat quickstart.log # transcript of the last ./quickstart.sh run
|
||||
make help # help about available commands
|
||||
|
@ -276,9 +277,14 @@ ifeq (,$(wildcard build/sql/run_last.sql))
|
|||
endif
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
clean: clean-test-data
|
||||
rm -rf build
|
||||
|
||||
clean-test-data:
|
||||
rm -rf data/changes.state.txt
|
||||
rm -rf data/last.state.txt
|
||||
rm -rf data/changes.repl.json
|
||||
|
||||
.PHONY: destroy-db
|
||||
# TODO: Use https://stackoverflow.com/a/27852388/177275
|
||||
destroy-db: DC_PROJECT := $(shell echo $(DC_PROJECT) | tr A-Z a-z)
|
||||
|
@ -589,3 +595,42 @@ debug: ## Use this target when developing Makefile itself to verify loaded envi
|
|||
@echo BBOX = $(BBOX) , $$BBOX
|
||||
@echo MIN_ZOOM = $(MIN_ZOOM) , $$MIN_ZOOM
|
||||
@echo MAX_ZOOM = $(MAX_ZOOM) , $$MAX_ZOOM
|
||||
|
||||
build/import-tests.osm.pbf: init-dirs
|
||||
$(DOCKER_COMPOSE) $(DC_CONFIG_CACHE) run $(DC_OPTS_CACHE) openmaptiles-tools sh -c 'osmconvert tests/import/*.osm -o=build/import-tests.osm.pbf'
|
||||
|
||||
data/changes.state.txt:
|
||||
cp -f tests/changes.state.txt data/
|
||||
|
||||
data/last.state.txt:
|
||||
cp -f tests/last.state.txt data/
|
||||
|
||||
data/changes.repl.json:
|
||||
cp -f tests/changes.repl.json data/
|
||||
|
||||
data/changes.osc.gz: init-dirs
|
||||
@echo " UPDATE unit test data..."
|
||||
$(DOCKER_COMPOSE) $(DC_CONFIG_CACHE) run $(DC_OPTS_CACHE) openmaptiles-tools sh -c 'osmconvert tests/update/*.osc --merge-versions -o=data/changes.osc && gzip -f data/changes.osc'
|
||||
|
||||
test-sql: clean refresh-docker-images destroy-db start-db-nowait build/import-tests.osm.pbf data/changes.state.txt data/last.state.txt data/changes.repl.json build/mapping.yaml data/changes.osc.gz
|
||||
$(eval area := changes)
|
||||
|
||||
@echo "Load IMPORT test data"
|
||||
sed -ir "s/^[#]*\s*MAX_ZOOM=.*/MAX_ZOOM=14/" .env
|
||||
sed -ir "s/^[#]*\s*DIFF_MODE=.*/DIFF_MODE=false/" .env
|
||||
$(DOCKER_COMPOSE) $(DC_CONFIG_CACHE) run $(DC_OPTS_CACHE) openmaptiles-tools sh -c 'pgwait && import-osm build/import-tests.osm.pbf'
|
||||
|
||||
@echo "Apply OpenMapTiles SQL schema to test data @ Zoom 14..."
|
||||
$(DOCKER_COMPOSE) run $(DC_OPTS) openmaptiles-tools sh -c 'pgwait && import-sql' | \
|
||||
awk -v s=": WARNING:" '1{print; fflush()} $$0~s{print "\n*** WARNING detected, aborting"; exit(1)}' | \
|
||||
awk '1{print; fflush()} $$0~".*ERROR" {txt=$$0} END{ if(txt){print "\n*** ERROR detected, aborting:"; print txt; exit(1)} }'
|
||||
|
||||
@echo "Test SQL output for Import Test Data"
|
||||
$(DOCKER_COMPOSE) $(DC_CONFIG_CACHE) run $(DC_OPTS_CACHE) openmaptiles-tools sh -c 'pgwait && psql.sh < tests/test-post-import.sql'
|
||||
|
||||
@echo "Run UPDATE process on test data..."
|
||||
sed -ir "s/^[#]*\s*DIFF_MODE=.*/DIFF_MODE=true/" .env
|
||||
$(DOCKER_COMPOSE) $(DC_CONFIG_CACHE) run $(DC_OPTS_CACHE) openmaptiles-tools sh -c 'pgwait && import-diff'
|
||||
|
||||
@echo "Test SQL output for Update Test Data"
|
||||
$(DOCKER_COMPOSE) $(DC_CONFIG_CACHE) run $(DC_OPTS_CACHE) openmaptiles-tools sh -c 'pgwait && psql.sh < tests/test-post-update.sql'
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
|
||||
# OpenMapTiles SQL Testing
|
||||
|
||||
The OpenMapTiles SQL tests ensure that OSM data is properly imported and updated in the OpenMapTiles data schema. The tests work by injecting test OSM data into the database and checking to ensure that the data is properly reflected in the SQL output.
|
||||
|
||||
Usage:
|
||||
|
||||
`make clean && make sql-test`
|
||||
|
||||
## How it works
|
||||
|
||||
The SQL tests consist of the following parts:
|
||||
|
||||
1. **Test import data**, located in `tests/import`. This test data is in the [OSM XML](https://wiki.openstreetmap.org/wiki/OSM_XML) format and contains the data that should be initially injected into the database. The files are numbered in order to ensure that each test data file OSM id numbers that are unique from the other files. For example, the file starting with `100` will use node ids from 100000-199999, way ids from 1000-1999, and relation ids from 100-199.
|
||||
2. **Test update data**, located in `tests/update`. This test data is in the [osmChange XML](https://wiki.openstreetmap.org/wiki/OsmChange) format, and contains the data that will be used to update the test import data (in order to verify that the update process is working correctly. These files are also numbered using the same scheme as the test import data.
|
||||
3. **Import SQL test script**, located at `tests/test-post-import.sql`. This script is executed after the test import data has been injected, and runs SQL-based checks to ensure that the import data was properly imported. If there are failures in the tests, an entry will be added to the table `omt_test_failures`, with one record per error that occurs during the import process. A test failure will also fail the build. To inspect the test failure messages, run `make psql` and issue the comment `SELECT * FROM omt_test_failures`.
|
||||
4. **Update SQL test script**, located at `tests/test-post-update.sql`. This script performs the same function as the import test script, except that it occurs after the test update data has been applied to the database. Note that script will only run if the import script passes all tests.
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"replication_interval": "24h",
|
||||
"replication_url": "dummy"
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
#Sat Sep 25 23:23:00 UTC 2021
|
||||
sequenceNumber=4730693
|
||||
timestamp=2021-09-25T23\:22\:58Z
|
|
@ -0,0 +1,43 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<osm version="0.6" generator="Manual">
|
||||
<node id="100001" timestamp="2019-01-01T00:00:00Z" visible="true" version="1" lat="44.5" lon="-103.0" />
|
||||
<node id="100002" timestamp="2019-01-01T00:00:00Z" visible="true" version="1" lat="40.5" lon="-103.0" />
|
||||
<node id="100003" timestamp="2019-01-01T00:00:00Z" visible="true" version="1" lat="40.5" lon="-97.0" />
|
||||
<node id="100004" timestamp="2019-01-01T00:00:00Z" visible="true" version="1" lat="44.5" lon="-97.0" />
|
||||
<node id="100101" timestamp="2019-01-01T00:00:00Z" visible="true" version="1" lat="39.5" lon="-103.0" />
|
||||
<node id="100102" timestamp="2019-01-01T00:00:00Z" visible="true" version="1" lat="35.5" lon="-103.0" />
|
||||
<node id="100103" timestamp="2019-01-01T00:00:00Z" visible="true" version="1" lat="35.5" lon="-97.0" />
|
||||
<node id="100104" timestamp="2019-01-01T00:00:00Z" visible="true" version="1" lat="39.5" lon="-97.0" />
|
||||
<node id="100201" timestamp="2019-01-01T00:00:00Z" visible="true" version="1" lat="44.5" lon="-95.0" />
|
||||
<node id="100202" timestamp="2019-01-01T00:00:00Z" visible="true" version="1" lat="40.5" lon="-95.0" />
|
||||
<node id="100203" timestamp="2019-01-01T00:00:00Z" visible="true" version="1" lat="40.5" lon="-89.0" />
|
||||
<node id="100204" timestamp="2019-01-01T00:00:00Z" visible="true" version="1" lat="44.5" lon="-89.0" />
|
||||
<way id="1000" timestamp="2019-01-01T00:00:00Z" version="1" visible="true">
|
||||
<nd ref="100001" />
|
||||
<nd ref="100002" />
|
||||
<nd ref="100003" />
|
||||
<nd ref="100004" />
|
||||
<nd ref="100001" />
|
||||
<tag k="boundary" v="national_park" />
|
||||
<tag k="name" v="test-national-park" />
|
||||
</way>
|
||||
<way id="1001" timestamp="2019-01-01T00:00:00Z" version="1" visible="true">
|
||||
<nd ref="100101" />
|
||||
<nd ref="100102" />
|
||||
<nd ref="100103" />
|
||||
<nd ref="100104" />
|
||||
<nd ref="100101" />
|
||||
<tag k="leisure" v="nature_reserve" />
|
||||
<tag k="name" v="test-nature-reserve" />
|
||||
</way>
|
||||
<way id="1002" timestamp="2019-01-01T00:00:00Z" version="1" visible="true">
|
||||
<nd ref="100201" />
|
||||
<nd ref="100202" />
|
||||
<nd ref="100203" />
|
||||
<nd ref="100204" />
|
||||
<nd ref="100201" />
|
||||
<tag k="boundary" v="protected_area" />
|
||||
<tag k="name" v="test-protected-area" />
|
||||
<tag k="protect_class" v="5" />
|
||||
</way>
|
||||
</osm>
|
|
@ -0,0 +1,29 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<osm version="0.6" generator="Manual">
|
||||
<node id="200001" visible="true" timestamp="2019-01-01T00:00:00Z" version="1" lat="35.0" lon="-80.0" />
|
||||
<node id="200002" visible="true" timestamp="2019-01-01T00:00:00Z" version="1" lat="35.1" lon="-80.0" />
|
||||
<node id="200003" visible="true" timestamp="2019-01-01T00:00:00Z" version="1" lat="35.1" lon="-80.1" />
|
||||
<node id="200004" visible="true" timestamp="2019-01-01T00:00:00Z" version="1" lat="35.0" lon="-80.1" />
|
||||
<node id="200100" visible="true" timestamp="2019-01-01T00:00:00Z" version="1" lat="35.2" lon="-80.2">
|
||||
<tag k="aeroway" v="aerodrome"/>
|
||||
<tag k="ele" v="123"/>
|
||||
<tag k="faa" v="90F"/>
|
||||
<tag k="name" v="OpenMapTiles Airport"/>
|
||||
</node>
|
||||
<node id="200101" visible="true" timestamp="2019-01-01T00:00:00Z" version="1" lat="35.2" lon="-80.3">
|
||||
<tag k="aeroway" v="aerodrome"/>
|
||||
<tag k="ele" v="456"/>
|
||||
<tag k="faa" v="90G"/>
|
||||
<tag k="name" v="OpenMapTiles Airport #2"/>
|
||||
</node>
|
||||
<way id="2000" version="1" timestamp="2019-01-01T00:00:00Z" visible="true">
|
||||
<nd ref="200001" />
|
||||
<nd ref="200002" />
|
||||
<nd ref="200003" />
|
||||
<nd ref="200004" />
|
||||
<nd ref="200001" />
|
||||
<tag k="aerodrome" v="international"/>
|
||||
<tag k="aeroway" v="aerodrome"/>
|
||||
<tag k="name" v="test-airport"/>
|
||||
</way>
|
||||
</osm>
|
|
@ -0,0 +1,15 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<osm version="0.6" generator="Manual">
|
||||
<node id="300001" visible="true" timestamp="2019-01-01T00:00:00Z" version="1" lat="34.0" lon="-80.0" />
|
||||
<node id="300002" visible="true" timestamp="2019-01-01T00:00:00Z" version="1" lat="34.1" lon="-80.0" />
|
||||
<node id="300003" visible="true" timestamp="2019-01-01T00:00:00Z" version="1" lat="34.1" lon="-80.1" />
|
||||
<node id="300004" visible="true" timestamp="2019-01-01T00:00:00Z" version="1" lat="34.0" lon="-80.1" />
|
||||
<way id="3000" timestamp="2019-01-01T00:00:00Z" version="1" visible="true">
|
||||
<nd ref="300001" />
|
||||
<nd ref="300002" />
|
||||
<nd ref="300003" />
|
||||
<nd ref="300004" />
|
||||
<nd ref="300001" />
|
||||
<tag k="natural" v="wood"/>
|
||||
</way>
|
||||
</osm>
|
|
@ -0,0 +1,47 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<osm version="0.6" generator="Manual">
|
||||
<node id="400001" visible="true" timestamp="2019-01-01T00:00:00Z" version="1" lat="33.0" lon="-80.0" />
|
||||
<node id="400002" visible="true" timestamp="2019-01-01T00:00:00Z" version="1" lat="33.1" lon="-80.0" />
|
||||
<node id="400003" visible="true" timestamp="2019-01-01T00:00:00Z" version="1" lat="33.1" lon="-80.1" />
|
||||
<node id="400004" visible="true" timestamp="2019-01-01T00:00:00Z" version="1" lat="33.0" lon="-80.1" />
|
||||
|
||||
<node id="400005" visible="true" timestamp="2019-01-01T00:00:00Z" version="1" lat="32.0" lon="-79.0" />
|
||||
<node id="400006" visible="true" timestamp="2019-01-01T00:00:00Z" version="1" lat="34.0" lon="-79.0" />
|
||||
<node id="400007" visible="true" timestamp="2019-01-01T00:00:00Z" version="1" lat="34.0" lon="-81.0" />
|
||||
<node id="400008" visible="true" timestamp="2019-01-01T00:00:00Z" version="1" lat="32.0" lon="-81.0" />
|
||||
<way id="4000" version="1" timestamp="2019-01-01T00:00:00Z" visible="true">
|
||||
<nd ref="400001" />
|
||||
<nd ref="400002" />
|
||||
<nd ref="400003" />
|
||||
<nd ref="400004" />
|
||||
<nd ref="400001" />
|
||||
</way>
|
||||
<way id="4001" version="1" timestamp="2019-01-01T00:00:00Z" visible="true">
|
||||
<nd ref="400005" />
|
||||
<nd ref="400006" />
|
||||
<nd ref="400007" />
|
||||
<nd ref="400008" />
|
||||
</way>
|
||||
<way id="4002" version="1" timestamp="2019-01-01T00:00:00Z" visible="true">
|
||||
<nd ref="400005" />
|
||||
<nd ref="400008" />
|
||||
<tag k="boundary" v="maritime"/>
|
||||
</way>
|
||||
<relation id="400" visible="true" timestamp="2019-01-01T00:00:00Z" version="1" changeset="1" user="u" uid="1">
|
||||
<member type="way" ref="4000" role="outer"/>
|
||||
<tag k="admin_level" v="8"/>
|
||||
<tag k="boundary" v="administrative"/>
|
||||
<tag k="name" v="OpenMapTiles City"/>
|
||||
<tag k="place" v="city"/>
|
||||
<tag k="type" v="boundary"/>
|
||||
</relation>
|
||||
<relation id="401" visible="true" timestamp="2019-01-01T00:00:00Z" version="1" changeset="1" user="u" uid="1">
|
||||
<member type="way" ref="4000" role="inner"/>
|
||||
<member type="way" ref="4001" role="outer"/>
|
||||
<member type="way" ref="4002" role="outer"/>
|
||||
<tag k="admin_level" v="2"/>
|
||||
<tag k="boundary" v="administrative"/>
|
||||
<tag k="name" v="OpenMapTiles Nation"/>
|
||||
<tag k="type" v="boundary"/>
|
||||
</relation>
|
||||
</osm>
|
|
@ -0,0 +1,3 @@
|
|||
#Sat Sep 25 23:23:00 UTC 2021
|
||||
sequenceNumber=4730692
|
||||
timestamp=2021-09-25T23\:21\:58Z
|
|
@ -0,0 +1,88 @@
|
|||
-- Store test results
|
||||
|
||||
DROP TABLE IF EXISTS omt_test_failures;
|
||||
CREATE TABLE omt_test_failures(
|
||||
test_id integer,
|
||||
test_type varchar(6),
|
||||
error_message text
|
||||
);
|
||||
|
||||
-- Checks to ensure that test data was imported correctly
|
||||
DO $$
|
||||
|
||||
DECLARE
|
||||
cnt integer;
|
||||
|
||||
BEGIN
|
||||
|
||||
-- Test 100
|
||||
SELECT COUNT(*) INTO cnt FROM osm_park_polygon;
|
||||
IF cnt <> 3 THEN
|
||||
INSERT INTO omt_test_failures VALUES(100, 'import', 'osm_park_polygon expected 3, got ' || cnt);
|
||||
END IF;
|
||||
|
||||
SELECT COUNT(*) INTO cnt FROM osm_park_polygon_gen_z5;
|
||||
IF cnt <> 3 THEN
|
||||
INSERT INTO omt_test_failures VALUES(100, 'import', 'osm_park_polygon_gen_z5 expected 3, got ' || cnt);
|
||||
END IF;
|
||||
|
||||
SELECT COUNT(*) INTO cnt FROM osm_park_polygon_gen_z5 WHERE leisure='nature_reserve';
|
||||
IF cnt <> 1 THEN
|
||||
INSERT INTO omt_test_failures VALUES(100, 'import', 'osm_park_polygon_gen_z5 nature_reserve expected 1, got ' || cnt);
|
||||
END IF;
|
||||
|
||||
SELECT COUNT(*) INTO cnt FROM osm_park_polygon_gen_z5 WHERE boundary='protected_area';
|
||||
IF cnt <> 1 THEN
|
||||
INSERT INTO omt_test_failures VALUES(100, 'import', 'osm_park_polygon_gen_z5 protected_area expected 1, got ' || cnt);
|
||||
END IF;
|
||||
|
||||
SELECT COUNT(*) INTO cnt FROM osm_park_polygon_gen_z5 WHERE boundary='national_park';
|
||||
IF cnt <> 1 THEN
|
||||
INSERT INTO omt_test_failures VALUES(100, 'import', 'osm_park_polygon_gen_z5 national_park expected 1, got ' || cnt);
|
||||
END IF;
|
||||
|
||||
-- Test 200
|
||||
SELECT COUNT(*) INTO cnt FROM osm_aerodrome_label_point;
|
||||
IF cnt <> 3 THEN
|
||||
INSERT INTO omt_test_failures VALUES(200, 'import', 'osm_aerodrome_label expected 3, got ' || cnt);
|
||||
END IF;
|
||||
|
||||
SELECT COUNT(*) INTO cnt FROM osm_aerodrome_label_point WHERE ele=123;
|
||||
IF cnt <> 1 THEN
|
||||
INSERT INTO omt_test_failures VALUES(200, 'import', 'osm_aerodrome_label ele=123 expected 1, got ' || cnt);
|
||||
END IF;
|
||||
|
||||
-- Test 300
|
||||
SELECT COUNT(*) INTO cnt FROM osm_landcover_polygon WHERE mapping_key='natural' AND subclass='wood';
|
||||
IF cnt <> 1 THEN
|
||||
INSERT INTO omt_test_failures VALUES(300, 'import', 'osm_landcover_polygon natural=wood expected 1, got ' || cnt);
|
||||
END IF;
|
||||
|
||||
-- Test 400
|
||||
SELECT COUNT(DISTINCT relation_id) INTO cnt FROM osm_border_linestring WHERE admin_level=8;
|
||||
IF cnt <> 1 THEN
|
||||
INSERT INTO omt_test_failures VALUES(400, 'update', 'osm_border_linestring city count expected 1, got ' || cnt);
|
||||
END IF;
|
||||
|
||||
SELECT COUNT(DISTINCT relation_id) INTO cnt FROM osm_border_linestring WHERE admin_level=2;
|
||||
IF cnt <> 1 THEN
|
||||
INSERT INTO omt_test_failures VALUES(400, 'update', 'osm_border_linestring country count expected 1, got ' || cnt);
|
||||
END IF;
|
||||
|
||||
END;
|
||||
|
||||
$$
|
||||
LANGUAGE plpgsql;
|
||||
|
||||
DO $$
|
||||
|
||||
DECLARE
|
||||
cnt integer;
|
||||
BEGIN
|
||||
SELECT COUNT(*) INTO cnt FROM omt_test_failures;
|
||||
IF cnt > 0 THEN
|
||||
RAISE '% unit test(s) failed on imports. Details can be found in table omt_test_failures.', cnt USING ERRCODE = '0Z000';
|
||||
END IF;
|
||||
END;
|
||||
|
||||
$$;
|
|
@ -0,0 +1,67 @@
|
|||
-- Checks to ensure that test data was imported correctly
|
||||
DO $$
|
||||
|
||||
DECLARE
|
||||
cnt integer;
|
||||
|
||||
BEGIN
|
||||
|
||||
-- Clear prior results
|
||||
DELETE FROM omt_test_failures WHERE test_type='update';
|
||||
|
||||
-- Test 100: Verify re-tag of national_park to protected_area worked
|
||||
SELECT COUNT(*) INTO cnt FROM osm_park_polygon_gen_z5 WHERE boundary='national_park';
|
||||
IF cnt <> 0 THEN
|
||||
INSERT INTO omt_test_failures VALUES(100, 'update', 'osm_park_polygon_gen_z5 national_park expected 0, got ' || cnt);
|
||||
END IF;
|
||||
|
||||
SELECT COUNT(*) INTO cnt FROM osm_park_polygon_gen_z5 WHERE boundary='protected_area';
|
||||
IF cnt <> 2 THEN
|
||||
INSERT INTO omt_test_failures VALUES(100, 'update', 'osm_park_polygon_gen_z5 protected_area expected 2, got ' || cnt);
|
||||
END IF;
|
||||
|
||||
-- Test 200: Verify aerodrome deleted and modified
|
||||
SELECT COUNT(*) INTO cnt FROM osm_aerodrome_label_point;
|
||||
IF cnt <> 2 THEN
|
||||
INSERT INTO omt_test_failures VALUES(200, 'update', 'osm_aerodrome_label_point expected 2, got ' || cnt);
|
||||
END IF;
|
||||
|
||||
SELECT COUNT(*) INTO cnt FROM osm_aerodrome_label_point WHERE icao='KOMT' AND ele='124' AND name='OpenMapTiles International Airport';
|
||||
IF cnt <> 1 THEN
|
||||
INSERT INTO omt_test_failures VALUES(200, 'update', 'osm_aerodrome_label_point failed to update attributes');
|
||||
END IF;
|
||||
|
||||
-- Test 300: Verify landuse modified
|
||||
SELECT COUNT(*) INTO cnt FROM osm_landcover_polygon WHERE mapping_key='natural' AND subclass='scrub';
|
||||
IF cnt <> 1 THEN
|
||||
INSERT INTO omt_test_failures VALUES(300, 'import', 'osm_landcover_polygon natural=scrub expected 1, got ' || cnt);
|
||||
END IF;
|
||||
|
||||
SELECT COUNT(*) INTO cnt FROM osm_landcover_polygon WHERE mapping_key='natural' AND subclass='wood';
|
||||
IF cnt <> 0 THEN
|
||||
INSERT INTO omt_test_failures VALUES(300, 'import', 'osm_landcover_polygon natural=wood expected 0, got ' || cnt);
|
||||
END IF;
|
||||
|
||||
-- Test 400: Verify new city added
|
||||
SELECT COUNT(DISTINCT relation_id) INTO cnt FROM osm_border_linestring WHERE admin_level=8;
|
||||
IF cnt <> 2 THEN
|
||||
INSERT INTO omt_test_failures VALUES(400, 'update', 'osm_border_linestring city count expected 2, got ' || cnt);
|
||||
END IF;
|
||||
|
||||
END;
|
||||
|
||||
$$;
|
||||
|
||||
|
||||
DO $$
|
||||
|
||||
DECLARE
|
||||
cnt integer;
|
||||
BEGIN
|
||||
SELECT COUNT(*) INTO cnt FROM omt_test_failures;
|
||||
IF cnt > 0 THEN
|
||||
RAISE '% unit test(s) failed on updates. Details can be found in table omt_test_failures.', cnt USING ERRCODE = '0Z000';
|
||||
END IF;
|
||||
END;
|
||||
|
||||
$$;
|
|
@ -0,0 +1,26 @@
|
|||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<osmChange version="0.6" generator="Manual" timestamp="2020-01-02T00:00:00Z">
|
||||
<!--
|
||||
Test 100: Park polygons
|
||||
Move geometry
|
||||
Change name
|
||||
-->
|
||||
<modify>
|
||||
<!-- Move polygon positions -->
|
||||
<node id="100001" version="2" timestamp="2020-01-01T00:00:00Z" uid="1" user="u" changeset="2" lat="44.6" lon="-103.1"/>
|
||||
<node id="100002" version="2" timestamp="2020-01-01T00:00:00Z" uid="1" user="u" changeset="2" lat="40.6" lon="-103.1"/>
|
||||
<node id="100003" version="2" timestamp="2020-01-01T00:00:00Z" uid="1" user="u" changeset="2" lat="40.6" lon="-97.1"/>
|
||||
<node id="100004" version="2" timestamp="2020-01-01T00:00:00Z" uid="1" user="u" changeset="2" lat="44.6" lon="-97.1"/>
|
||||
|
||||
<!-- Change polygon tags -->
|
||||
<way id="1000" version="2" timestamp="2020-01-01T00:00:00Z" uid="1" user="u" changeset="2">
|
||||
<nd ref="100001" />
|
||||
<nd ref="100002" />
|
||||
<nd ref="100003" />
|
||||
<nd ref="100004" />
|
||||
<nd ref="100001" />
|
||||
<tag k="boundary" v="protected_area" /> <!-- Change from national_park -->
|
||||
<tag k="name" v="update-protected-area" /> <!-- Change from test-national-park -->
|
||||
</way>
|
||||
</modify>
|
||||
</osmChange>
|
|
@ -0,0 +1,21 @@
|
|||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<osmChange version="0.6" generator="Manual" timestamp="2020-01-02T00:00:00Z">
|
||||
<!--
|
||||
Test 200: Airports
|
||||
Delete airport
|
||||
Change elevation
|
||||
Add ICAO tag
|
||||
Change name
|
||||
-->
|
||||
<modify>
|
||||
<node id="200100" visible="true" timestamp="2020-01-02T00:00:00Z" version="1" lat="35.2" lon="-80.2">
|
||||
<tag k="aeroway" v="aerodrome"/>
|
||||
<tag k="ele" v="124"/>
|
||||
<tag k="icao" v="KOMT"/>
|
||||
<tag k="name" v="OpenMapTiles International Airport"/>
|
||||
</node>
|
||||
</modify>
|
||||
<delete>
|
||||
<node id="200101" timestamp="2020-01-02T00:00:00Z" uid="1" user="u" changeset="2" />
|
||||
</delete>
|
||||
</osmChange>
|
|
@ -0,0 +1,17 @@
|
|||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<osmChange version="0.6" generator="Manual" timestamp="2020-01-02T00:00:00Z">
|
||||
<!--
|
||||
Test 300: Landcover
|
||||
Change type of land cover from wood to scrub
|
||||
-->
|
||||
<modify>
|
||||
<way id="3000" timestamp="2020-01-02T00:00:00Z" version="2">
|
||||
<nd ref="300001" />
|
||||
<nd ref="300002" />
|
||||
<nd ref="300003" />
|
||||
<nd ref="300004" />
|
||||
<nd ref="300001" />
|
||||
<tag k="natural" v="scrub"/>
|
||||
</way>
|
||||
</modify>
|
||||
</osmChange>
|
|
@ -0,0 +1,29 @@
|
|||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<osmChange version="0.6" generator="Manual" timestamp="2020-01-02T00:00:00Z">
|
||||
<!--
|
||||
Test 400: Boundaries
|
||||
Add new boundary
|
||||
-->
|
||||
<create>
|
||||
<!-- Add new adjacent rectangular boundary -->
|
||||
<node id="400009" version="1" timestamp="2019-01-01T00:00:00Z" uid="1" user="u" changeset="2" lat="32.0" lon="-82.0" />
|
||||
<node id="400010" version="1" timestamp="2019-01-01T00:00:00Z" uid="1" user="u" changeset="2" lat="34.0" lon="-82.0" />
|
||||
|
||||
<way id="4003" version="2" timestamp="2020-01-01T00:00:00Z" uid="1" user="u" changeset="2">
|
||||
<nd ref="400007" />
|
||||
<nd ref="400008" />
|
||||
<nd ref="400009" />
|
||||
<nd ref="400010" />
|
||||
<nd ref="400007" />
|
||||
</way>
|
||||
|
||||
<relation id="402" visible="true" timestamp="2019-01-01T00:00:00Z" version="1" changeset="1" user="u" uid="1">
|
||||
<member type="way" ref="4003" role="outer"/>
|
||||
<tag k="admin_level" v="8"/>
|
||||
<tag k="boundary" v="administrative"/>
|
||||
<tag k="name" v="OpenMapTiles Suburb"/>
|
||||
<tag k="place" v="suburb"/>
|
||||
<tag k="type" v="boundary"/>
|
||||
</relation>
|
||||
</create>
|
||||
</osmChange>
|
Ładowanie…
Reference in New Issue