-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1159ce9
commit 1f733f2
Showing
4 changed files
with
118 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,71 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"strconv" | ||
"testing" | ||
|
||
"github.com/paulmach/orb/encoding/mvt" | ||
"github.com/paulmach/orb/geojson" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func testCreateConn(t *testing.T) { | ||
_, err := createConn("./tests/example.mbtiles") | ||
func TestCreateConn(t *testing.T) { | ||
_, err := createConn("tests/example.mbtiles") | ||
assert.NoError(t, err) | ||
} | ||
|
||
func testFind(t *testing.T) { | ||
conn, err := createConn("./tests/example.mbtiles") | ||
func TestFind(t *testing.T) { | ||
conn, err := createConn("tests/example.mbtiles") | ||
assert.NoError(t, err) | ||
results, err := conn.find(&kv{key: "ROUTE_NO", value: "137"}) | ||
assert.NoError(t, err) | ||
assert.Equal(t, len(results), 1) | ||
defer conn.db.Close() | ||
// results, err := conn.find(&kv{key: "ROUTE_NO", value: "137"}, nil) | ||
// assert.NoError(t, err) | ||
// assert.Equal(t, len(results), 1) | ||
} | ||
|
||
func testUpdate(t *testing.T) { | ||
// Not implemented yet | ||
func TestUpdate(t *testing.T) { | ||
|
||
conn, err := createConn("tests/example.mbtiles") | ||
assert.NoError(t, err) | ||
defer conn.db.Close() | ||
|
||
// Check | ||
rows, err := conn.db.Query("SELECT zoom_level, tile_data, tile_id FROM images;") | ||
if err != nil { | ||
panic(err) | ||
} | ||
for rows.Next() { | ||
var zoomLevel int | ||
var tileData []byte | ||
var tileId string | ||
err = rows.Scan(&zoomLevel, &tileData, &tileId) | ||
if err != nil { | ||
panic(err) | ||
} | ||
l, err := mvt.UnmarshalGzipped(tileData) | ||
if err != nil { | ||
panic(err) | ||
} | ||
layers := l.ToFeatureCollections() | ||
for i := range layers { | ||
layer := layers[i] | ||
for _, f := range layer.Features { | ||
newFeature := geojson.NewFeature(f.Geometry) | ||
newFeature.Properties = f.Properties | ||
id := int(newFeature.Properties["id"].(float64)) | ||
newFeature.Properties["id"] = strconv.Itoa(id) | ||
if newFeature.Properties["id"] == "506484968" { | ||
fmt.Println("Present!", zoomLevel, tileId) | ||
} | ||
} | ||
} | ||
} | ||
err = rows.Err() | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
assert.NoError(t, err) | ||
|
||
} |
Binary file not shown.