From 0015924ea7deff0dda748b5ac695196ac1420fb6 Mon Sep 17 00:00:00 2001 From: Gautam Dey Date: Sun, 3 Dec 2017 15:35:03 -0800 Subject: [PATCH] [issue-195] Added test case. Added test case for Issue #195. Without the fix for #195 this will fail via a panic. --- mvt/layer.go | 4 +--- mvt/layer_test.go | 52 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 3 deletions(-) diff --git a/mvt/layer.go b/mvt/layer.go index fa748274b..407aed81d 100644 --- a/mvt/layer.go +++ b/mvt/layer.go @@ -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 { diff --git a/mvt/layer_test.go b/mvt/layer_test.go index cafa4252e..85345d568 100644 --- a/mvt/layer_test.go +++ b/mvt/layer_test.go @@ -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" @@ -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,