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