Last active
March 12, 2018 07:59
-
-
Save sousk/e8b53288c09b148f1a1cfa97a206d601 to your computer and use it in GitHub Desktop.
Test code to reproduce a mercari/datastore's bug
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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