forked from mercari/datastore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
geopoint.go
66 lines (57 loc) · 1.25 KB
/
geopoint.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package testsuite
import (
"context"
"testing"
"go.mercari.io/datastore"
)
func geoPointPutAndGet(ctx context.Context, t *testing.T, client datastore.Client) {
defer func() {
err := client.Close()
if err != nil {
t.Fatal(err)
}
}()
// NOTE *datastore.GeoPoint is not officially supported by Datastore.
// it convert to *datastore.Entity, but AEDatastore is not supported it.
type Data struct {
A datastore.GeoPoint
B []datastore.GeoPoint
}
obj := &Data{
A: datastore.GeoPoint{Lat: 1.1, Lng: 2.2},
B: []datastore.GeoPoint{
{Lat: 5.5, Lng: 6.6},
{Lat: 7.7, Lng: 8.8},
},
}
key, err := client.Put(ctx, client.IncompleteKey("Data", nil), obj)
if err != nil {
t.Fatal(err)
}
obj = &Data{}
err = client.Get(ctx, key, obj)
if err != nil {
t.Fatal(err)
}
if v := obj.A.Lat; v != 1.1 {
t.Errorf("unexpected: %v", v)
}
if v := obj.A.Lng; v != 2.2 {
t.Errorf("unexpected: %v", v)
}
if v := len(obj.B); v != 2 {
t.Fatalf("unexpected: %v", v)
}
if v := obj.B[0].Lat; v != 5.5 {
t.Errorf("unexpected: %v", v)
}
if v := obj.B[0].Lng; v != 6.6 {
t.Errorf("unexpected: %v", v)
}
if v := obj.B[1].Lat; v != 7.7 {
t.Errorf("unexpected: %v", v)
}
if v := obj.B[1].Lng; v != 8.8 {
t.Errorf("unexpected: %v", v)
}
}