Skip to content

Commit 96b6bd7

Browse files
committed
add tests for delete callback
1 parent 70ed61d commit 96b6bd7

File tree

1 file changed

+112
-0
lines changed

1 file changed

+112
-0
lines changed
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
Feature: Test for delete callbacks
2+
3+
Background:
4+
Given the input file 'liechtenstein-2013-08-03.osm.pbf'
5+
And the lua style
6+
"""
7+
local change = osm2pgsql.define_table{
8+
name = 'change',
9+
ids = {type = 'any', id_column = 'osm_id', type_column = 'osm_type'},
10+
columns = {
11+
{ column = 'extra', type = 'int' }
12+
}}
13+
14+
local function process_delete(object)
15+
change:insert{extra = object.version}
16+
end
17+
18+
osm2pgsql.delete_node = process_delete
19+
osm2pgsql.delete_way = process_delete
20+
osm2pgsql.delete_relation = process_delete
21+
"""
22+
When running osm2pgsql flex with parameters
23+
| --slim |
24+
25+
Then table change contains exactly
26+
| osm_type | osm_id |
27+
28+
Given the input file '008-ch.osc.gz'
29+
30+
Scenario: Delete callbacks are called
31+
When running osm2pgsql flex with parameters
32+
| --slim | -a |
33+
34+
Then SELECT osm_type, count(*), sum(extra) FROM change GROUP BY osm_type
35+
| osm_type | count | sum |
36+
| N | 16773 | 16779 |
37+
| W | 4 | 9 |
38+
| R | 1 | 3 |
39+
40+
When running osm2pgsql flex with parameters
41+
| --slim | -a |
42+
43+
Then SELECT osm_type, count(*), sum(osm_id) FROM change GROUP BY osm_type
44+
| osm_type | count | sum |
45+
| N | 16773 | 37856781001834 |
46+
| W | 4 | 350933407 |
47+
| R | 1 | 2871571 |
48+
49+
Scenario: No object payload is available
50+
Given the lua style
51+
"""
52+
local change = osm2pgsql.define_table{
53+
name = 'change',
54+
ids = {type = 'any', id_column = 'osm_id', type_column = 'osm_type'},
55+
columns = {
56+
{ column = 'extra', type = 'int' }
57+
}}
58+
59+
function osm2pgsql.delete_node(object)
60+
change:insert{extra = object.tags == nil and 1 or 0}
61+
end
62+
63+
function osm2pgsql.delete_way(object)
64+
change:insert{extra = object.nodes == nil and 1 or 0}
65+
end
66+
67+
function osm2pgsql.delete_relation(object)
68+
change:insert{extra = object.members == nil and 1 or 0}
69+
end
70+
71+
72+
"""
73+
When running osm2pgsql flex with parameters
74+
| --slim | -a |
75+
Then SELECT osm_type, count(*), sum(extra) FROM change GROUP BY osm_type
76+
| osm_type | count | sum |
77+
| N | 16773 | 16773 |
78+
| W | 4 | 4 |
79+
| R | 1 | 1 |
80+
81+
82+
Scenario: Geometries are not valid for deleted objects
83+
Given the lua style
84+
"""
85+
change = osm2pgsql.define_table{
86+
name = 'change',
87+
ids = {type = 'any', id_column = 'osm_id', type_column = 'osm_type'},
88+
columns = {
89+
{ column = 'extra', sql_type = 'int' }
90+
}}
91+
92+
function osm2pgsql.delete_node(object)
93+
change:insert{extra = object.as_point == nil and 1 or 0}
94+
end
95+
96+
function osm2pgsql.delete_way(object)
97+
change:insert{extra = object.as_linestring == nil and 1 or 0}
98+
end
99+
100+
function osm2pgsql.delete_relation(object)
101+
change:insert{extra = object.as_geometrycollection == nil and 1 or 0}
102+
end
103+
104+
105+
"""
106+
When running osm2pgsql flex with parameters
107+
| --slim | -a |
108+
Then SELECT osm_type, count(*), sum(extra) FROM change GROUP BY osm_type
109+
| osm_type | count | sum |
110+
| N | 16773 | 16773|
111+
| W | 4 | 4|
112+
| R | 1 | 1|

0 commit comments

Comments
 (0)