test: refactor to use go 1.7 subtests

master
Oliver Tonnhofer 2018-06-05 21:04:02 +02:00
parent 32b80c2cdd
commit 160847e116
6 changed files with 1350 additions and 1303 deletions

View File

@ -10,53 +10,63 @@ import (
"github.com/omniscale/imposm3/geom/geos"
)
func TestAnyAny_Prepare(t *testing.T) {
var err error
func TestAnyAny(t *testing.T) {
if testing.Short() {
t.Skip("system test skipped with -test.short")
}
ts.dir, err = ioutil.TempDir("", "imposm_test")
if err != nil {
t.Fatal(err)
ts := importTestSuite{
name: "any_any",
}
ts.config = importConfig{
connection: "postgis://",
cacheDir: ts.dir,
osmFileName: "build/any_any.pbf",
mappingFileName: "any_any_mapping.json",
}
ts.g = geos.NewGeos()
ts.db, err = sql.Open("postgres", "sslmode=disable")
if err != nil {
t.Fatal(err)
}
ts.dropSchemas()
}
t.Run("Prepare", func(t *testing.T) {
var err error
func TestAnyAny_Import(t *testing.T) {
if ts.tableExists(t, dbschemaImport, "osm_all") != false {
t.Fatalf("table osm_all exists in schema %s", dbschemaImport)
}
ts.importOsm(t)
ts.deployOsm(t)
if ts.tableExists(t, dbschemaProduction, "osm_all") != true {
t.Fatalf("table osm_all does not exists in schema %s", dbschemaProduction)
}
}
ts.dir, err = ioutil.TempDir("", "imposm_test")
if err != nil {
t.Fatal(err)
}
ts.config = importConfig{
connection: "postgis://",
cacheDir: ts.dir,
osmFileName: "build/any_any.pbf",
mappingFileName: "any_any_mapping.json",
}
ts.g = geos.NewGeos()
func TestAnyAny_InsertedNodes(t *testing.T) {
assertHstore(t, []checkElem{
{"osm_all", 10000, "", nil}, // nodes without tags are not inserted
{"osm_all", 10001, "*", map[string]string{"random": "tag"}},
{"osm_all", 10002, "*", map[string]string{"amenity": "shop"}},
{"osm_all", 10003, "*", map[string]string{"random": "tag", "but": "mapped", "amenity": "shop"}},
{"osm_amenities", 10002, "*", map[string]string{"amenity": "shop"}},
{"osm_amenities", 10003, "*", map[string]string{"random": "tag", "but": "mapped", "amenity": "shop"}},
ts.db, err = sql.Open("postgres", "sslmode=disable")
if err != nil {
t.Fatal(err)
}
ts.dropSchemas()
})
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)
ts.deployOsm(t)
if ts.tableExists(t, ts.dbschemaProduction(), "osm_all") != true {
t.Fatalf("table osm_all does not exists in schema %s", ts.dbschemaProduction())
}
})
t.Run("InsertedNodes", func(t *testing.T) {
ts.assertHstore(t, []checkElem{
{"osm_all", 10000, "", nil}, // nodes without tags are not inserted
{"osm_all", 10001, "*", map[string]string{"random": "tag"}},
{"osm_all", 10002, "*", map[string]string{"amenity": "shop"}},
{"osm_all", 10003, "*", map[string]string{"random": "tag", "but": "mapped", "amenity": "shop"}},
{"osm_amenities", 10002, "*", map[string]string{"amenity": "shop"}},
{"osm_amenities", 10003, "*", map[string]string{"random": "tag", "but": "mapped", "amenity": "shop"}},
})
})
t.Run("Cleanup", func(t *testing.T) {
ts.dropSchemas()
if err := os.RemoveAll(ts.dir); err != nil {
t.Error(err)
}
})
}
func TestAnyAny_Cleanup(t *testing.T) {
ts.dropSchemas()
if err := os.RemoveAll(ts.dir); err != nil {
t.Error(err)
}
}

File diff suppressed because it is too large Load Diff

View File

@ -14,168 +14,178 @@ import (
"github.com/omniscale/imposm3/geom/geos"
)
func TestExpireTiles_Prepare(t *testing.T) {
var err error
ts.dir, err = ioutil.TempDir("", "imposm_test")
if err != nil {
t.Fatal(err)
func TestExpireTiles(t *testing.T) {
if testing.Short() {
t.Skip("system test skipped with -test.short")
}
ts.config = importConfig{
connection: "postgis://",
cacheDir: ts.dir,
osmFileName: "build/expire_tiles.pbf",
mappingFileName: "expire_tiles_mapping.yml",
expireTileDir: filepath.Join(ts.dir, "expiretiles"),
}
ts.g = geos.NewGeos()
ts.db, err = sql.Open("postgres", "sslmode=disable")
if err != nil {
t.Fatal(err)
ts := importTestSuite{
name: "expire_tiles",
}
ts.dropSchemas()
}
func TestExpireTiles_Import(t *testing.T) {
if ts.tableExists(t, dbschemaImport, "osm_roads") != false {
t.Fatalf("table osm_roads exists in schema %s", dbschemaImport)
}
ts.importOsm(t)
ts.deployOsm(t)
if ts.tableExists(t, dbschemaProduction, "osm_roads") != true {
t.Fatalf("table osm_roads does not exists in schema %s", dbschemaProduction)
}
}
t.Run("Prepare", func(t *testing.T) {
var err error
func TestExpireTiles_Elements(t *testing.T) {
assertRecords(t, []checkElem{
{"osm_roads", 20151, "motorway", nil},
{"osm_roads", 20251, "motorway", nil},
{"osm_roads", 20351, "motorway", nil},
ts.dir, err = ioutil.TempDir("", "imposm_test")
if err != nil {
t.Fatal(err)
}
ts.config = importConfig{
connection: "postgis://",
cacheDir: ts.dir,
osmFileName: "build/expire_tiles.pbf",
mappingFileName: "expire_tiles_mapping.yml",
expireTileDir: filepath.Join(ts.dir, "expiretiles"),
}
ts.g = geos.NewGeos()
{"osm_buildings", -30191, "yes", nil},
{"osm_buildings", -30291, "yes", nil},
{"osm_buildings", -30391, "yes", nil},
{"osm_buildings", -30491, "yes", nil},
ts.db, err = sql.Open("postgres", "sslmode=disable")
if err != nil {
t.Fatal(err)
}
ts.dropSchemas()
})
}
func TestExpireTiles_Update(t *testing.T) {
ts.updateOsm(t, "build/expire_tiles.osc.gz")
}
t.Run("Import", func(t *testing.T) {
if ts.tableExists(t, ts.dbschemaImport(), "osm_roads") != false {
t.Fatalf("table osm_roads exists in schema %s", ts.dbschemaImport())
}
ts.importOsm(t)
ts.deployOsm(t)
if ts.tableExists(t, ts.dbschemaProduction(), "osm_roads") != true {
t.Fatalf("table osm_roads does not exists in schema %s", ts.dbschemaProduction())
}
})
func TestExpireTiles_CheckExpireFile(t *testing.T) {
files, err := filepath.Glob(filepath.Join(ts.config.expireTileDir, "*", "*.tiles"))
if err != nil {
t.Fatal(err)
}
if len(files) != 1 {
t.Fatalf("expected one expire tile file, got: %v", files)
}
tiles, err := parseTileList(files[0])
if err != nil {
t.Error(err)
}
t.Run("Elements", func(t *testing.T) {
ts.assertRecords(t, []checkElem{
{"osm_roads", 20151, "motorway", nil},
{"osm_roads", 20251, "motorway", nil},
{"osm_roads", 20351, "motorway", nil},
for _, test := range []struct {
reason string
tiles []tile
expire bool
}{
{"create node", []tile{{8328, 8146, 14}}, true},
{"modify node (old)", []tile{{8237, 8146, 14}}, true},
{"modify node (new)", []tile{{8237, 8237, 14}}, true},
{"modify node to unmapped (old)", []tile{{8373, 8146, 14}, {8374, 8146, 14}}, true},
{"modify node to unmapped (new)", []tile{{8373, 8146, 14}, {8374, 8146, 14}}, false},
{"delete node", []tile{{8282, 8146, 14}, {8283, 8146, 14}}, true},
{"osm_buildings", -30191, "yes", nil},
{"osm_buildings", -30291, "yes", nil},
{"osm_buildings", -30391, "yes", nil},
{"osm_buildings", -30491, "yes", nil},
})
})
{"delete way", []tile{{8283, 8100, 14}}, true},
{"modify way", []tile{{8237, 8100, 14}}, true},
{"modify way from node (old)", []tile{{8328, 8100, 14}}, true},
{"modify way from node (new)", []tile{{8328, 8283, 14}}, true},
{"create way", []tile{{8374, 8100, 14}}, true},
{"create long way", []tile{{8419, 8100, 14}, {8420, 8100, 14}, {8421, 8100, 14}}, true},
t.Run("Update", func(t *testing.T) {
ts.updateOsm(t, "build/expire_tiles.osc.gz")
})
{"modify relation", []tile{{8237, 8055, 14}}, true},
{"delete relation", []tile{{8283, 8055, 14}}, true},
{"modify relation from way", []tile{{8328, 8055, 14}}, true},
{"modify relation from nodes (old)", []tile{{8374, 8055, 14}}, true},
{"modify relation from nodes (new)", []tile{{8374, 8328, 14}}, true},
{"create polygon (box)", []tile{
{8237, 8007, 14},
{8237, 8008, 14},
{8237, 8009, 14},
{8238, 8007, 14},
{8238, 8008, 14},
{8238, 8009, 14},
{8239, 8007, 14},
{8239, 8008, 14},
{8239, 8009, 14},
}, true},
t.Run("CheckExpireFile", func(t *testing.T) {
files, err := filepath.Glob(filepath.Join(ts.config.expireTileDir, "*", "*.tiles"))
if err != nil {
t.Fatal(err)
}
if len(files) != 1 {
t.Fatalf("expected one expire tile file, got: %v", files)
}
tiles, err := parseTileList(files[0])
if err != nil {
t.Error(err)
}
{"create polygon (outline)", []tile{
{8310, 8005, 14}, {8302, 7991, 14}, {8283, 7993, 14},
{8300, 8009, 14}, {8283, 8003, 14}, {8308, 8009, 14},
{8310, 7995, 14}, {8285, 8009, 14}, {8288, 8009, 14},
{8301, 8009, 14}, {8310, 8002, 14}, {8302, 8009, 14},
{8310, 8003, 14}, {8286, 8009, 14}, {8300, 7991, 14},
{8283, 7994, 14}, {8296, 8009, 14}, {8298, 8009, 14},
{8310, 8009, 14}, {8283, 7999, 14}, {8283, 7992, 14},
{8290, 7991, 14}, {8305, 8009, 14}, {8309, 7991, 14},
{8306, 7991, 14}, {8291, 7991, 14}, {8283, 7996, 14},
{8310, 7996, 14}, {8293, 7991, 14}, {8310, 8007, 14},
{8310, 8001, 14}, {8307, 8009, 14}, {8299, 8009, 14},
{8310, 7998, 14}, {8310, 7999, 14}, {8301, 7991, 14},
{8283, 7998, 14}, {8283, 8006, 14}, {8289, 8009, 14},
{8310, 8008, 14}, {8285, 7991, 14}, {8283, 8002, 14},
{8289, 7991, 14}, {8286, 7991, 14}, {8288, 7991, 14},
{8283, 8008, 14}, {8283, 8005, 14}, {8310, 7992, 14},
{8310, 8004, 14}, {8310, 7991, 14}, {8296, 7991, 14},
{8292, 7991, 14}, {8283, 8009, 14}, {8291, 8009, 14},
{8293, 8009, 14}, {8284, 8009, 14}, {8287, 7991, 14},
{8297, 8009, 14}, {8283, 8007, 14}, {8299, 7991, 14},
{8310, 7997, 14}, {8303, 8009, 14}, {8290, 8009, 14},
{8306, 8009, 14}, {8283, 7995, 14}, {8283, 8000, 14},
{8295, 8009, 14}, {8310, 8006, 14}, {8304, 8009, 14},
{8295, 7991, 14}, {8292, 8009, 14}, {8309, 8009, 14},
{8283, 8004, 14}, {8307, 7991, 14}, {8305, 7991, 14},
{8283, 8001, 14}, {8284, 7991, 14}, {8297, 7991, 14},
{8310, 7993, 14}, {8303, 7991, 14}, {8294, 8009, 14},
{8287, 8009, 14}, {8283, 7991, 14}, {8283, 7997, 14},
{8308, 7991, 14}, {8304, 7991, 14}, {8298, 7991, 14},
{8310, 8000, 14}, {8310, 7994, 14}, {8294, 7991, 14},
}, true},
} {
for _, test := range []struct {
reason string
tiles []tile
expire bool
}{
{"create node", []tile{{8328, 8146, 14}}, true},
{"modify node (old)", []tile{{8237, 8146, 14}}, true},
{"modify node (new)", []tile{{8237, 8237, 14}}, true},
{"modify node to unmapped (old)", []tile{{8373, 8146, 14}, {8374, 8146, 14}}, true},
{"modify node to unmapped (new)", []tile{{8373, 8146, 14}, {8374, 8146, 14}}, false},
{"delete node", []tile{{8282, 8146, 14}, {8283, 8146, 14}}, true},
for _, coord := range test.tiles {
if test.expire {
if _, ok := tiles[coord]; !ok {
t.Errorf("missing expire tile for %s %v", test.reason, coord)
{"delete way", []tile{{8283, 8100, 14}}, true},
{"modify way", []tile{{8237, 8100, 14}}, true},
{"modify way from node (old)", []tile{{8328, 8100, 14}}, true},
{"modify way from node (new)", []tile{{8328, 8283, 14}}, true},
{"create way", []tile{{8374, 8100, 14}}, true},
{"create long way", []tile{{8419, 8100, 14}, {8420, 8100, 14}, {8421, 8100, 14}}, true},
{"modify relation", []tile{{8237, 8055, 14}}, true},
{"delete relation", []tile{{8283, 8055, 14}}, true},
{"modify relation from way", []tile{{8328, 8055, 14}}, true},
{"modify relation from nodes (old)", []tile{{8374, 8055, 14}}, true},
{"modify relation from nodes (new)", []tile{{8374, 8328, 14}}, true},
{"create polygon (box)", []tile{
{8237, 8007, 14},
{8237, 8008, 14},
{8237, 8009, 14},
{8238, 8007, 14},
{8238, 8008, 14},
{8238, 8009, 14},
{8239, 8007, 14},
{8239, 8008, 14},
{8239, 8009, 14},
}, true},
{"create polygon (outline)", []tile{
{8310, 8005, 14}, {8302, 7991, 14}, {8283, 7993, 14},
{8300, 8009, 14}, {8283, 8003, 14}, {8308, 8009, 14},
{8310, 7995, 14}, {8285, 8009, 14}, {8288, 8009, 14},
{8301, 8009, 14}, {8310, 8002, 14}, {8302, 8009, 14},
{8310, 8003, 14}, {8286, 8009, 14}, {8300, 7991, 14},
{8283, 7994, 14}, {8296, 8009, 14}, {8298, 8009, 14},
{8310, 8009, 14}, {8283, 7999, 14}, {8283, 7992, 14},
{8290, 7991, 14}, {8305, 8009, 14}, {8309, 7991, 14},
{8306, 7991, 14}, {8291, 7991, 14}, {8283, 7996, 14},
{8310, 7996, 14}, {8293, 7991, 14}, {8310, 8007, 14},
{8310, 8001, 14}, {8307, 8009, 14}, {8299, 8009, 14},
{8310, 7998, 14}, {8310, 7999, 14}, {8301, 7991, 14},
{8283, 7998, 14}, {8283, 8006, 14}, {8289, 8009, 14},
{8310, 8008, 14}, {8285, 7991, 14}, {8283, 8002, 14},
{8289, 7991, 14}, {8286, 7991, 14}, {8288, 7991, 14},
{8283, 8008, 14}, {8283, 8005, 14}, {8310, 7992, 14},
{8310, 8004, 14}, {8310, 7991, 14}, {8296, 7991, 14},
{8292, 7991, 14}, {8283, 8009, 14}, {8291, 8009, 14},
{8293, 8009, 14}, {8284, 8009, 14}, {8287, 7991, 14},
{8297, 8009, 14}, {8283, 8007, 14}, {8299, 7991, 14},
{8310, 7997, 14}, {8303, 8009, 14}, {8290, 8009, 14},
{8306, 8009, 14}, {8283, 7995, 14}, {8283, 8000, 14},
{8295, 8009, 14}, {8310, 8006, 14}, {8304, 8009, 14},
{8295, 7991, 14}, {8292, 8009, 14}, {8309, 8009, 14},
{8283, 8004, 14}, {8307, 7991, 14}, {8305, 7991, 14},
{8283, 8001, 14}, {8284, 7991, 14}, {8297, 7991, 14},
{8310, 7993, 14}, {8303, 7991, 14}, {8294, 8009, 14},
{8287, 8009, 14}, {8283, 7991, 14}, {8283, 7997, 14},
{8308, 7991, 14}, {8304, 7991, 14}, {8298, 7991, 14},
{8310, 8000, 14}, {8310, 7994, 14}, {8294, 7991, 14},
}, true},
} {
for _, coord := range test.tiles {
if test.expire {
if _, ok := tiles[coord]; !ok {
t.Errorf("missing expire tile for %s %v", test.reason, coord)
} else {
delete(tiles, coord)
}
} else {
delete(tiles, coord)
}
} else {
if _, ok := tiles[coord]; ok {
t.Errorf("found expire tile for %s %v", test.reason, coord)
if _, ok := tiles[coord]; ok {
t.Errorf("found expire tile for %s %v", test.reason, coord)
}
}
}
}
}
if len(tiles) > 0 {
t.Errorf("found %d unexpected tiles", len(tiles))
}
for tile, _ := range tiles {
t.Errorf("unexpected tile expired: %v", tile)
}
}
if len(tiles) > 0 {
t.Errorf("found %d unexpected tiles", len(tiles))
}
for tile, _ := range tiles {
t.Errorf("unexpected tile expired: %v", tile)
}
})
func TestExpireTiles_Cleanup(t *testing.T) {
ts.dropSchemas()
if err := os.RemoveAll(ts.dir); err != nil {
t.Error(err)
}
t.Run("Cleanup", func(t *testing.T) {
ts.dropSchemas()
if err := os.RemoveAll(ts.dir); err != nil {
t.Error(err)
}
})
}
type tile struct {

View File

@ -21,12 +21,6 @@ import (
"github.com/omniscale/imposm3/import_"
)
const (
dbschemaImport = "imposm_test_import"
dbschemaProduction = "imposm_test_production"
dbschemaBackup = "imposm_test_backup"
)
type importConfig struct {
connection string
osmFileName string
@ -38,6 +32,7 @@ type importConfig struct {
type importTestSuite struct {
dir string
name string
config importConfig
db *sql.DB
g *geos.Geos
@ -45,6 +40,10 @@ type importTestSuite struct {
const Missing = ""
func (s *importTestSuite) dbschemaImport() string { return "imposm_test_" + s.name + "_import" }
func (s *importTestSuite) dbschemaProduction() string { return "imposm_test_" + s.name + "_production" }
func (s *importTestSuite) dbschemaBackup() string { return "imposm_test_" + s.name + "_backup" }
func (s *importTestSuite) importOsm(t *testing.T) {
importArgs := []string{
"-connection", s.config.connection,
@ -53,7 +52,7 @@ func (s *importTestSuite) importOsm(t *testing.T) {
"-cachedir", s.config.cacheDir,
"-diff",
"-overwritecache",
"-dbschema-import", dbschemaImport,
"-dbschema-import", s.dbschemaImport(),
// "-optimize",
"-mapping", s.config.mappingFileName,
"-quiet",
@ -75,9 +74,9 @@ func (s *importTestSuite) deployOsm(t *testing.T) {
"-deployproduction",
"-removebackup=false",
"-connection", s.config.connection,
"-dbschema-import", dbschemaImport,
"-dbschema-production", dbschemaProduction,
"-dbschema-backup", dbschemaBackup,
"-dbschema-import", s.dbschemaImport(),
"-dbschema-production", s.dbschemaProduction(),
"-dbschema-backup", s.dbschemaBackup(),
"-deployproduction",
"-mapping", s.config.mappingFileName,
"-quiet",
@ -96,9 +95,9 @@ func (s *importTestSuite) revertDeployOsm(t *testing.T) {
"-deployproduction=false",
"-removebackup=false",
"-connection", s.config.connection,
"-dbschema-import", dbschemaImport,
"-dbschema-production", dbschemaProduction,
"-dbschema-backup", dbschemaBackup,
"-dbschema-import", s.dbschemaImport(),
"-dbschema-production", s.dbschemaProduction(),
"-dbschema-backup", s.dbschemaBackup(),
"-revertdeploy",
"-deployproduction=false",
"-removebackup=false",
@ -135,9 +134,9 @@ func (s *importTestSuite) removeBackupOsm(t *testing.T) {
"-deployproduction=false",
"-removebackup",
"-connection", s.config.connection,
"-dbschema-import", dbschemaImport,
"-dbschema-production", dbschemaProduction,
"-dbschema-backup", dbschemaBackup,
"-dbschema-import", s.dbschemaImport(),
"-dbschema-production", s.dbschemaProduction(),
"-dbschema-backup", s.dbschemaBackup(),
"-mapping", s.config.mappingFileName,
"-quiet",
}
@ -151,7 +150,7 @@ func (s *importTestSuite) updateOsm(t *testing.T, diffFile string) {
"-connection", s.config.connection,
"-cachedir", s.config.cacheDir,
"-limitto", "clipping.geojson",
"-dbschema-production", dbschemaProduction,
"-dbschema-production", s.dbschemaProduction(),
"-mapping", s.config.mappingFileName,
}
if s.config.expireTileDir != "" {
@ -164,15 +163,15 @@ func (s *importTestSuite) updateOsm(t *testing.T, diffFile string) {
func (s *importTestSuite) dropSchemas() {
var err error
_, err = s.db.Exec(fmt.Sprintf(`DROP SCHEMA IF EXISTS %s CASCADE`, dbschemaImport))
_, err = s.db.Exec(fmt.Sprintf(`DROP SCHEMA IF EXISTS %s CASCADE`, s.dbschemaImport()))
if err != nil {
log.Fatal(err)
}
_, err = s.db.Exec(fmt.Sprintf(`DROP SCHEMA IF EXISTS %s CASCADE`, dbschemaProduction))
_, err = s.db.Exec(fmt.Sprintf(`DROP SCHEMA IF EXISTS %s CASCADE`, s.dbschemaProduction()))
if err != nil {
log.Fatal(err)
}
_, err = s.db.Exec(fmt.Sprintf(`DROP SCHEMA IF EXISTS %s CASCADE`, dbschemaBackup))
_, err = s.db.Exec(fmt.Sprintf(`DROP SCHEMA IF EXISTS %s CASCADE`, s.dbschemaBackup()))
if err != nil {
log.Fatal(err)
}
@ -208,7 +207,7 @@ func (s *importTestSuite) query(t *testing.T, table string, id int64, keys []str
} else {
columns = "hstore(ARRAY[" + columns + "])"
}
stmt := fmt.Sprintf(`SELECT osm_id, name, type, ST_AsText(geometry), %s FROM "%s"."%s" WHERE osm_id=$1`, columns, dbschemaProduction, table)
stmt := fmt.Sprintf(`SELECT osm_id, name, type, ST_AsText(geometry), %s FROM "%s"."%s" WHERE osm_id=$1`, columns, s.dbschemaProduction(), table)
row := s.db.QueryRow(stmt, id)
r := record{}
h := hstore.Hstore{}
@ -231,7 +230,7 @@ func (s *importTestSuite) query(t *testing.T, table string, id int64, keys []str
}
func (s *importTestSuite) queryTags(t *testing.T, table string, id int64) record {
stmt := fmt.Sprintf(`SELECT osm_id, tags FROM "%s"."%s" WHERE osm_id=$1`, dbschemaProduction, table)
stmt := fmt.Sprintf(`SELECT osm_id, tags FROM "%s"."%s" WHERE osm_id=$1`, s.dbschemaProduction(), table)
row := s.db.QueryRow(stmt, id)
r := record{}
h := hstore.Hstore{}
@ -254,7 +253,7 @@ func (s *importTestSuite) queryTags(t *testing.T, table string, id int64) record
}
func (s *importTestSuite) queryRows(t *testing.T, table string, id int64) []record {
rows, err := s.db.Query(fmt.Sprintf(`SELECT osm_id, name, type, ST_AsText(geometry) FROM "%s"."%s" WHERE osm_id=$1 ORDER BY type, name, ST_GeometryType(geometry)`, dbschemaProduction, table), id)
rows, err := s.db.Query(fmt.Sprintf(`SELECT osm_id, name, type, ST_AsText(geometry) FROM "%s"."%s" WHERE osm_id=$1 ORDER BY type, name, ST_GeometryType(geometry)`, s.dbschemaProduction(), table), id)
if err != nil {
t.Fatal(err)
}
@ -270,7 +269,7 @@ func (s *importTestSuite) queryRows(t *testing.T, table string, id int64) []reco
}
func (s *importTestSuite) queryRowsTags(t *testing.T, table string, id int64) []record {
rows, err := s.db.Query(fmt.Sprintf(`SELECT osm_id, ST_AsText(geometry), tags FROM "%s"."%s" WHERE osm_id=$1 ORDER BY ST_GeometryType(geometry)`, dbschemaProduction, table), id)
rows, err := s.db.Query(fmt.Sprintf(`SELECT osm_id, ST_AsText(geometry), tags FROM "%s"."%s" WHERE osm_id=$1 ORDER BY ST_GeometryType(geometry)`, s.dbschemaProduction(), table), id)
if err != nil {
t.Fatal(err)
}
@ -295,7 +294,7 @@ func (s *importTestSuite) queryRowsTags(t *testing.T, table string, id int64) []
}
func (s *importTestSuite) queryGeom(t *testing.T, table string, id int64) *geos.Geom {
stmt := fmt.Sprintf(`SELECT osm_id, ST_AsText(geometry) FROM "%s"."%s" WHERE osm_id=$1`, dbschemaProduction, table)
stmt := fmt.Sprintf(`SELECT osm_id, ST_AsText(geometry) FROM "%s"."%s" WHERE osm_id=$1`, s.dbschemaProduction(), table)
row := s.db.QueryRow(stmt, id)
r := record{}
if err := row.Scan(&r.id, &r.wkt); err != nil {
@ -315,7 +314,7 @@ func (s *importTestSuite) queryGeom(t *testing.T, table string, id int64) *geos.
}
func (s *importTestSuite) queryDynamic(t *testing.T, table, where string) []map[string]string {
stmt := fmt.Sprintf(`SELECT hstore(r) FROM (SELECT ST_AsText(geometry) AS wkt, * FROM "%s"."%s" WHERE %s) AS r`, dbschemaProduction, table, where)
stmt := fmt.Sprintf(`SELECT hstore(r) FROM (SELECT ST_AsText(geometry) AS wkt, * FROM "%s"."%s" WHERE %s) AS r`, s.dbschemaProduction(), table, where)
rows, err := s.db.Query(stmt)
if err != nil {
t.Fatal(err)
@ -344,7 +343,7 @@ type checkElem struct {
tags map[string]string
}
func assertRecords(t *testing.T, elems []checkElem) {
func (ts *importTestSuite) assertRecords(t *testing.T, elems []checkElem) {
for _, e := range elems {
keys := make([]string, 0, len(e.tags))
for k, _ := range e.tags {
@ -368,7 +367,7 @@ func assertRecords(t *testing.T, elems []checkElem) {
}
}
func assertHstore(t *testing.T, elems []checkElem) {
func (ts *importTestSuite) assertHstore(t *testing.T, elems []checkElem) {
for _, e := range elems {
r := ts.queryTags(t, e.table, e.id)
if e.osmType == "" {
@ -388,14 +387,14 @@ func assertHstore(t *testing.T, elems []checkElem) {
}
}
func assertGeomValid(t *testing.T, e checkElem) {
func (ts *importTestSuite) assertGeomValid(t *testing.T, e checkElem) {
geom := ts.queryGeom(t, e.table, e.id)
if !ts.g.IsValid(geom) {
t.Fatalf("geometry of %d is invalid", e.id)
}
}
func assertGeomArea(t *testing.T, e checkElem, expect float64) {
func (ts *importTestSuite) assertGeomArea(t *testing.T, e checkElem, expect float64) {
geom := ts.queryGeom(t, e.table, e.id)
if !ts.g.IsValid(geom) {
t.Fatalf("geometry of %d is invalid", e.id)
@ -406,7 +405,7 @@ func assertGeomArea(t *testing.T, e checkElem, expect float64) {
}
}
func assertGeomLength(t *testing.T, e checkElem, expect float64) {
func (ts *importTestSuite) assertGeomLength(t *testing.T, e checkElem, expect float64) {
geom := ts.queryGeom(t, e.table, e.id)
if !ts.g.IsValid(geom) {
t.Fatalf("geometry of %d is invalid", e.id)
@ -417,14 +416,14 @@ func assertGeomLength(t *testing.T, e checkElem, expect float64) {
}
}
func assertGeomType(t *testing.T, e checkElem, expect string) {
func (ts *importTestSuite) assertGeomType(t *testing.T, e checkElem, expect string) {
actual := ts.g.Type(ts.queryGeom(t, e.table, e.id))
if actual != expect {
t.Errorf("expected %s geometry for %d, got %s", expect, e.id, actual)
}
}
func assertCachedWay(t *testing.T, c *cache.OSMCache, id int64) *element.Way {
func (ts *importTestSuite) assertCachedWay(t *testing.T, c *cache.OSMCache, id int64) *element.Way {
way, err := c.Ways.GetWay(id)
if err == cache.NotFound {
t.Errorf("missing way %d", id)
@ -437,7 +436,7 @@ func assertCachedWay(t *testing.T, c *cache.OSMCache, id int64) *element.Way {
return way
}
func assertCachedNode(t *testing.T, c *cache.OSMCache, id int64) *element.Node {
func (ts *importTestSuite) assertCachedNode(t *testing.T, c *cache.OSMCache, id int64) *element.Node {
node, err := c.Nodes.GetNode(id)
if err == cache.NotFound {
node, err = c.Coords.GetCoord(id)

View File

@ -10,158 +10,168 @@ import (
"github.com/omniscale/imposm3/geom/geos"
)
func TestRouteRelation_Prepare(t *testing.T) {
var err error
func TestRouteRelation(t *testing.T) {
if testing.Short() {
t.Skip("system test skipped with -test.short")
}
ts.dir, err = ioutil.TempDir("", "imposm_test")
if err != nil {
t.Fatal(err)
ts := importTestSuite{
name: "route_relation",
}
ts.config = importConfig{
connection: "postgis://",
cacheDir: ts.dir,
osmFileName: "build/route_relation.pbf",
mappingFileName: "route_relation_mapping.yml",
}
ts.g = geos.NewGeos()
ts.db, err = sql.Open("postgres", "sslmode=disable")
if err != nil {
t.Fatal(err)
}
ts.dropSchemas()
}
func TestRouteRelation_Import(t *testing.T) {
if ts.tableExists(t, dbschemaImport, "osm_routes") != false {
t.Fatalf("table osm_routes exists in schema %s", dbschemaImport)
}
ts.importOsm(t)
if ts.tableExists(t, dbschemaImport, "osm_routes") != true {
t.Fatalf("table osm_routes does not exists in schema %s", dbschemaImport)
}
}
func TestRouteRelation_Deploy(t *testing.T) {
ts.deployOsm(t)
if ts.tableExists(t, dbschemaImport, "osm_routes") != false {
t.Fatalf("table osm_routes exists in schema %s", dbschemaImport)
}
if ts.tableExists(t, dbschemaProduction, "osm_routes") != true {
t.Fatalf("table osm_routes does not exists in schema %s", dbschemaProduction)
}
}
func TestRouteRelation_RelationData(t *testing.T) {
// check tags of relation
r := ts.queryTags(t, "osm_routes", -100901)
if r.tags["name"] != "Bus 301: A => B" {
t.Error(r)
}
// check tags of master relation
r = ts.queryTags(t, "osm_routes", -100911)
if r.tags["name"] != "Bus 301" {
t.Error(r)
}
}
func TestRouteRelation_MemberUpdatedByNode1(t *testing.T) {
// check that member is updated after node was modified
rows := ts.queryDynamic(t, "osm_route_members", "osm_id = -110901 AND member = 110101")
if len(rows) != 1 {
t.Fatal(rows)
}
if rows[0]["name"] != "Stop" {
t.Error(rows[0])
}
}
func TestRouteRelation_MemberGeomUpdated1(t *testing.T) {
rows := ts.queryDynamic(t, "osm_route_members", "osm_id = -100902 AND member = 100502")
if len(rows) != 1 {
t.Fatal(rows)
}
g := ts.g.FromWkt(rows[0]["wkt"])
if math.Abs(g.Length()-111.32448543701321) > 0.00000001 {
t.Fatal(g.Length())
}
rows = ts.queryDynamic(t, "osm_route_members", "osm_id = -100902 AND member = 100503")
if len(rows) != 1 {
t.Fatal(rows)
}
if rows[0]["name"] != "" {
t.Error(rows[0])
}
}
func TestRouteRelation_NoRouteWithMissingMember(t *testing.T) {
// current implementation: route members are all or nothing.
// if one member is missing, no member is imported
if r := ts.queryDynamic(t, "osm_route_members", "osm_id = -120901 AND member = 120101"); len(r) > 0 {
t.Error("found member from route with missing members")
}
}
// #######################################################################
func TestRouteRelation_Update(t *testing.T) {
ts.updateOsm(t, "./build/route_relation.osc.gz")
}
// #######################################################################
func TestRouteRelation_MemberGeomUpdated2(t *testing.T) {
rows := ts.queryDynamic(t, "osm_route_members", "osm_id = -100902 AND member = 100502")
if len(rows) != 1 {
t.Fatal(rows)
}
g := ts.g.FromWkt(rows[0]["wkt"])
if math.Abs(g.Length()-184.97560221624542) > 0.00000001 {
t.Fatal(g.Length())
}
// tag from member is updated
rows = ts.queryDynamic(t, "osm_route_members", "osm_id = -100902 AND member = 100503")
if len(rows) != 1 {
t.Fatal(rows)
}
if rows[0]["name"] != "new name" {
t.Error(rows[0])
}
// member is removed
rows = ts.queryDynamic(t, "osm_route_members", "osm_id = -100902 AND member = 100512")
if len(rows) != 0 {
t.Fatal(rows)
}
// role from member is updated
rows = ts.queryDynamic(t, "osm_route_members", "osm_id = -100902 AND member = 100102")
if len(rows) != 1 {
t.Fatal(rows)
}
if rows[0]["role"] != "halt" {
t.Error(rows[0])
}
}
func TestRouteRelation_MemberUpdatedByNode2(t *testing.T) {
// check that member is updated after node was modified
rows := ts.queryDynamic(t, "osm_route_members", "osm_id = -110901 AND member = 110101")
if len(rows) != 1 {
t.Fatal(rows)
}
if rows[0]["name"] != "Stop2" {
t.Error(rows[0])
}
}
func TestRouteRelation_Cleanup(t *testing.T) {
ts.dropSchemas()
if err := os.RemoveAll(ts.dir); err != nil {
t.Error(err)
}
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/route_relation.pbf",
mappingFileName: "route_relation_mapping.yml",
}
ts.g = geos.NewGeos()
ts.db, err = sql.Open("postgres", "sslmode=disable")
if err != nil {
t.Fatal(err)
}
ts.dropSchemas()
})
t.Run("Import", func(t *testing.T) {
if ts.tableExists(t, ts.dbschemaImport(), "osm_routes") != false {
t.Fatalf("table osm_routes exists in schema %s", ts.dbschemaImport())
}
ts.importOsm(t)
if ts.tableExists(t, ts.dbschemaImport(), "osm_routes") != true {
t.Fatalf("table osm_routes does not exists in schema %s", ts.dbschemaImport())
}
})
t.Run("Deploy", func(t *testing.T) {
ts.deployOsm(t)
if ts.tableExists(t, ts.dbschemaImport(), "osm_routes") != false {
t.Fatalf("table osm_routes exists in schema %s", ts.dbschemaImport())
}
if ts.tableExists(t, ts.dbschemaProduction(), "osm_routes") != true {
t.Fatalf("table osm_routes does not exists in schema %s", ts.dbschemaProduction())
}
})
t.Run("RelationData", func(t *testing.T) {
// check tags of relation
r := ts.queryTags(t, "osm_routes", -100901)
if r.tags["name"] != "Bus 301: A => B" {
t.Error(r)
}
// check tags of master relation
r = ts.queryTags(t, "osm_routes", -100911)
if r.tags["name"] != "Bus 301" {
t.Error(r)
}
})
t.Run("MemberUpdatedByNode1", func(t *testing.T) {
// check that member is updated after node was modified
rows := ts.queryDynamic(t, "osm_route_members", "osm_id = -110901 AND member = 110101")
if len(rows) != 1 {
t.Fatal(rows)
}
if rows[0]["name"] != "Stop" {
t.Error(rows[0])
}
})
t.Run("MemberGeomUpdated1", func(t *testing.T) {
rows := ts.queryDynamic(t, "osm_route_members", "osm_id = -100902 AND member = 100502")
if len(rows) != 1 {
t.Fatal(rows)
}
g := ts.g.FromWkt(rows[0]["wkt"])
if math.Abs(g.Length()-111.32448543701321) > 0.00000001 {
t.Fatal(g.Length())
}
rows = ts.queryDynamic(t, "osm_route_members", "osm_id = -100902 AND member = 100503")
if len(rows) != 1 {
t.Fatal(rows)
}
if rows[0]["name"] != "" {
t.Error(rows[0])
}
})
t.Run("NoRouteWithMissingMember", func(t *testing.T) {
// current implementation: route members are all or nothing.
// if one member is missing, no member is imported
if r := ts.queryDynamic(t, "osm_route_members", "osm_id = -120901 AND member = 120101"); len(r) > 0 {
t.Error("found member from route with missing members")
}
})
// #######################################################################
t.Run("Update", func(t *testing.T) {
ts.updateOsm(t, "build/route_relation.osc.gz")
})
// #######################################################################
t.Run("MemberGeomUpdated2", func(t *testing.T) {
rows := ts.queryDynamic(t, "osm_route_members", "osm_id = -100902 AND member = 100502")
if len(rows) != 1 {
t.Fatal(rows)
}
g := ts.g.FromWkt(rows[0]["wkt"])
if math.Abs(g.Length()-184.97560221624542) > 0.00000001 {
t.Fatal(g.Length())
}
// tag from member is updated
rows = ts.queryDynamic(t, "osm_route_members", "osm_id = -100902 AND member = 100503")
if len(rows) != 1 {
t.Fatal(rows)
}
if rows[0]["name"] != "new name" {
t.Error(rows[0])
}
// member is removed
rows = ts.queryDynamic(t, "osm_route_members", "osm_id = -100902 AND member = 100512")
if len(rows) != 0 {
t.Fatal(rows)
}
// role from member is updated
rows = ts.queryDynamic(t, "osm_route_members", "osm_id = -100902 AND member = 100102")
if len(rows) != 1 {
t.Fatal(rows)
}
if rows[0]["role"] != "halt" {
t.Error(rows[0])
}
})
t.Run("MemberUpdatedByNode2", func(t *testing.T) {
// check that member is updated after node was modified
rows := ts.queryDynamic(t, "osm_route_members", "osm_id = -110901 AND member = 110101")
if len(rows) != 1 {
t.Fatal(rows)
}
if rows[0]["name"] != "Stop2" {
t.Error(rows[0])
}
})
t.Run("Cleanup", func(t *testing.T) {
ts.dropSchemas()
if err := os.RemoveAll(ts.dir); err != nil {
t.Error(err)
}
})
}

View File

@ -13,195 +13,205 @@ import (
const RelOffset = -1e17
func TestSingleTable_Prepare(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()
}
func TestSingleTable_Import(t *testing.T) {
if ts.tableExists(t, dbschemaImport, "osm_all") != false {
t.Fatalf("table osm_all exists in schema %s", dbschemaImport)
}
ts.importOsm(t)
if ts.tableExists(t, dbschemaImport, "osm_all") != true {
t.Fatalf("table osm_all does not exists in schema %s", dbschemaImport)
}
}
func TestSingleTable_Deploy(t *testing.T) {
ts.deployOsm(t)
if ts.tableExists(t, dbschemaImport, "osm_all") != false {
t.Fatalf("table osm_all exists in schema %s", dbschemaImport)
}
if ts.tableExists(t, dbschemaProduction, "osm_all") != true {
t.Fatalf("table osm_all does not exists in schema %s", dbschemaProduction)
}
}
func TestSingleTable_NonMappedNodeIsMissing(t *testing.T) {
// Node without mapped tags is missing.
cache := ts.cache(t)
defer cache.Close()
assertCachedNode(t, cache, 10001)
assertHstore(t, []checkElem{
{"osm_all", 10001, Missing, nil},
})
}
func TestSingleTable_MappedNode(t *testing.T) {
// Node is stored with all tags.
cache := ts.cache(t)
defer cache.Close()
assertCachedNode(t, cache, 10002)
assertHstore(t, []checkElem{
{"osm_all", 10002, "*", map[string]string{"random": "tag", "but": "mapped", "poi": "unicorn"}},
})
}
func TestSingleTable_NonMappedWayIsMissing(t *testing.T) {
// Way without mapped tags is missing.
cache := ts.cache(t)
defer cache.Close()
assertCachedWay(t, cache, 20101)
assertCachedWay(t, cache, 20102)
assertCachedWay(t, cache, 20103)
assertHstore(t, []checkElem{
{"osm_all", 20101, Missing, nil},
{"osm_all", 20102, Missing, nil},
{"osm_all", 20103, Missing, nil},
})
}
func TestSingleTable_MappedWay(t *testing.T) {
// Way is stored with all tags.
cache := ts.cache(t)
defer cache.Close()
assertCachedWay(t, cache, 20201)
assertHstore(t, []checkElem{
{"osm_all", -20201, "*", map[string]string{"random": "tag", "highway": "yes"}},
})
}
func TestSingleTable_NonMappedClosedWayIsMissing(t *testing.T) {
// Closed way without mapped tags is missing.
cache := ts.cache(t)
defer cache.Close()
assertCachedWay(t, cache, 20301)
assertHstore(t, []checkElem{
{"osm_all", 20301, Missing, nil},
{"osm_all", -20301, Missing, nil},
})
}
func TestSingleTable_MappedClosedWay(t *testing.T) {
// Closed way is stored with all tags.
assertHstore(t, []checkElem{
{"osm_all", -20401, "*", map[string]string{"random": "tag", "building": "yes"}},
})
}
func TestSingleTable_MappedClosedWayAreaYes(t *testing.T) {
// Closed way with area=yes is not stored as linestring.
assertHstore(t, []checkElem{
{"osm_all", -20501, "*", map[string]string{"random": "tag", "landuse": "grass", "highway": "pedestrian", "area": "yes"}},
})
assertGeomType(t, checkElem{"osm_all", -20501, "*", nil}, "Polygon")
}
func TestSingleTable_MappedClosedWayAreaNo(t *testing.T) {
// Closed way with area=no is not stored as polygon.
assertHstore(t, []checkElem{
{"osm_all", -20502, "*", map[string]string{"random": "tag", "landuse": "grass", "highway": "pedestrian", "area": "no"}},
})
assertGeomType(t, checkElem{"osm_all", -20502, "*", nil}, "LineString")
}
func TestSingleTable_MappedClosedWayWithoutArea(t *testing.T) {
// Closed way without area is stored as mapped (linestring and polygon).
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)
}
}
func TestSingleTable_DuplicateIds1(t *testing.T) {
// Points/lines/polygons with same ID are inserted.
assertHstore(t, []checkElem{
{"osm_all", 31101, "*", map[string]string{"amenity": "cafe"}},
})
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)
func TestSingleTable(t *testing.T) {
if testing.Short() {
t.Skip("system test skipped with -test.short")
}
assertHstore(t, []checkElem{
{"osm_all", RelOffset - 31101, "*", map[string]string{"building": "yes", "type": "multipolygon"}},
})
assertGeomType(t, checkElem{"osm_all", RelOffset - 31101, "*", nil}, "Polygon")
}
// #######################################################################
func TestSingleTable_Update(t *testing.T) {
ts.updateOsm(t, "./build/single_table.osc.gz")
}
// #######################################################################
func TestSingleTable_DuplicateIds2(t *testing.T) {
// Node moved and ways/rels with same ID are still present.
assertHstore(t, []checkElem{
{"osm_all", 31101, "*", map[string]string{"amenity": "cafe"}},
})
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)
ts := importTestSuite{
name: "single_table",
}
assertHstore(t, []checkElem{
{"osm_all", RelOffset - 31101, "*", map[string]string{"building": "yes", "type": "multipolygon"}},
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()
})
assertGeomType(t, checkElem{"osm_all", RelOffset - 31101, "*", nil}, "Polygon")
}
func TestSingleTable_ModifiedRelation2(t *testing.T) {
// Modified relation is not inserted twice. Check for #88
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())
}
})
rows := ts.queryRowsTags(t, "osm_all", RelOffset-32901)
if len(rows) != 1 {
t.Errorf("found duplicate row: %v", rows)
}
}
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())
}
})
func TestSingleTable_Cleanup(t *testing.T) {
ts.dropSchemas()
if err := os.RemoveAll(ts.dir); err != nil {
t.Error(err)
}
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)
ts.assertHstore(t, []checkElem{
{"osm_all", 10001, Missing, nil},
})
})
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)
ts.assertHstore(t, []checkElem{
{"osm_all", 10002, "*", map[string]string{"random": "tag", "but": "mapped", "poi": "unicorn"}},
})
})
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)
ts.assertHstore(t, []checkElem{
{"osm_all", -20201, "*", map[string]string{"random": "tag", "highway": "yes"}},
})
})
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},
})
})
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"}},
})
})
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")
})
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")
})
t.Run("MappedClosedWayWithoutArea", func(t *testing.T) {
// Closed way without area is stored as mapped (linestring and polygon).
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)
}
})
t.Run("DuplicateIds1", func(t *testing.T) {
// Points/lines/polygons with same ID are inserted.
ts.assertHstore(t, []checkElem{
{"osm_all", 31101, "*", map[string]string{"amenity": "cafe"}},
})
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)
}
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")
})
// #######################################################################
t.Run("Update", func(t *testing.T) {
ts.updateOsm(t, "build/single_table.osc.gz")
})
// #######################################################################
t.Run("DuplicateIds2", func(t *testing.T) {
// Node moved and ways/rels with same ID are still present.
ts.assertHstore(t, []checkElem{
{"osm_all", 31101, "*", map[string]string{"amenity": "cafe"}},
})
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)
}
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")
})
t.Run("ModifiedRelation2", func(t *testing.T) {
// Modified relation is not inserted twice. Check for #88
rows := ts.queryRowsTags(t, "osm_all", RelOffset-32901)
if len(rows) != 1 {
t.Errorf("found duplicate row: %v", rows)
}
})
t.Run("Cleanup", func(t *testing.T) {
ts.dropSchemas()
if err := os.RemoveAll(ts.dir); err != nil {
t.Error(err)
}
})
}