Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@sousk
Last active March 12, 2018 07:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sousk/e8b53288c09b148f1a1cfa97a206d601 to your computer and use it in GitHub Desktop.
Save sousk/e8b53288c09b148f1a1cfa97a206d601 to your computer and use it in GitHub Desktop.
Test code to reproduce a mercari/datastore's bug
package aedatastore
import (
"testing"
"time"
"google.golang.org/appengine"
"google.golang.org/appengine/aetest"
)
func TestAEDatastore_DataTypes(t *testing.T) {
inst, err := aetest.NewInstance(&aetest.Options{StronglyConsistentDatastore: true})
if err != nil {
t.Fatal(err)
}
defer inst.Close()
r, err := inst.NewRequest("GET", "/", nil)
if err != nil {
t.Fatal(err)
}
ctx := appengine.NewContext(r)
type Location struct {
Lat float64 `json:"lat"`
Lng float64 `json:"lng"`
}
type LocalAccessID struct {
UserID int64 `datastore:"UserId"`
Location
}
type LocalAccess struct {
LocalAccessID
PreciseLocation Location `datastore:"PreciseLocation"`
Count int64 `datastore:"Count"`
UpdatedTime time.Time `datastore:"UpdatedTime"`
CreatedTime time.Time `datastore:"CreatedTime"`
}
client, err := FromContext(ctx)
if err != nil {
t.Fatal(err)
}
dat := &LocalAccess{
LocalAccessID: LocalAccessID{
UserID: 1,
Location: Location{10.78, 20.35},
},
PreciseLocation: Location{10.78, 20.35},
UpdatedTime: time.Now(),
CreatedTime: time.Now(),
}
key := client.NameKey("LocalAccess", "1-10.78-20.35", nil)
_, err = client.Put(ctx, key, &dat)
if err != nil {
t.Errorf("want nil; got %s", err)
}
}
package aedatastore
import (
"testing"
"google.golang.org/appengine/aetest"
"google.golang.org/appengine"
)
func TestAEDatastore_DataTypes(t *testing.T) {
inst, err := aetest.NewInstance(&aetest.Options{StronglyConsistentDatastore: true})
if err != nil {
t.Fatal(err)
}
defer inst.Close()
r, err := inst.NewRequest("GET", "/", nil)
if err != nil {
t.Fatal(err)
}
ctx := appengine.NewContext(r)
type Cheese struct {}
type Contains struct {
Cheese Cheese
ExtraCheese *Cheese
}
type Burger struct {
Contains
}
client, err := FromContext(ctx)
if err != nil {
t.Fatal(err)
}
burger := Burger{
Contains{
Cheese: Cheese{},
ExtraCheese: &Cheese{},
},
}
key := client.NameKey("DomDom","a", nil)
_, err = client.Put(ctx, key, &burger)
if err != nil {
t.Errorf("want nil; got %s", err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment