Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions tests/bdd/flex/lua-index-definitions.feature
Original file line number Diff line number Diff line change
Expand Up @@ -537,3 +537,51 @@ Feature: Index definitions in Lua file
schemaname = 'public' AND tablename = 'mytable' AND indexname LIKE '%node_id%'
"""

Scenario: Create a unique id index when requested
Given the input file 'liechtenstein-2013-08-03.osm.pbf'
And the lua style
"""
local t = osm2pgsql.define_table({
name = 'foo',
ids = { type = 'node', id_column = 'node_id', create_index = 'unique' },
columns = {}
})

function osm2pgsql.process_node(object)
t:insert({})
end
"""
When running osm2pgsql flex
Then table foo has 1562 rows
And SELECT indexdef FROM pg_indexes WHERE tablename = 'foo'
| indexdef@fullmatch |
| CREATE UNIQUE INDEX .* USING .*\(node_id\) |
And table pg_catalog.pg_index has 0 rows with condition
"""
indrelid = 'foo'::regclass and indisprimary
"""

Scenario: Create a primary key id index when requested
Given the input file 'liechtenstein-2013-08-03.osm.pbf'
And the lua style
"""
local t = osm2pgsql.define_table({
name = 'foo',
ids = { type = 'node', id_column = 'node_id', create_index = 'primary_key' },
columns = {}
})

function osm2pgsql.process_node(object)
t:insert({})
end
"""
When running osm2pgsql flex
Then table foo has 1562 rows
And SELECT indexdef FROM pg_indexes WHERE tablename = 'foo'
| indexdef@fullmatch |
| CREATE UNIQUE INDEX .* USING .*\(node_id\) |
And table pg_catalog.pg_index has 1 row with condition
"""
indrelid = 'foo'::regclass and indisprimary
"""

34 changes: 0 additions & 34 deletions tests/bdd/flex/lua-table-definitions.feature
Original file line number Diff line number Diff line change
Expand Up @@ -99,40 +99,6 @@ Feature: Table definitions in Lua file
When running osm2pgsql flex
Then table foo has 1562 rows

Scenario: Unique index is okay
Given the input file 'liechtenstein-2013-08-03.osm.pbf'
And the lua style
"""
local t = osm2pgsql.define_table({
name = 'foo',
ids = { type = 'node', id_column = 'node_id', index = 'unique' },
columns = {}
})

function osm2pgsql.process_node(object)
t:insert({})
end
"""
When running osm2pgsql flex
Then table foo has 1562 rows

Scenario: Primary key is okay
Given the input file 'liechtenstein-2013-08-03.osm.pbf'
And the lua style
"""
local t = osm2pgsql.define_table({
name = 'foo',
ids = { type = 'node', id_column = 'node_id', index = 'primary_key' },
columns = {}
})

function osm2pgsql.process_node(object)
t:insert({})
end
"""
When running osm2pgsql flex
Then table foo has 1562 rows

Scenario: Can not create two tables with the same name
Given the input file 'liechtenstein-2013-08-03.osm.pbf'
And the lua style
Expand Down
14 changes: 14 additions & 0 deletions tests/bdd/steps/steps_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ def __init__(self, row, headings, factory):
self.data.append(None)
elif head.lower().startswith('st_astext('):
self.data.append(DBValueGeometry(value, props, factory))
elif props == 'fullmatch':
self.data.append(DBValueRegex(value))
else:
self.data.append(str(value))

Expand Down Expand Up @@ -234,3 +236,15 @@ def __eq__(self, other):

def __repr__(self):
return repr(self.value)


class DBValueRegex:

def __init__(self, value):
self.value = str(value)

def __eq__(self, other):
return re.fullmatch(str(other), self.value) is not None

def __repr__(self):
return repr(self.value)
Loading