|
| 1 | +package test |
| 2 | + |
| 3 | +import ( |
| 4 | + "database/sql" |
| 5 | + "io/ioutil" |
| 6 | + |
| 7 | + "testing" |
| 8 | + |
| 9 | + "github.com/omniscale/imposm3/geom/geos" |
| 10 | +) |
| 11 | + |
| 12 | +func TestMultiLineString(t *testing.T) { |
| 13 | + if testing.Short() { |
| 14 | + t.Skip("system test skipped with -test.short") |
| 15 | + } |
| 16 | + t.Parallel() |
| 17 | + |
| 18 | + ts := importTestSuite{ |
| 19 | + name: "multilinestring", |
| 20 | + } |
| 21 | + |
| 22 | + t.Run("Prepare", func(t *testing.T) { |
| 23 | + var err error |
| 24 | + |
| 25 | + ts.dir, err = ioutil.TempDir("", "imposm_test") |
| 26 | + if err != nil { |
| 27 | + t.Fatal(err) |
| 28 | + } |
| 29 | + ts.config = importConfig{ |
| 30 | + connection: "postgis://", |
| 31 | + cacheDir: ts.dir, |
| 32 | + osmFileName: "build/multilinestring.pbf", |
| 33 | + mappingFileName: "multilinestring_mapping.yml", |
| 34 | + } |
| 35 | + ts.g = geos.NewGeos() |
| 36 | + |
| 37 | + ts.db, err = sql.Open("postgres", "sslmode=disable") |
| 38 | + if err != nil { |
| 39 | + t.Fatal(err) |
| 40 | + } |
| 41 | + ts.dropSchemas() |
| 42 | + }) |
| 43 | + |
| 44 | + const mlsTable = "osm_multilinestring" |
| 45 | + |
| 46 | + t.Run("Import", func(t *testing.T) { |
| 47 | + if ts.tableExists(t, ts.dbschemaImport(), mlsTable) != false { |
| 48 | + t.Fatalf("table %s exists in schema %s", mlsTable, ts.dbschemaImport()) |
| 49 | + } |
| 50 | + ts.importOsm(t) |
| 51 | + if ts.tableExists(t, ts.dbschemaImport(), mlsTable) != true { |
| 52 | + t.Fatalf("table %s does not exists in schema %s", mlsTable, ts.dbschemaImport()) |
| 53 | + } |
| 54 | + }) |
| 55 | + |
| 56 | + t.Run("Deploy", func(t *testing.T) { |
| 57 | + ts.deployOsm(t) |
| 58 | + if ts.tableExists(t, ts.dbschemaImport(), mlsTable) != false { |
| 59 | + t.Fatalf("table %s exists in schema %s", mlsTable, ts.dbschemaImport()) |
| 60 | + } |
| 61 | + if ts.tableExists(t, ts.dbschemaProduction(), mlsTable) != true { |
| 62 | + t.Fatalf("table %s does not exists in schema %s", mlsTable, ts.dbschemaProduction()) |
| 63 | + } |
| 64 | + }) |
| 65 | + |
| 66 | + t.Run("CheckMultiLineStringGeometry", func(t *testing.T) { |
| 67 | + element := checkElem{mlsTable, -100, "*", nil} |
| 68 | + ts.assertGeomType(t, element, "MultiLineString") |
| 69 | + ts.assertGeomValid(t, element) |
| 70 | + ts.assertGeomLength(t, element, 38) |
| 71 | + }) |
| 72 | + |
| 73 | + t.Run("CheckLineStringGeometry", func(t *testing.T) { |
| 74 | + element := checkElem{mlsTable, 1000, "*", nil} |
| 75 | + ts.assertGeomType(t, element, "LineString") |
| 76 | + ts.assertGeomValid(t, element) |
| 77 | + ts.assertGeomLength(t, element, 10) |
| 78 | + }) |
| 79 | + |
| 80 | + t.Run("CheckFilters", func(t *testing.T) { |
| 81 | + if records := ts.queryRows(t, mlsTable, 1008); len(records) > 0 { |
| 82 | + t.Fatalf("The way 1008 should be filtered out by typed filter") |
| 83 | + } |
| 84 | + if records := ts.queryRows(t, mlsTable, 1004); len(records) > 0 { |
| 85 | + t.Fatalf("The way 1004 should be filtered out as it is closed path with area=yes") |
| 86 | + } |
| 87 | + }) |
| 88 | + |
| 89 | + t.Run("RelationTypesFilter", func(t *testing.T) { |
| 90 | + if records := ts.queryRows(t, "osm_multilinestring_no_relations", -100); len(records) > 0 { |
| 91 | + t.Fatalf("The relation -100 should not be imported due to empty relation_types") |
| 92 | + } |
| 93 | + }) |
| 94 | + |
| 95 | + t.Run("Update", func(t *testing.T) { |
| 96 | + ts.updateOsm(t, "build/multilinestring.osc.gz") |
| 97 | + }) |
| 98 | + |
| 99 | + t.Run("CheckFilters2", func(t *testing.T) { |
| 100 | + if records := ts.queryRows(t, mlsTable, 1004); len(records) == 0 { |
| 101 | + t.Fatalf("The way 1004 should now be there as we removed area=yes in the update") |
| 102 | + } |
| 103 | + }) |
| 104 | + |
| 105 | + t.Run("CheckNewRelation", func(t *testing.T) { |
| 106 | + if records := ts.queryRows(t, mlsTable, -102); len(records) == 0 { |
| 107 | + t.Fatalf("The relation -102 should be created") |
| 108 | + } |
| 109 | + }) |
| 110 | +} |
| 111 | + |
0 commit comments