Skip to content

Commit 6da6ae6

Browse files
committed
Added GeoJSON attribute to TestEntityMarshal test.
1 parent 51aa72d commit 6da6ae6

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

model/model.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -665,8 +665,6 @@ func (a *Attribute) GetAsGeoJSON() (*geojson.Geometry, error) {
665665
if a.Type != GeoJSONType {
666666
return nil, fmt.Errorf("Attribute is not geo:json, but '%s'", a.Type)
667667
}
668-
fmt.Println("type:", reflect.TypeOf(a.Value))
669-
fmt.Println(a.Value)
670668
g, ok := a.Value.(*geojson.Geometry)
671669
if !ok {
672670
return nil, fmt.Errorf("Attribute with geo:json type does not contain geo:json value")

model/model_test.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package model_test
22

33
import (
44
"encoding/json"
5+
geojson "github.com/paulmach/go.geojson"
56
"testing"
67
"time"
78

@@ -269,6 +270,9 @@ func TestEntityMarshal(t *testing.T) {
269270
t.Fatal("Expected an error for an invalid attribute")
270271
}
271272

273+
geoJsonPoint := geojson.NewPointGeometry([]float64{4.1, 2.3})
274+
office.SetAttributeAsGeoJSON("position", geoJsonPoint)
275+
272276
bytes, err := json.Marshal(office)
273277
if err != nil {
274278
t.Fatalf("Unexpected error: '%v'", err)
@@ -358,6 +362,22 @@ func TestEntityMarshal(t *testing.T) {
358362
}
359363
}
360364
}
365+
366+
if positionAttr, err := unmarshaled.GetAttribute("position"); err != nil {
367+
t.Fatalf("Unexpected error: '%v'", err)
368+
} else {
369+
if positionVal, err := positionAttr.GetAsGeoJSON(); err != nil {
370+
t.Fatalf("Unexpected error: '%v'", err)
371+
} else {
372+
if !positionVal.IsPoint() {
373+
t.Fatalf("Expected '%v' for position type == point, got '%v'", true, positionVal.IsPoint())
374+
}
375+
376+
if positionVal.Point[0] != geoJsonPoint.Point[0] || positionVal.Point[1] != geoJsonPoint.Point[1] {
377+
t.Fatalf("Expected '%v' for location value, got '%v'", geoJsonPoint.Point, positionVal.Point)
378+
}
379+
}
380+
}
361381
}
362382

363383
func TestDirectEntityAttributeAccess(t *testing.T) {
@@ -465,7 +485,7 @@ func TestDirectEntityAttributeAccess(t *testing.T) {
465485

466486
if lastUpdateAttrValue, err := office.GetAttributeAsDateTime("lastUpdate"); err != nil {
467487
t.Fatalf("Unexpected error: '%v'", err)
468-
} else if lastUpdateAttrValue.Day() != timeNow.Day() || lastUpdateAttrValue.Minute() != lastUpdateAttrValue.Minute() {
488+
} else if lastUpdateAttrValue.Day() != timeNow.Day() || lastUpdateAttrValue.Minute() != timeNow.Minute() {
469489
t.Fatalf("Expected '%v' for lastUpdate value, got '%v'", timeNow, lastUpdateAttrValue)
470490
}
471491

0 commit comments

Comments
 (0)