Skip to content

Commit cff21ad

Browse files
authored
Merge pull request #2382 from lonvia/fix-index-tests
Move and fix tests for unique and primary key id indexes
2 parents c1fea70 + 7faa7d6 commit cff21ad

File tree

3 files changed

+62
-34
lines changed

3 files changed

+62
-34
lines changed

tests/bdd/flex/lua-index-definitions.feature

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,3 +537,51 @@ Feature: Index definitions in Lua file
537537
schemaname = 'public' AND tablename = 'mytable' AND indexname LIKE '%node_id%'
538538
"""
539539

540+
Scenario: Create a unique id index when requested
541+
Given the input file 'liechtenstein-2013-08-03.osm.pbf'
542+
And the lua style
543+
"""
544+
local t = osm2pgsql.define_table({
545+
name = 'foo',
546+
ids = { type = 'node', id_column = 'node_id', create_index = 'unique' },
547+
columns = {}
548+
})
549+
550+
function osm2pgsql.process_node(object)
551+
t:insert({})
552+
end
553+
"""
554+
When running osm2pgsql flex
555+
Then table foo has 1562 rows
556+
And SELECT indexdef FROM pg_indexes WHERE tablename = 'foo'
557+
| indexdef@fullmatch |
558+
| CREATE UNIQUE INDEX .* USING .*\(node_id\) |
559+
And table pg_catalog.pg_index has 0 rows with condition
560+
"""
561+
indrelid = 'foo'::regclass and indisprimary
562+
"""
563+
564+
Scenario: Create a primary key id index when requested
565+
Given the input file 'liechtenstein-2013-08-03.osm.pbf'
566+
And the lua style
567+
"""
568+
local t = osm2pgsql.define_table({
569+
name = 'foo',
570+
ids = { type = 'node', id_column = 'node_id', create_index = 'primary_key' },
571+
columns = {}
572+
})
573+
574+
function osm2pgsql.process_node(object)
575+
t:insert({})
576+
end
577+
"""
578+
When running osm2pgsql flex
579+
Then table foo has 1562 rows
580+
And SELECT indexdef FROM pg_indexes WHERE tablename = 'foo'
581+
| indexdef@fullmatch |
582+
| CREATE UNIQUE INDEX .* USING .*\(node_id\) |
583+
And table pg_catalog.pg_index has 1 row with condition
584+
"""
585+
indrelid = 'foo'::regclass and indisprimary
586+
"""
587+

tests/bdd/flex/lua-table-definitions.feature

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -99,40 +99,6 @@ Feature: Table definitions in Lua file
9999
When running osm2pgsql flex
100100
Then table foo has 1562 rows
101101

102-
Scenario: Unique index is okay
103-
Given the input file 'liechtenstein-2013-08-03.osm.pbf'
104-
And the lua style
105-
"""
106-
local t = osm2pgsql.define_table({
107-
name = 'foo',
108-
ids = { type = 'node', id_column = 'node_id', index = 'unique' },
109-
columns = {}
110-
})
111-
112-
function osm2pgsql.process_node(object)
113-
t:insert({})
114-
end
115-
"""
116-
When running osm2pgsql flex
117-
Then table foo has 1562 rows
118-
119-
Scenario: Primary key is okay
120-
Given the input file 'liechtenstein-2013-08-03.osm.pbf'
121-
And the lua style
122-
"""
123-
local t = osm2pgsql.define_table({
124-
name = 'foo',
125-
ids = { type = 'node', id_column = 'node_id', index = 'primary_key' },
126-
columns = {}
127-
})
128-
129-
function osm2pgsql.process_node(object)
130-
t:insert({})
131-
end
132-
"""
133-
When running osm2pgsql flex
134-
Then table foo has 1562 rows
135-
136102
Scenario: Can not create two tables with the same name
137103
Given the input file 'liechtenstein-2013-08-03.osm.pbf'
138104
And the lua style

tests/bdd/steps/steps_db.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ def __init__(self, row, headings, factory):
153153
self.data.append(None)
154154
elif head.lower().startswith('st_astext('):
155155
self.data.append(DBValueGeometry(value, props, factory))
156+
elif props == 'fullmatch':
157+
self.data.append(DBValueRegex(value))
156158
else:
157159
self.data.append(str(value))
158160

@@ -234,3 +236,15 @@ def __eq__(self, other):
234236

235237
def __repr__(self):
236238
return repr(self.value)
239+
240+
241+
class DBValueRegex:
242+
243+
def __init__(self, value):
244+
self.value = str(value)
245+
246+
def __eq__(self, other):
247+
return re.fullmatch(str(other), self.value) is not None
248+
249+
def __repr__(self):
250+
return repr(self.value)

0 commit comments

Comments
 (0)