mirror of
https://github.com/osm2pgsql-dev/osm2pgsql.git
synced 2025-08-16 15:04:27 +00:00
Basic test of osm2pgsql-replication
This commit is contained in:
@ -32,7 +32,7 @@ runs:
|
||||
python3-psycopg2 \
|
||||
python3-setuptools \
|
||||
zlib1g-dev
|
||||
pip3 install behave
|
||||
pip3 install behave osmium
|
||||
if [ "$CC" = clang-8 ]; then sudo apt-get install -yq --no-install-suggests --no-install-recommends clang-8; fi
|
||||
shell: bash
|
||||
|
||||
|
2
.github/actions/win-install/action.yml
vendored
2
.github/actions/win-install/action.yml
vendored
@ -19,5 +19,5 @@ runs:
|
||||
zlib:x64-windows
|
||||
shell: bash
|
||||
- name: Install psycopg2 and behave
|
||||
run: python -m pip install psycopg2 behave
|
||||
run: python -m pip install psycopg2 behave osmium
|
||||
shell: bash
|
||||
|
2
.github/workflows/ci.yml
vendored
2
.github/workflows/ci.yml
vendored
@ -15,7 +15,7 @@ jobs:
|
||||
- name: Install prerequisites
|
||||
run: |
|
||||
brew install lua boost postgis pandoc cimg potrace
|
||||
pip3 install psycopg2 behave
|
||||
pip3 install psycopg2 behave osmium
|
||||
pg_ctl -D /usr/local/var/postgres init
|
||||
pg_ctl -D /usr/local/var/postgres start
|
||||
# Work around homebrew postgresql installation screw-up, see
|
||||
|
32
tests/bdd/command-line/replication.feature
Normal file
32
tests/bdd/command-line/replication.feature
Normal file
@ -0,0 +1,32 @@
|
||||
Feature: Tests for the osm2pgsql-replication script
|
||||
|
||||
Scenario: Replication can be initialised
|
||||
|
||||
Given the OSM data
|
||||
"""
|
||||
n34 Tamenity=restaurant x77 y45.3
|
||||
"""
|
||||
When running osm2pgsql pgsql with parameters
|
||||
| --slim |
|
||||
|
||||
And running osm2pgsql-replication
|
||||
| init | --osm-file={TEST_DATA_DIR}/liechtenstein-2013-08-03.osm.pbf |
|
||||
|
||||
Then table planet_osm_replication_status has 1 row
|
||||
|
||||
Scenario: Replication can be initialised in different schema
|
||||
|
||||
Given the database schema foobar
|
||||
And the OSM data
|
||||
"""
|
||||
n34 Tamenity=restaurant x77 y45.3
|
||||
"""
|
||||
When running osm2pgsql pgsql with parameters
|
||||
| --slim |
|
||||
|
||||
And running osm2pgsql-replication
|
||||
| init |
|
||||
| --osm-file={TEST_DATA_DIR}/liechtenstein-2013-08-03.osm.pbf |
|
||||
| --middle-schema=foobar |
|
||||
|
||||
Then table foobar.planet_osm_replication_status has 1 row
|
@ -23,6 +23,7 @@ TEST_BASE_DIR = (Path(__file__) / '..' / '..').resolve()
|
||||
# behave -DBINARY=/tmp/my-builddir/osm2pgsql -DKEEP_TEST_DB
|
||||
USER_CONFIG = {
|
||||
'BINARY': (TEST_BASE_DIR / '..' / 'build' / 'osm2pgsql').resolve(),
|
||||
'REPLICATION_SCRIPT': (TEST_BASE_DIR / '..' / 'scripts' / 'osm2pgsql-replication').resolve(),
|
||||
'TEST_DATA_DIR': TEST_BASE_DIR / 'data',
|
||||
'SRC_DIR': (TEST_BASE_DIR / '..').resolve(),
|
||||
'KEEP_TEST_DB': False,
|
||||
|
@ -9,6 +9,7 @@ Steps for executing osm2pgsql.
|
||||
"""
|
||||
from io import StringIO
|
||||
from pathlib import Path
|
||||
import os
|
||||
import subprocess
|
||||
|
||||
def get_import_file(context):
|
||||
@ -38,8 +39,9 @@ def run_osm2pgsql(context, output):
|
||||
cmdline.extend(('-O', output))
|
||||
cmdline.extend(context.osm2pgsql_params)
|
||||
|
||||
# convert table items to CLI arguments and inject constants to placeholders
|
||||
if context.table:
|
||||
cmdline.extend(f for f in context.table.headings if f)
|
||||
cmdline.extend(f.format(**context.config.userdata) for f in context.table.headings if f)
|
||||
for row in context.table:
|
||||
cmdline.extend(f.format(**context.config.userdata) for f in row if f)
|
||||
|
||||
@ -72,6 +74,31 @@ def run_osm2pgsql(context, output):
|
||||
|
||||
return proc.returncode
|
||||
|
||||
|
||||
def run_osm2pgsql_replication(context):
|
||||
cmdline = [str(Path(context.config.userdata['REPLICATION_SCRIPT']).resolve())]
|
||||
# convert table items to CLI arguments and inject constants to placeholders
|
||||
if context.table:
|
||||
cmdline.extend(f.format(**context.config.userdata) for f in context.table.headings if f)
|
||||
for row in context.table:
|
||||
cmdline.extend(f.format(**context.config.userdata) for f in row if f)
|
||||
|
||||
if '-d' not in cmdline and '--database' not in cmdline:
|
||||
cmdline.extend(('-d', context.config.userdata['TEST_DB']))
|
||||
|
||||
# on Windows execute script directly with python, because shebang is not recognised
|
||||
if os.name == 'nt':
|
||||
cmdline.insert(0, "python")
|
||||
|
||||
proc = subprocess.Popen(cmdline, cwd=str(context.workdir),
|
||||
stdin=subprocess.PIPE,
|
||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
|
||||
_, errs = proc.communicate()
|
||||
|
||||
return proc.returncode, errs.decode('utf-8')
|
||||
|
||||
|
||||
@given("no lua tagtransform")
|
||||
def do_not_setup_tagtransform(context):
|
||||
pass
|
||||
@ -106,7 +133,7 @@ def setup_style_file(context, style):
|
||||
|
||||
|
||||
@when("running osm2pgsql (?P<output>\w+)(?: with parameters)?")
|
||||
def execute_osm2pgsql_sucessfully(context, output):
|
||||
def execute_osm2pgsql_successfully(context, output):
|
||||
returncode = run_osm2pgsql(context, output)
|
||||
|
||||
if context.scenario.status == "skipped":
|
||||
@ -127,6 +154,15 @@ def execute_osm2pgsql_with_failure(context, output):
|
||||
assert returncode != 0, "osm2pgsql unexpectedly succeeded"
|
||||
|
||||
|
||||
@when("running osm2pgsql-replication")
|
||||
def execute_osm2pgsql_replication_successfully(context):
|
||||
returncode, errs = run_osm2pgsql_replication(context)
|
||||
|
||||
assert returncode == 0,\
|
||||
f"osm2pgsql-replication failed with error code {returncode}.\n"\
|
||||
f"Errors:\n{errs}"
|
||||
|
||||
|
||||
@then("the (?P<kind>\w+) output contains")
|
||||
def check_program_output(context, kind):
|
||||
if kind == 'error':
|
||||
|
Binary file not shown.
Reference in New Issue
Block a user