Skip to content

Commit b51de17

Browse files
authored
Merge pull request #5 from phoops/geo-json
Added GeoJSON attribute to TestEntityMarshal test.
2 parents 0522881 + 6da6ae6 commit b51de17

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
@@ -743,8 +743,6 @@ func (a *Attribute) GetAsGeoJSON() (*geojson.Geometry, error) {
743743
if a.Type != GeoJSONType {
744744
return nil, fmt.Errorf("Attribute is not geo:json, but '%s'", a.Type)
745745
}
746-
fmt.Println("type:", reflect.TypeOf(a.Value))
747-
fmt.Println(a.Value)
748746
g, ok := a.Value.(*geojson.Geometry)
749747
if !ok {
750748
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

@@ -323,6 +324,9 @@ func TestEntityMarshal(t *testing.T) {
323324
t.Fatal("Expected an error for an invalid attribute")
324325
}
325326

327+
geoJsonPoint := geojson.NewPointGeometry([]float64{4.1, 2.3})
328+
office.SetAttributeAsGeoJSON("position", geoJsonPoint)
329+
326330
bytes, err := json.Marshal(office)
327331
if err != nil {
328332
t.Fatalf("Unexpected error: '%v'", err)
@@ -436,6 +440,22 @@ func TestEntityMarshal(t *testing.T) {
436440
}
437441
}
438442
}
443+
444+
if positionAttr, err := unmarshaled.GetAttribute("position"); err != nil {
445+
t.Fatalf("Unexpected error: '%v'", err)
446+
} else {
447+
if positionVal, err := positionAttr.GetAsGeoJSON(); err != nil {
448+
t.Fatalf("Unexpected error: '%v'", err)
449+
} else {
450+
if !positionVal.IsPoint() {
451+
t.Fatalf("Expected '%v' for position type == point, got '%v'", true, positionVal.IsPoint())
452+
}
453+
454+
if positionVal.Point[0] != geoJsonPoint.Point[0] || positionVal.Point[1] != geoJsonPoint.Point[1] {
455+
t.Fatalf("Expected '%v' for location value, got '%v'", geoJsonPoint.Point, positionVal.Point)
456+
}
457+
}
458+
}
439459
}
440460

441461
func TestDirectEntityAttributeAccess(t *testing.T) {
@@ -543,7 +563,7 @@ func TestDirectEntityAttributeAccess(t *testing.T) {
543563

544564
if lastUpdateAttrValue, err := office.GetAttributeAsDateTime("lastUpdate"); err != nil {
545565
t.Fatalf("Unexpected error: '%v'", err)
546-
} else if lastUpdateAttrValue.Day() != timeNow.Day() || lastUpdateAttrValue.Minute() != lastUpdateAttrValue.Minute() {
566+
} else if lastUpdateAttrValue.Day() != timeNow.Day() || lastUpdateAttrValue.Minute() != timeNow.Minute() {
547567
t.Fatalf("Expected '%v' for lastUpdate value, got '%v'", timeNow, lastUpdateAttrValue)
548568
}
549569

0 commit comments

Comments
 (0)