2015-11-23 11:05:19 +03:00
|
|
|
package test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"database/sql"
|
2016-06-15 15:26:50 +03:00
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
2015-12-21 12:41:27 +03:00
|
|
|
"strings"
|
2015-11-23 11:05:19 +03:00
|
|
|
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/omniscale/imposm3/geom/geos"
|
|
|
|
)
|
|
|
|
|
|
|
|
const RelOffset = -1e17
|
|
|
|
|
2018-06-05 22:04:02 +03:00
|
|
|
func TestSingleTable(t *testing.T) {
|
|
|
|
if testing.Short() {
|
|
|
|
t.Skip("system test skipped with -test.short")
|
2015-11-23 11:05:19 +03:00
|
|
|
}
|
|
|
|
|
2018-06-05 22:04:02 +03:00
|
|
|
ts := importTestSuite{
|
|
|
|
name: "single_table",
|
2015-11-23 11:05:19 +03:00
|
|
|
}
|
|
|
|
|
2018-06-05 22:04:02 +03:00
|
|
|
t.Run("Prepare", func(t *testing.T) {
|
|
|
|
var err error
|
|
|
|
|
|
|
|
ts.dir, err = ioutil.TempDir("", "imposm_test")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
ts.config = importConfig{
|
|
|
|
connection: "postgis://",
|
|
|
|
cacheDir: ts.dir,
|
|
|
|
osmFileName: "build/single_table.pbf",
|
|
|
|
mappingFileName: "single_table_mapping.json",
|
|
|
|
}
|
|
|
|
ts.g = geos.NewGeos()
|
|
|
|
|
|
|
|
ts.db, err = sql.Open("postgres", "sslmode=disable")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
ts.dropSchemas()
|
|
|
|
})
|
2015-11-23 11:05:19 +03:00
|
|
|
|
2018-06-05 22:04:02 +03:00
|
|
|
t.Run("Import", func(t *testing.T) {
|
|
|
|
if ts.tableExists(t, ts.dbschemaImport(), "osm_all") != false {
|
|
|
|
t.Fatalf("table osm_all exists in schema %s", ts.dbschemaImport())
|
|
|
|
}
|
|
|
|
ts.importOsm(t)
|
|
|
|
if ts.tableExists(t, ts.dbschemaImport(), "osm_all") != true {
|
|
|
|
t.Fatalf("table osm_all does not exists in schema %s", ts.dbschemaImport())
|
|
|
|
}
|
|
|
|
})
|
2015-11-23 11:05:19 +03:00
|
|
|
|
2018-06-05 22:04:02 +03:00
|
|
|
t.Run("Deploy", func(t *testing.T) {
|
|
|
|
ts.deployOsm(t)
|
|
|
|
if ts.tableExists(t, ts.dbschemaImport(), "osm_all") != false {
|
|
|
|
t.Fatalf("table osm_all exists in schema %s", ts.dbschemaImport())
|
|
|
|
}
|
|
|
|
if ts.tableExists(t, ts.dbschemaProduction(), "osm_all") != true {
|
|
|
|
t.Fatalf("table osm_all does not exists in schema %s", ts.dbschemaProduction())
|
|
|
|
}
|
2015-11-23 11:05:19 +03:00
|
|
|
})
|
|
|
|
|
2018-06-05 22:04:02 +03:00
|
|
|
t.Run("NonMappedNodeIsMissing", func(t *testing.T) {
|
|
|
|
// Node without mapped tags is missing.
|
|
|
|
cache := ts.cache(t)
|
|
|
|
defer cache.Close()
|
|
|
|
ts.assertCachedNode(t, cache, 10001)
|
2015-11-23 11:05:19 +03:00
|
|
|
|
2018-06-05 22:04:02 +03:00
|
|
|
ts.assertHstore(t, []checkElem{
|
|
|
|
{"osm_all", 10001, Missing, nil},
|
|
|
|
})
|
2015-11-23 11:05:19 +03:00
|
|
|
})
|
|
|
|
|
2018-06-05 22:04:02 +03:00
|
|
|
t.Run("MappedNode", func(t *testing.T) {
|
|
|
|
// Node is stored with all tags.
|
|
|
|
cache := ts.cache(t)
|
|
|
|
defer cache.Close()
|
|
|
|
ts.assertCachedNode(t, cache, 10002)
|
2015-12-21 12:41:27 +03:00
|
|
|
|
2018-06-05 22:04:02 +03:00
|
|
|
ts.assertHstore(t, []checkElem{
|
|
|
|
{"osm_all", 10002, "*", map[string]string{"random": "tag", "but": "mapped", "poi": "unicorn"}},
|
|
|
|
})
|
2015-11-23 11:05:19 +03:00
|
|
|
})
|
|
|
|
|
2018-06-05 22:04:02 +03:00
|
|
|
t.Run("NonMappedWayIsMissing", func(t *testing.T) {
|
|
|
|
// Way without mapped tags is missing.
|
|
|
|
cache := ts.cache(t)
|
|
|
|
defer cache.Close()
|
|
|
|
ts.assertCachedWay(t, cache, 20101)
|
|
|
|
ts.assertCachedWay(t, cache, 20102)
|
|
|
|
ts.assertCachedWay(t, cache, 20103)
|
|
|
|
|
|
|
|
ts.assertHstore(t, []checkElem{
|
|
|
|
{"osm_all", 20101, Missing, nil},
|
|
|
|
{"osm_all", 20102, Missing, nil},
|
|
|
|
{"osm_all", 20103, Missing, nil},
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("MappedWay", func(t *testing.T) {
|
|
|
|
// Way is stored with all tags.
|
|
|
|
cache := ts.cache(t)
|
|
|
|
defer cache.Close()
|
|
|
|
ts.assertCachedWay(t, cache, 20201)
|
2015-12-21 12:41:27 +03:00
|
|
|
|
2018-06-05 22:04:02 +03:00
|
|
|
ts.assertHstore(t, []checkElem{
|
|
|
|
{"osm_all", -20201, "*", map[string]string{"random": "tag", "highway": "yes"}},
|
|
|
|
})
|
2015-11-23 11:05:19 +03:00
|
|
|
})
|
|
|
|
|
2018-06-05 22:04:02 +03:00
|
|
|
t.Run("NonMappedClosedWayIsMissing", func(t *testing.T) {
|
|
|
|
// Closed way without mapped tags is missing.
|
|
|
|
cache := ts.cache(t)
|
|
|
|
defer cache.Close()
|
|
|
|
ts.assertCachedWay(t, cache, 20301)
|
|
|
|
ts.assertHstore(t, []checkElem{
|
|
|
|
{"osm_all", 20301, Missing, nil},
|
|
|
|
{"osm_all", -20301, Missing, nil},
|
|
|
|
})
|
2015-11-23 11:05:19 +03:00
|
|
|
})
|
|
|
|
|
2018-06-05 22:04:02 +03:00
|
|
|
t.Run("MappedClosedWay", func(t *testing.T) {
|
|
|
|
// Closed way is stored with all tags.
|
|
|
|
ts.assertHstore(t, []checkElem{
|
|
|
|
{"osm_all", -20401, "*", map[string]string{"random": "tag", "building": "yes"}},
|
|
|
|
})
|
2015-11-23 11:05:19 +03:00
|
|
|
})
|
|
|
|
|
2018-06-05 22:04:02 +03:00
|
|
|
t.Run("MappedClosedWayAreaYes", func(t *testing.T) {
|
|
|
|
// Closed way with area=yes is not stored as linestring.
|
|
|
|
ts.assertHstore(t, []checkElem{
|
|
|
|
{"osm_all", -20501, "*", map[string]string{"random": "tag", "landuse": "grass", "highway": "pedestrian", "area": "yes"}},
|
|
|
|
})
|
|
|
|
ts.assertGeomType(t, checkElem{"osm_all", -20501, "*", nil}, "Polygon")
|
2015-11-23 11:05:19 +03:00
|
|
|
})
|
|
|
|
|
2018-06-05 22:04:02 +03:00
|
|
|
t.Run("MappedClosedWayAreaNo", func(t *testing.T) {
|
|
|
|
// Closed way with area=no is not stored as polygon.
|
|
|
|
ts.assertHstore(t, []checkElem{
|
|
|
|
{"osm_all", -20502, "*", map[string]string{"random": "tag", "landuse": "grass", "highway": "pedestrian", "area": "no"}},
|
|
|
|
})
|
|
|
|
ts.assertGeomType(t, checkElem{"osm_all", -20502, "*", nil}, "LineString")
|
2015-11-23 11:05:19 +03:00
|
|
|
})
|
|
|
|
|
2018-06-05 22:04:02 +03:00
|
|
|
t.Run("MappedClosedWayWithoutArea", func(t *testing.T) {
|
|
|
|
// Closed way without area is stored as mapped (linestring and polygon).
|
2015-12-21 12:41:27 +03:00
|
|
|
|
2018-06-05 22:04:02 +03:00
|
|
|
rows := ts.queryRowsTags(t, "osm_all", -20601)
|
|
|
|
if len(rows) != 2 || strings.HasPrefix(rows[0].wkt, "LineString") || strings.HasPrefix(rows[1].wkt, "Polygon") {
|
|
|
|
t.Errorf("unexpected geometries: %v", rows)
|
|
|
|
}
|
|
|
|
})
|
2015-11-23 11:05:19 +03:00
|
|
|
|
2018-06-05 22:04:02 +03:00
|
|
|
t.Run("DuplicateIds1", func(t *testing.T) {
|
|
|
|
// Points/lines/polygons with same ID are inserted.
|
2015-12-21 12:41:27 +03:00
|
|
|
|
2018-06-05 22:04:02 +03:00
|
|
|
ts.assertHstore(t, []checkElem{
|
|
|
|
{"osm_all", 31101, "*", map[string]string{"amenity": "cafe"}},
|
|
|
|
})
|
2015-12-21 12:41:27 +03:00
|
|
|
|
2018-06-05 22:04:02 +03:00
|
|
|
rows := ts.queryRowsTags(t, "osm_all", -31101)
|
|
|
|
if len(rows) != 2 || strings.HasPrefix(rows[0].wkt, "LineString") || strings.HasPrefix(rows[1].wkt, "Polygon") {
|
|
|
|
t.Errorf("unexpected geometries: %v", rows)
|
|
|
|
}
|
2015-11-23 11:05:19 +03:00
|
|
|
|
2018-06-05 22:04:02 +03:00
|
|
|
ts.assertHstore(t, []checkElem{
|
|
|
|
{"osm_all", RelOffset - 31101, "*", map[string]string{"building": "yes", "type": "multipolygon"}},
|
|
|
|
})
|
|
|
|
ts.assertGeomType(t, checkElem{"osm_all", RelOffset - 31101, "*", nil}, "Polygon")
|
2015-11-23 11:05:19 +03:00
|
|
|
})
|
|
|
|
|
2018-06-05 22:04:02 +03:00
|
|
|
// #######################################################################
|
2015-11-23 11:05:19 +03:00
|
|
|
|
2018-06-05 22:04:02 +03:00
|
|
|
t.Run("Update", func(t *testing.T) {
|
|
|
|
ts.updateOsm(t, "build/single_table.osc.gz")
|
|
|
|
})
|
2015-11-23 11:05:19 +03:00
|
|
|
|
2018-06-05 22:04:02 +03:00
|
|
|
// #######################################################################
|
2015-11-23 11:05:19 +03:00
|
|
|
|
2018-06-05 22:04:02 +03:00
|
|
|
t.Run("DuplicateIds2", func(t *testing.T) {
|
|
|
|
// Node moved and ways/rels with same ID are still present.
|
2015-11-23 11:05:19 +03:00
|
|
|
|
2018-06-05 22:04:02 +03:00
|
|
|
ts.assertHstore(t, []checkElem{
|
|
|
|
{"osm_all", 31101, "*", map[string]string{"amenity": "cafe"}},
|
|
|
|
})
|
2015-11-23 11:05:19 +03:00
|
|
|
|
2018-06-05 22:04:02 +03:00
|
|
|
rows := ts.queryRowsTags(t, "osm_all", -31101)
|
|
|
|
if len(rows) != 2 || strings.HasPrefix(rows[0].wkt, "LineString") || strings.HasPrefix(rows[1].wkt, "Polygon") {
|
|
|
|
t.Errorf("unexpected geometries: %v", rows)
|
|
|
|
}
|
2015-11-23 11:05:19 +03:00
|
|
|
|
2018-06-05 22:04:02 +03:00
|
|
|
ts.assertHstore(t, []checkElem{
|
|
|
|
{"osm_all", RelOffset - 31101, "*", map[string]string{"building": "yes", "type": "multipolygon"}},
|
|
|
|
})
|
|
|
|
ts.assertGeomType(t, checkElem{"osm_all", RelOffset - 31101, "*", nil}, "Polygon")
|
2015-11-23 11:05:19 +03:00
|
|
|
})
|
2016-02-04 19:07:35 +03:00
|
|
|
|
2018-06-05 22:04:02 +03:00
|
|
|
t.Run("ModifiedRelation2", func(t *testing.T) {
|
|
|
|
// Modified relation is not inserted twice. Check for #88
|
2016-02-04 19:07:35 +03:00
|
|
|
|
2018-06-05 22:04:02 +03:00
|
|
|
rows := ts.queryRowsTags(t, "osm_all", RelOffset-32901)
|
|
|
|
if len(rows) != 1 {
|
|
|
|
t.Errorf("found duplicate row: %v", rows)
|
|
|
|
}
|
|
|
|
})
|
2016-06-15 15:26:50 +03:00
|
|
|
|
2018-06-05 22:04:02 +03:00
|
|
|
t.Run("Cleanup", func(t *testing.T) {
|
|
|
|
ts.dropSchemas()
|
|
|
|
if err := os.RemoveAll(ts.dir); err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
})
|
2016-06-15 15:26:50 +03:00
|
|
|
}
|