@@ -2,6 +2,7 @@ package model_test
2
2
3
3
import (
4
4
"encoding/json"
5
+ geojson "github.com/paulmach/go.geojson"
5
6
"testing"
6
7
"time"
7
8
@@ -269,6 +270,9 @@ func TestEntityMarshal(t *testing.T) {
269
270
t .Fatal ("Expected an error for an invalid attribute" )
270
271
}
271
272
273
+ geoJsonPoint := geojson .NewPointGeometry ([]float64 {4.1 , 2.3 })
274
+ office .SetAttributeAsGeoJSON ("position" , geoJsonPoint )
275
+
272
276
bytes , err := json .Marshal (office )
273
277
if err != nil {
274
278
t .Fatalf ("Unexpected error: '%v'" , err )
@@ -358,6 +362,22 @@ func TestEntityMarshal(t *testing.T) {
358
362
}
359
363
}
360
364
}
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
+ }
361
381
}
362
382
363
383
func TestDirectEntityAttributeAccess (t * testing.T ) {
@@ -465,7 +485,7 @@ func TestDirectEntityAttributeAccess(t *testing.T) {
465
485
466
486
if lastUpdateAttrValue , err := office .GetAttributeAsDateTime ("lastUpdate" ); err != nil {
467
487
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 () {
469
489
t .Fatalf ("Expected '%v' for lastUpdate value, got '%v'" , timeNow , lastUpdateAttrValue )
470
490
}
471
491
0 commit comments