Skip to content

Commit

Permalink
[issue-195] Added test case.
Browse files Browse the repository at this point in the history
Added test case for Issue #195.
Without the fix for #195 this will fail via a panic.
  • Loading branch information
gdey committed Dec 3, 2017
1 parent a7f2e6e commit 0015924
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 3 deletions.
4 changes: 1 addition & 3 deletions mvt/layer.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,7 @@ func (l *Layer) VTileLayer(ctx context.Context, extent tegola.BoundingBox) (*vec
}

//Version is the version of tile spec this layer is from.
func (*Layer) Version() int {
return 2
}
func (*Layer) Version() int { return 2 }

// Extent defaults to 4096
func (l *Layer) Extent() int {
Expand Down
52 changes: 52 additions & 0 deletions mvt/layer_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package mvt

import (
"reflect"
"testing"

"context"

"github.com/gdey/tbltest"
"github.com/terranodo/tegola"
"github.com/terranodo/tegola/basic"
"github.com/terranodo/tegola/mvt/vector_tile"
Expand All @@ -23,6 +25,56 @@ func newTileLayer(name string, keys []string, values []*vectorTile.Tile_Value, f
}
}

func TestLayerAddFeatures(t *testing.T) {
type tc struct {
features []Feature
expected []Feature // Nil means that it's the same as the features.
skipped bool
}
fn := func(idx int, tcase tc) {
defer func() {
if r := recover(); r != nil {
t.Errorf("Did not expect AddFeatures to painc: Recovered: %v", r)
}
}()
// First create a blank layer to add the features to.
l := new(Layer)
skipped := l.AddFeatures(tcase.features...)
if tcase.skipped != skipped {
t.Errorf("[%v] skipped value; expected: %v got: %v", tcase.skipped, skipped)
}
gotFeatures := l.Features()
expectedFeatures := tcase.expected
if expectedFeatures == nil {
expectedFeatures = tcase.features
}
if len(gotFeatures) != len(expectedFeatures) {
t.Errorf("[%v] number of features incorrect. expected: %v got: %v", len(expectedFeatures), len(gotFeatures))
}
for i := range expectedFeatures {
if !reflect.DeepEqual(expectedFeatures[i], gotFeatures[i]) {
t.Errorf("[%v] expected feature %v to match. expected: %v got: %v", idx, i, expectedFeatures[i], gotFeatures[i])
}
}
}
newID := func(id uint64) *uint64 { return &id }
tbltest.Cases(
tc{
features: []Feature{
{
Tags: map[string]interface{}{"btag": "tag"},
Geometry: basic.Point{12.0, 15.0},
},
{
ID: newID(1),
Tags: map[string]interface{}{"atag": "tag"},
Geometry: basic.Point{12.0, 15.0},
},
},
},
).Run(fn)
}

func TestLayer(t *testing.T) {
baseBBox := tegola.BoundingBox{
Minx: 0,
Expand Down

0 comments on commit 0015924

Please sign in to comment.