Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Unified Diff: impl/memory/datastore_test.go

Issue 1355783002: Refactor keys and queries in datastore service and implementation. (Closed) Base URL: https://github.com/luci/gae.git@master
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: impl/memory/datastore_test.go
diff --git a/impl/memory/datastore_test.go b/impl/memory/datastore_test.go
index 9eb4e286f57bf315b3e8ee8d64fd6208725a0f4c..d86f64f31b0a8ad966df1ea10b4bbe7008074288 100644
--- a/impl/memory/datastore_test.go
+++ b/impl/memory/datastore_test.go
@@ -10,51 +10,23 @@ import (
"time"
dsS "github.com/luci/gae/service/datastore"
- "github.com/luci/gae/service/datastore/dskey"
"github.com/luci/gae/service/datastore/serialize"
infoS "github.com/luci/gae/service/info"
. "github.com/smartystreets/goconvey/convey"
"golang.org/x/net/context"
)
-func TestDatastoreKinder(t *testing.T) {
- t.Parallel()
-
- Convey("Datastore keys", t, func() {
- c := Use(context.Background())
- ds := dsS.Get(c)
- So(ds, ShouldNotBeNil)
-
- Convey("implements DSNewKeyer", func() {
- Convey("NewKey", func() {
- key := ds.NewKey("nerd", "stringID", 0, nil)
- So(key, ShouldNotBeNil)
- So(key.Kind(), ShouldEqual, "nerd")
- So(key.StringID(), ShouldEqual, "stringID")
- So(key.IntID(), ShouldEqual, 0)
- So(key.Parent(), ShouldBeNil)
- So(key.AppID(), ShouldEqual, "dev~app")
- So(key.Namespace(), ShouldEqual, "")
- So(key.String(), ShouldEqual, "/nerd,stringID")
- So(key.Incomplete(), ShouldBeFalse)
- So(key.Valid(false, "dev~app", ""), ShouldBeTrue)
- })
- })
-
- })
-}
-
type MetaGroup struct {
- _id int64 `gae:"$id,1"`
- _kind string `gae:"$kind,__entity_group__"`
- Parent dsS.Key `gae:"$parent"`
+ _id int64 `gae:"$id,1"`
+ _kind string `gae:"$kind,__entity_group__"`
+ Parent *dsS.Key `gae:"$parent"`
Version int64 `gae:"__version__"`
}
-func testGetMeta(c context.Context, k dsS.Key) int64 {
+func testGetMeta(c context.Context, k *dsS.Key) int64 {
ds := dsS.Get(c)
- mg := &MetaGroup{Parent: dskey.Root(k)}
+ mg := &MetaGroup{Parent: k.Root()}
if err := ds.Get(mg); err != nil {
panic(err)
}
@@ -64,8 +36,8 @@ func testGetMeta(c context.Context, k dsS.Key) int64 {
var pls = dsS.GetPLS
type Foo struct {
- Id int64 `gae:"$id"`
- Parent dsS.Key `gae:"$parent"`
+ Id int64 `gae:"$id"`
+ Parent *dsS.Key `gae:"$parent"`
Val int
}
@@ -92,7 +64,7 @@ func TestDatastoreSingleReadWriter(t *testing.T) {
f := &Foo{Val: 10}
So(ds.Put(f), ShouldBeNil)
k := ds.KeyForObj(f)
- So(k.String(), ShouldEqual, "/Foo,1")
+ So(k.String(), ShouldEqual, "dev~app::/Foo,1")
iannucci 2015/09/18 04:31:52 I got pissed off at the Key string format not actu
Convey("and Get it back", func() {
newFoo := &Foo{Id: 1}
@@ -130,7 +102,7 @@ func TestDatastoreSingleReadWriter(t *testing.T) {
So(ds.PutMulti(foos), ShouldBeNil)
So(testGetMeta(c, k), ShouldEqual, 11)
- keys := make([]dsS.Key, len(foos))
+ keys := make([]*dsS.Key, len(foos))
for i, f := range foos {
keys[i] = ds.KeyForObj(&f)
}
@@ -178,7 +150,7 @@ func TestDatastoreSingleReadWriter(t *testing.T) {
f := &Foo{Val: 10}
So(ds.Put(f), ShouldBeNil)
k := ds.KeyForObj(f)
- So(k.String(), ShouldEqual, "/Foo,1")
+ So(k.String(), ShouldEqual, "dev~app::/Foo,1")
Convey("can Put new entity groups", func() {
err := ds.RunInTransaction(func(c context.Context) error {
@@ -212,12 +184,12 @@ func TestDatastoreSingleReadWriter(t *testing.T) {
f := &Foo{Val: 100, Parent: k}
So(ds.Put(f), ShouldBeNil)
- So(ds.KeyForObj(f).String(), ShouldEqual, "/Foo,1/Foo,1")
+ So(ds.KeyForObj(f).String(), ShouldEqual, "dev~app::/Foo,1/Foo,1")
f.Id = 0
f.Val = 200
So(ds.Put(f), ShouldBeNil)
- So(ds.KeyForObj(f).String(), ShouldEqual, "/Foo,1/Foo,2")
+ So(ds.KeyForObj(f).String(), ShouldEqual, "dev~app::/Foo,1/Foo,2")
return nil
}, nil)

Powered by Google App Engine
This is Rietveld 408576698