<p></p>
<p>Maybe we could enhance the test framework a bit to provide some very basic mock object for the osm2pgsql functionality provided by osm2pgsql. I believe this isn't supported by tests.lua as of now.</p>
<p>(file osm2pgsql-mock.lua)</p>
<pre><code>local osm2pgsql = {}
local inspect = require('inspect')
result = {}
function osm2pgsql.define_table(o)
local mock_table = {}
mock_table.name = o.name
mock_table.ids = o.ids
mock_table.columns = o.columns
function mock_table.add_row(x, y)
-- print(inspect(x))
-- print(inspect(y))
result = y
end
return mock_table
end
function osm2pgsql.get_mock_result()
return result
end
return osm2pgsql
</code></pre>
<p>File test.lua:</p>
<pre><code>osm2pgsql = require 'osm2pgsql-mock'
require 'openstreetmap-carto'
print("Running tests...")
x = {}
x.tags = {}
x.tags["highway"] = "bus_stop"
x.tags["layer"] = "1"
osm2pgsql.process_node(x)
r = osm2pgsql.get_mock_result()
assert(r["highway"] == 'bus_stop')
print("Done...")
</code></pre>
<p>Executing test from command line:</p>
<pre><code>lua test.lua
Running tests...
Done...
</code></pre>
<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />You are receiving this because you are subscribed to this thread.<br />Reply to this email directly, <a href="https://github.com/openstreetmap/osm2pgsql/issues/1130#issuecomment-633292987">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/AA6353Q2WLV6QPTUHBR4J3DRTF7ARANCNFSM4MLPW2VQ">unsubscribe</a>.<img src="https://github.com/notifications/beacon/AA6353XH3WRPBXMAIQ64TILRTF7ARA5CNFSM4MLPW2V2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEW7UROY.gif" height="1" width="1" alt="" /></p>
<script type="application/ld+json">[
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"potentialAction": {
"@type": "ViewAction",
"target": "https://github.com/openstreetmap/osm2pgsql/issues/1130#issuecomment-633292987",
"url": "https://github.com/openstreetmap/osm2pgsql/issues/1130#issuecomment-633292987",
"name": "View Issue"
},
"description": "View this Issue on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
}
]</script>