@@ -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
@@ -323,6 +324,9 @@ func TestEntityMarshal(t *testing.T) {
323
324
t .Fatal ("Expected an error for an invalid attribute" )
324
325
}
325
326
327
+ geoJsonPoint := geojson .NewPointGeometry ([]float64 {4.1 , 2.3 })
328
+ office .SetAttributeAsGeoJSON ("position" , geoJsonPoint )
329
+
326
330
bytes , err := json .Marshal (office )
327
331
if err != nil {
328
332
t .Fatalf ("Unexpected error: '%v'" , err )
@@ -436,6 +440,22 @@ func TestEntityMarshal(t *testing.T) {
436
440
}
437
441
}
438
442
}
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
+ }
439
459
}
440
460
441
461
func TestDirectEntityAttributeAccess (t * testing.T ) {
@@ -543,7 +563,7 @@ func TestDirectEntityAttributeAccess(t *testing.T) {
543
563
544
564
if lastUpdateAttrValue , err := office .GetAttributeAsDateTime ("lastUpdate" ); err != nil {
545
565
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 () {
547
567
t .Fatalf ("Expected '%v' for lastUpdate value, got '%v'" , timeNow , lastUpdateAttrValue )
548
568
}
549
569
0 commit comments