| Index: go/src/infra/gae/libs/gae/memory/raw_datstore_test.go
|
| diff --git a/go/src/infra/gae/libs/wrapper/memory/datastore_test.go b/go/src/infra/gae/libs/gae/memory/raw_datstore_test.go
|
| similarity index 56%
|
| rename from go/src/infra/gae/libs/wrapper/memory/datastore_test.go
|
| rename to go/src/infra/gae/libs/gae/memory/raw_datstore_test.go
|
| index 8ca4bd7db7e3434a62021050297837245ebb8319..d0c5100c806bc9aaf304cbcb88d3dbe232ae2339 100644
|
| --- a/go/src/infra/gae/libs/wrapper/memory/datastore_test.go
|
| +++ b/go/src/infra/gae/libs/gae/memory/raw_datstore_test.go
|
| @@ -6,224 +6,136 @@ package memory
|
|
|
| import (
|
| "fmt"
|
| - "infra/gae/libs/meta"
|
| - "infra/gae/libs/wrapper"
|
| + "infra/gae/libs/gae"
|
| + "infra/gae/libs/gae/helper"
|
| "math"
|
| "testing"
|
|
|
| . "github.com/smartystreets/goconvey/convey"
|
| "golang.org/x/net/context"
|
| -
|
| - "appengine/datastore"
|
| )
|
|
|
| func TestDatastoreKinder(t *testing.T) {
|
| t.Parallel()
|
|
|
| - Convey("Datastore kinds and keys", t, func() {
|
| + Convey("Datastore keys", t, func() {
|
| c := Use(context.Background())
|
| - ds := wrapper.GetDS(c)
|
| - So(ds, ShouldNotBeNil)
|
| -
|
| - Convey("implements DSKinder", func() {
|
| - type Foo struct{}
|
| - So(ds.Kind(&Foo{}), ShouldEqual, "Foo")
|
| -
|
| - Convey("which can be tweaked by DSKindSetter", func() {
|
| - ds.SetKindNameResolver(func(interface{}) string { return "spam" })
|
| - So(ds.Kind(&Foo{}), ShouldEqual, "spam")
|
| -
|
| - Convey("and it retains the function so you can stack them", func() {
|
| - cur := ds.KindNameResolver()
|
| - ds.SetKindNameResolver(func(o interface{}) string { return "wat" + cur(o) })
|
| - So(ds.Kind(&Foo{}), ShouldEqual, "watspam")
|
| - })
|
| - })
|
| - })
|
| + rds := gae.GetRDS(c)
|
| + So(rds, ShouldNotBeNil)
|
|
|
| Convey("implements DSNewKeyer", func() {
|
| Convey("NewKey", func() {
|
| - key := ds.NewKey("nerd", "stringID", 0, nil)
|
| + key := rds.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~my~app")
|
| + So(key.AppID(), ShouldEqual, "dev~app")
|
| So(key.Namespace(), ShouldEqual, "")
|
| So(key.String(), ShouldEqual, "/nerd,stringID")
|
| - So(key.Incomplete(), ShouldBeFalse)
|
| - So(keyValid("", key, userKeyOnly), ShouldBeTrue)
|
| -
|
| - chkey := ds.NewKey("wat", "", 100, key)
|
| - So(chkey, ShouldNotBeNil)
|
| - So(chkey.Kind(), ShouldEqual, "wat")
|
| - So(chkey.StringID(), ShouldEqual, "")
|
| - So(chkey.IntID(), ShouldEqual, 100)
|
| - So(chkey.Parent(), ShouldEqual, key)
|
| - So(chkey.AppID(), ShouldEqual, "dev~my~app")
|
| - So(chkey.Namespace(), ShouldEqual, "")
|
| - So(chkey.String(), ShouldEqual, "/nerd,stringID/wat,100")
|
| - So(key.Incomplete(), ShouldBeFalse)
|
| - So(keyValid("", chkey, userKeyOnly), ShouldBeTrue)
|
| -
|
| - incompl := ds.NewKey("sup", "", 0, key)
|
| - So(incompl, ShouldNotBeNil)
|
| - So(incompl.Incomplete(), ShouldBeTrue)
|
| - So(keyValid("", incompl, userKeyOnly), ShouldBeTrue)
|
| - So(incompl.String(), ShouldEqual, "/nerd,stringID/sup,0")
|
| -
|
| - bad := ds.NewKey("nooo", "", 10, incompl)
|
| - So(bad, ShouldNotBeNil)
|
| - So(bad.Incomplete(), ShouldBeFalse)
|
| - So(keyValid("", bad, userKeyOnly), ShouldBeFalse)
|
| - So(bad.String(), ShouldEqual, "/nerd,stringID/sup,0/nooo,10")
|
| -
|
| - So(rootKey(bad), ShouldEqual, key)
|
| -
|
| - Convey("other key validation", func() {
|
| - So(keyValid("", nil, userKeyOnly), ShouldBeFalse)
|
| -
|
| - key := ds.NewKey("", "", 0, nil)
|
| - So(key, ShouldNotBeNil)
|
| -
|
| - So(keyValid("", key, userKeyOnly), ShouldBeFalse)
|
| -
|
| - key = ds.NewKey("noop", "power level", 9000, nil)
|
| - So(key, ShouldNotBeNil)
|
| -
|
| - So(keyValid("", key, userKeyOnly), ShouldBeFalse)
|
| - })
|
| - })
|
| -
|
| - Convey("NewKeyObj", func() {
|
| - type Foo struct {
|
| - _knd string `goon:"kind,coool"`
|
| - ID int64 `goon:"id"`
|
| - Parent *datastore.Key `goon:"parent"`
|
| - }
|
| - f := &Foo{ID: 100}
|
| - k := ds.NewKeyObj(f)
|
| - So(k.String(), ShouldEqual, "/coool,100")
|
| -
|
| - f.Parent = k
|
| - f._knd = "weevils"
|
| - f.ID = 19
|
| - k = ds.NewKeyObj(f)
|
| - So(k.String(), ShouldEqual, "/coool,100/weevils,19")
|
| -
|
| - Convey("panics when you do a dumb thing", func() {
|
| - type Foo struct {
|
| - ID []byte `goon:"id"`
|
| - }
|
| - So(func() { ds.NewKeyObj(&Foo{}) }, ShouldPanic)
|
| - })
|
| - })
|
| -
|
| - Convey("NewKeyObjError", func() {
|
| - type Foo struct {
|
| - ID []byte `goon:"id"`
|
| - }
|
| - _, err := ds.NewKeyObjError(&Foo{})
|
| - So(err.Error(), ShouldContainSubstring, "must be int64 or string")
|
| + So(helper.DSKeyIncomplete(key), ShouldBeFalse)
|
| + So(helper.DSKeyValid(key, "", false), ShouldBeTrue)
|
| })
|
| })
|
|
|
| })
|
| }
|
|
|
| +func testGetMeta(c context.Context, k gae.DSKey) int64 {
|
| + rds := gae.GetRDS(c)
|
| + k = rds.NewKey("__entity_group__", "", 1, helper.DSKeyRoot(k))
|
| + pmap := gae.DSPropertyMap{}
|
| + rds.Get(k, &pmap)
|
| + return pmap["__version__"][0].Value().(int64)
|
| +}
|
| +
|
| func TestDatastoreSingleReadWriter(t *testing.T) {
|
| t.Parallel()
|
|
|
| Convey("Datastore single reads and writes", t, func() {
|
| c := Use(context.Background())
|
| - ds := wrapper.GetDS(c)
|
| - So(ds, ShouldNotBeNil)
|
| + rds := gae.GetRDS(c)
|
| + So(rds, ShouldNotBeNil)
|
|
|
| Convey("implements DSSingleReadWriter", func() {
|
| type Foo struct {
|
| - ID int64 `goon:"id" datastore:"-"`
|
| - Parent *datastore.Key `goon:"parent" datastore:"-"`
|
| - Val int
|
| + Val int
|
| }
|
|
|
| Convey("invalid keys break", func() {
|
| - k := ds.NewKeyObj(&Foo{})
|
| - f := &Foo{Parent: k}
|
| - So(ds.Get(f), ShouldEqual, datastore.ErrInvalidKey)
|
| + k := rds.NewKey("Foo", "", 0, nil)
|
| + So(rds.Get(k, nil), ShouldEqual, gae.ErrDSInvalidKey)
|
|
|
| - _, err := ds.Put(f)
|
| - So(err, ShouldEqual, datastore.ErrInvalidKey)
|
| + _, err := rds.Put(rds.NewKey("Foo", "", 0, k), &Foo{})
|
| + So(err, ShouldEqual, gae.ErrDSInvalidKey)
|
| })
|
|
|
| Convey("getting objects that DNE is an error", func() {
|
| - So(ds.Get(&Foo{ID: 1}), ShouldEqual, datastore.ErrNoSuchEntity)
|
| + k := rds.NewKey("Foo", "", 1, nil)
|
| + So(rds.Get(k, nil), ShouldEqual, gae.ErrDSNoSuchEntity)
|
| })
|
|
|
| Convey("Can Put stuff", func() {
|
| // with an incomplete key!
|
| + k := rds.NewKey("Foo", "", 0, nil)
|
| f := &Foo{Val: 10}
|
| - k, err := ds.Put(f)
|
| + k, err := rds.Put(k, f)
|
| So(err, ShouldBeNil)
|
| So(k.String(), ShouldEqual, "/Foo,1")
|
| - So(ds.NewKeyObj(f), ShouldResemble, k)
|
|
|
| Convey("and Get it back", func() {
|
| - newFoo := &Foo{ID: 1}
|
| - err := ds.Get(newFoo)
|
| + newFoo := &Foo{}
|
| + err := rds.Get(k, newFoo)
|
| So(err, ShouldBeNil)
|
| So(newFoo, ShouldResemble, f)
|
|
|
| Convey("and we can Delete it", func() {
|
| - err := ds.Delete(ds.NewKey("Foo", "", 1, nil))
|
| + err := rds.Delete(k)
|
| So(err, ShouldBeNil)
|
|
|
| - err = ds.Get(newFoo)
|
| - So(err, ShouldEqual, datastore.ErrNoSuchEntity)
|
| + err = rds.Get(k, newFoo)
|
| + So(err, ShouldEqual, gae.ErrDSNoSuchEntity)
|
| })
|
| })
|
| Convey("Deleteing with a bogus key is bad", func() {
|
| - err := ds.Delete(ds.NewKey("Foo", "wat", 100, nil))
|
| - So(err, ShouldEqual, datastore.ErrInvalidKey)
|
| + err := rds.Delete(rds.NewKey("Foo", "wat", 100, nil))
|
| + So(err, ShouldEqual, gae.ErrDSInvalidKey)
|
| })
|
| Convey("Deleteing a DNE entity is fine", func() {
|
| - err := ds.Delete(ds.NewKey("Foo", "wat", 0, nil))
|
| + err := rds.Delete(rds.NewKey("Foo", "wat", 0, nil))
|
| So(err, ShouldBeNil)
|
| })
|
|
|
| Convey("serialization breaks in the normal ways", func() {
|
| type BadFoo struct {
|
| - _kind string `goon:"kind,Foo"`
|
| - ID int64 `goon:"id" datastore:"-"`
|
| - Val uint8
|
| + Val uint8
|
| }
|
| - _, err := ds.Put(&BadFoo{})
|
| - So(err.Error(), ShouldContainSubstring,
|
| - "unsupported struct field type: uint8")
|
| + _, err := rds.Put(k, &BadFoo{})
|
| + So(err.Error(), ShouldContainSubstring, "invalid type: uint8")
|
|
|
| - err = ds.Get(&BadFoo{ID: 1})
|
| - So(err.Error(), ShouldContainSubstring,
|
| - "type mismatch: int versus uint8")
|
| + err = rds.Get(k, &BadFoo{})
|
| + So(err.Error(), ShouldContainSubstring, "invalid type: uint8")
|
| })
|
|
|
| Convey("check that metadata works", func() {
|
| - val, _ := meta.GetEntityGroupVersion(c, k)
|
| - So(val, ShouldEqual, 1)
|
| + So(testGetMeta(c, k), ShouldEqual, 1)
|
|
|
| + pkey := k
|
| for i := 0; i < 10; i++ {
|
| - _, err = ds.Put(&Foo{Val: 10, Parent: k})
|
| + k := rds.NewKey("Foo", "", 0, pkey)
|
| + _, err = rds.Put(k, &Foo{Val: 10})
|
| So(err, ShouldBeNil)
|
| }
|
| - val, _ = meta.GetEntityGroupVersion(c, k)
|
| - So(val, ShouldEqual, 11)
|
| + So(testGetMeta(c, k), ShouldEqual, 11)
|
|
|
| Convey("ensure that group versions persist across deletes", func() {
|
| - So(ds.Delete(k), ShouldBeNil)
|
| + So(rds.Delete(k), ShouldBeNil)
|
| for i := int64(1); i < 11; i++ {
|
| - So(ds.Delete(ds.NewKey("Foo", "", i, k)), ShouldBeNil)
|
| + So(rds.Delete(rds.NewKey("Foo", "", i, k)), ShouldBeNil)
|
| }
|
| // TODO(riannucci): replace with a Count query instead of this cast
|
| - ents := ds.(*dsImpl).data.store.GetCollection("ents:")
|
| + ents := rds.(*dsImpl).data.store.GetCollection("ents:")
|
| num, _ := ents.GetTotals()
|
| // /__entity_root_ids__,Foo
|
| // /Foo,1/__entity_group__,1
|
| @@ -234,10 +146,9 @@ func TestDatastoreSingleReadWriter(t *testing.T) {
|
| So(err, ShouldBeNil)
|
| So(version, ShouldEqual, 22)
|
|
|
| - k, err := ds.Put(f)
|
| + k, err := rds.Put(k, f)
|
| So(err, ShouldBeNil)
|
| - val, _ := meta.GetEntityGroupVersion(c, k)
|
| - So(val, ShouldEqual, 23)
|
| + So(testGetMeta(c, k), ShouldEqual, 23)
|
| })
|
| })
|
| })
|
| @@ -245,57 +156,57 @@ func TestDatastoreSingleReadWriter(t *testing.T) {
|
|
|
| Convey("implements DSTransactioner", func() {
|
| type Foo struct {
|
| - ID int64 `goon:"id" datastore:"-"`
|
| - Parent *datastore.Key `goon:"parent" datastore:"-"`
|
| - Val int
|
| + Val int
|
| }
|
| Convey("Put", func() {
|
| + k := rds.NewKey("Foo", "", 0, nil)
|
| f := &Foo{Val: 10}
|
| - k, err := ds.Put(f)
|
| + k, err := rds.Put(k, f)
|
| So(err, ShouldBeNil)
|
| So(k.String(), ShouldEqual, "/Foo,1")
|
| - So(ds.NewKeyObj(f), ShouldResemble, k)
|
|
|
| Convey("can Put new entity groups", func() {
|
| - err := ds.RunInTransaction(func(c context.Context) error {
|
| - ds := wrapper.GetDS(c)
|
| - So(ds, ShouldNotBeNil)
|
| + err := rds.RunInTransaction(func(c context.Context) error {
|
| + rds := gae.GetRDS(c)
|
| + So(rds, ShouldNotBeNil)
|
|
|
| f1 := &Foo{Val: 100}
|
| - k, err := ds.Put(f1)
|
| + k, err := rds.Put(rds.NewKey("Foo", "", 0, nil), f1)
|
| So(err, ShouldBeNil)
|
| So(k.String(), ShouldEqual, "/Foo,2")
|
|
|
| f2 := &Foo{Val: 200}
|
| - k, err = ds.Put(f2)
|
| + k, err = rds.Put(rds.NewKey("Foo", "", 0, nil), f2)
|
| So(err, ShouldBeNil)
|
| So(k.String(), ShouldEqual, "/Foo,3")
|
|
|
| return nil
|
| - }, &datastore.TransactionOptions{XG: true})
|
| + }, &gae.DSTransactionOptions{XG: true})
|
| So(err, ShouldBeNil)
|
|
|
| - f := &Foo{ID: 2}
|
| - So(ds.Get(f), ShouldBeNil)
|
| + f := &Foo{}
|
| + So(rds.Get(rds.NewKey("Foo", "", 2, nil), f), ShouldBeNil)
|
| So(f.Val, ShouldEqual, 100)
|
|
|
| - f = &Foo{ID: 3}
|
| - So(ds.Get(f), ShouldBeNil)
|
| + f = &Foo{}
|
| + So(rds.Get(rds.NewKey("Foo", "", 3, nil), f), ShouldBeNil)
|
| So(f.Val, ShouldEqual, 200)
|
| })
|
|
|
| Convey("can Put new entities in a current group", func() {
|
| - err := ds.RunInTransaction(func(c context.Context) error {
|
| - ds := wrapper.GetDS(c)
|
| - So(ds, ShouldNotBeNil)
|
| + err := rds.RunInTransaction(func(c context.Context) error {
|
| + rds := gae.GetRDS(c)
|
| + So(rds, ShouldNotBeNil)
|
| +
|
| + par := k
|
|
|
| - f1 := &Foo{Val: 100, Parent: ds.NewKeyObj(f)}
|
| - k, err := ds.Put(f1)
|
| + f1 := &Foo{Val: 100}
|
| + k, err := rds.Put(rds.NewKey("Foo", "", 0, par), f1)
|
| So(err, ShouldBeNil)
|
| So(k.String(), ShouldEqual, "/Foo,1/Foo,1")
|
|
|
| - f2 := &Foo{Val: 200, Parent: ds.NewKeyObj(f)}
|
| - k, err = ds.Put(f2)
|
| + f2 := &Foo{Val: 200}
|
| + k, err = rds.Put(rds.NewKey("Foo", "", 0, par), f2)
|
| So(err, ShouldBeNil)
|
| So(k.String(), ShouldEqual, "/Foo,1/Foo,2")
|
|
|
| @@ -303,115 +214,113 @@ func TestDatastoreSingleReadWriter(t *testing.T) {
|
| }, nil)
|
| So(err, ShouldBeNil)
|
|
|
| - f1 := &Foo{ID: 1, Parent: ds.NewKeyObj(&Foo{ID: 1})}
|
| - So(ds.Get(f1), ShouldBeNil)
|
| + f1 := &Foo{}
|
| + So(rds.Get(rds.NewKey("Foo", "", 1, k), f1), ShouldBeNil)
|
| So(f1.Val, ShouldEqual, 100)
|
|
|
| - f2 := &Foo{ID: 2, Parent: f1.Parent}
|
| - So(ds.Get(f2), ShouldBeNil)
|
| + f2 := &Foo{}
|
| + So(rds.Get(rds.NewKey("Foo", "", 2, k), f2), ShouldBeNil)
|
| So(f2.Val, ShouldEqual, 200)
|
| })
|
|
|
| Convey("Deletes work too", func() {
|
| - err := ds.RunInTransaction(func(c context.Context) error {
|
| - ds := wrapper.GetDS(c)
|
| - So(ds, ShouldNotBeNil)
|
| - So(ds.Delete(ds.NewKeyObj(f)), ShouldBeNil)
|
| + err := rds.RunInTransaction(func(c context.Context) error {
|
| + rds := gae.GetRDS(c)
|
| + So(rds, ShouldNotBeNil)
|
| + So(rds.Delete(k), ShouldBeNil)
|
| return nil
|
| }, nil)
|
| So(err, ShouldBeNil)
|
| - So(ds.Get(f), ShouldEqual, datastore.ErrNoSuchEntity)
|
| + So(rds.Get(k, f), ShouldEqual, gae.ErrDSNoSuchEntity)
|
| })
|
|
|
| Convey("A Get counts against your group count", func() {
|
| - err := ds.RunInTransaction(func(c context.Context) error {
|
| - ds := wrapper.GetDS(c)
|
| - f := &Foo{ID: 20}
|
| - So(ds.Get(f), ShouldEqual, datastore.ErrNoSuchEntity)
|
| + err := rds.RunInTransaction(func(c context.Context) error {
|
| + rds := gae.GetRDS(c)
|
| + f := &Foo{}
|
| + So(rds.Get(rds.NewKey("Foo", "", 20, nil), f), ShouldEqual, gae.ErrDSNoSuchEntity)
|
|
|
| - f.ID = 1
|
| - So(ds.Get(f).Error(), ShouldContainSubstring, "cross-group")
|
| + So(rds.Get(k, f).Error(), ShouldContainSubstring, "cross-group")
|
| return nil
|
| }, nil)
|
| So(err, ShouldBeNil)
|
| })
|
|
|
| Convey("Get takes a snapshot", func() {
|
| - err := ds.RunInTransaction(func(c context.Context) error {
|
| - txnDS := wrapper.GetDS(c)
|
| + err := rds.RunInTransaction(func(c context.Context) error {
|
| + txnDS := gae.GetRDS(c)
|
| So(txnDS, ShouldNotBeNil)
|
|
|
| - f := &Foo{ID: 1}
|
| - So(txnDS.Get(f), ShouldBeNil)
|
| + So(txnDS.Get(k, f), ShouldBeNil)
|
| So(f.Val, ShouldEqual, 10)
|
|
|
| // Don't ever do this in a real program unless you want to guarantee
|
| // a failed transaction :)
|
| f.Val = 11
|
| - _, err := ds.Put(f)
|
| + _, err := rds.Put(k, f)
|
| So(err, ShouldBeNil)
|
|
|
| - So(txnDS.Get(f), ShouldBeNil)
|
| + So(txnDS.Get(k, f), ShouldBeNil)
|
| So(f.Val, ShouldEqual, 10)
|
|
|
| return nil
|
| }, nil)
|
| So(err, ShouldBeNil)
|
|
|
| - f := &Foo{ID: 1}
|
| - So(ds.Get(f), ShouldBeNil)
|
| + f := &Foo{}
|
| + So(rds.Get(k, f), ShouldBeNil)
|
| So(f.Val, ShouldEqual, 11)
|
| -
|
| })
|
|
|
| Convey("and snapshots are consistent even after Puts", func() {
|
| - err := ds.RunInTransaction(func(c context.Context) error {
|
| - txnDS := wrapper.GetDS(c)
|
| + err := rds.RunInTransaction(func(c context.Context) error {
|
| + txnDS := gae.GetRDS(c)
|
| So(txnDS, ShouldNotBeNil)
|
|
|
| - f := &Foo{ID: 1}
|
| - So(txnDS.Get(f), ShouldBeNil)
|
| + f := &Foo{}
|
| + So(txnDS.Get(k, f), ShouldBeNil)
|
| So(f.Val, ShouldEqual, 10)
|
|
|
| // Don't ever do this in a real program unless you want to guarantee
|
| // a failed transaction :)
|
| f.Val = 11
|
| - _, err := ds.Put(f)
|
| + _, err := rds.Put(k, f)
|
| So(err, ShouldBeNil)
|
|
|
| - So(txnDS.Get(f), ShouldBeNil)
|
| + So(txnDS.Get(k, f), ShouldBeNil)
|
| So(f.Val, ShouldEqual, 10)
|
|
|
| f.Val = 20
|
| - _, err = txnDS.Put(f)
|
| + _, err = txnDS.Put(k, f)
|
| So(err, ShouldBeNil)
|
|
|
| - So(txnDS.Get(f), ShouldBeNil)
|
| + So(txnDS.Get(k, f), ShouldBeNil)
|
| So(f.Val, ShouldEqual, 10) // still gets 10
|
|
|
| return nil
|
| }, nil)
|
| So(err.Error(), ShouldContainSubstring, "concurrent")
|
|
|
| - f := &Foo{ID: 1}
|
| - So(ds.Get(f), ShouldBeNil)
|
| + f := &Foo{}
|
| + So(rds.Get(k, f), ShouldBeNil)
|
| So(f.Val, ShouldEqual, 11)
|
| })
|
|
|
| Convey("Reusing a transaction context is bad news", func() {
|
| - txnDS := wrapper.Datastore(nil)
|
| - err := ds.RunInTransaction(func(c context.Context) error {
|
| - txnDS = wrapper.GetDS(c)
|
| - So(txnDS.Get(&Foo{ID: 1}), ShouldBeNil)
|
| + k := rds.NewKey("Foo", "", 1, nil)
|
| + txnDS := gae.RawDatastore(nil)
|
| + err := rds.RunInTransaction(func(c context.Context) error {
|
| + txnDS = gae.GetRDS(c)
|
| + So(txnDS.Get(k, &Foo{}), ShouldBeNil)
|
| return nil
|
| }, nil)
|
| So(err, ShouldBeNil)
|
| - So(txnDS.Get(&Foo{ID: 1}).Error(), ShouldContainSubstring, "expired")
|
| + So(txnDS.Get(k, &Foo{}).Error(), ShouldContainSubstring, "expired")
|
| })
|
|
|
| Convey("Nested transactions are rejected", func() {
|
| - err := ds.RunInTransaction(func(c context.Context) error {
|
| - err := wrapper.GetDS(c).RunInTransaction(func(c context.Context) error {
|
| + err := rds.RunInTransaction(func(c context.Context) error {
|
| + err := gae.GetRDS(c).RunInTransaction(func(c context.Context) error {
|
| panic("noooo")
|
| }, nil)
|
| So(err.Error(), ShouldContainSubstring, "nested transactions")
|
| @@ -428,16 +337,16 @@ func TestDatastoreSingleReadWriter(t *testing.T) {
|
| // entity group as soon as something observes/affects it.
|
| //
|
| // That said... I'm not sure if there's really a semantic difference.
|
| - err := ds.RunInTransaction(func(c context.Context) error {
|
| - txnDS := wrapper.GetDS(c)
|
| - f := &Foo{ID: 1, Val: 21}
|
| - _, err = txnDS.Put(f)
|
| + err := rds.RunInTransaction(func(c context.Context) error {
|
| + txnDS := gae.GetRDS(c)
|
| + f := &Foo{Val: 21}
|
| + _, err = txnDS.Put(k, f)
|
| So(err, ShouldBeNil)
|
|
|
| - err := ds.RunInTransaction(func(c context.Context) error {
|
| - txnDS := wrapper.GetDS(c)
|
| - f := &Foo{ID: 1, Val: 27}
|
| - _, err := txnDS.Put(f)
|
| + err := rds.RunInTransaction(func(c context.Context) error {
|
| + txnDS := gae.GetRDS(c)
|
| + f := &Foo{Val: 27}
|
| + _, err := txnDS.Put(k, f)
|
| So(err, ShouldBeNil)
|
| return nil
|
| }, nil)
|
| @@ -447,21 +356,20 @@ func TestDatastoreSingleReadWriter(t *testing.T) {
|
| }, nil)
|
| So(err.Error(), ShouldContainSubstring, "concurrent")
|
|
|
| - f := &Foo{ID: 1}
|
| - So(ds.Get(f), ShouldBeNil)
|
| + f := &Foo{}
|
| + So(rds.Get(k, f), ShouldBeNil)
|
| So(f.Val, ShouldEqual, 27)
|
| })
|
|
|
| Convey("XG", func() {
|
| Convey("Modifying two groups with XG=false is invalid", func() {
|
| - err := ds.RunInTransaction(func(c context.Context) error {
|
| - ds := wrapper.GetDS(c)
|
| - f := &Foo{ID: 1, Val: 200}
|
| - _, err := ds.Put(f)
|
| + err := rds.RunInTransaction(func(c context.Context) error {
|
| + rds := gae.GetRDS(c)
|
| + f := &Foo{Val: 200}
|
| + _, err := rds.Put(k, f)
|
| So(err, ShouldBeNil)
|
|
|
| - f.ID = 2
|
| - _, err = ds.Put(f)
|
| + _, err = rds.Put(rds.NewKey("Foo", "", 2, nil), f)
|
| So(err.Error(), ShouldContainSubstring, "cross-group")
|
| return err
|
| }, nil)
|
| @@ -469,52 +377,53 @@ func TestDatastoreSingleReadWriter(t *testing.T) {
|
| })
|
|
|
| Convey("Modifying >25 groups with XG=true is invald", func() {
|
| - err := ds.RunInTransaction(func(c context.Context) error {
|
| - ds := wrapper.GetDS(c)
|
| + err := rds.RunInTransaction(func(c context.Context) error {
|
| + rds := gae.GetRDS(c)
|
| for i := int64(1); i < 26; i++ {
|
| - f := &Foo{ID: i, Val: 200}
|
| - _, err := ds.Put(f)
|
| + k := rds.NewKey("Foo", "", i, nil)
|
| + f := &Foo{Val: 200}
|
| + _, err := rds.Put(k, f)
|
| So(err, ShouldBeNil)
|
| }
|
| - f := &Foo{ID: 27, Val: 200}
|
| - _, err := ds.Put(f)
|
| + f := &Foo{Val: 200}
|
| + _, err := rds.Put(rds.NewKey("Foo", "", 27, nil), f)
|
| So(err.Error(), ShouldContainSubstring, "too many entity groups")
|
| return err
|
| - }, &datastore.TransactionOptions{XG: true})
|
| + }, &gae.DSTransactionOptions{XG: true})
|
| So(err.Error(), ShouldContainSubstring, "too many entity groups")
|
| })
|
| })
|
|
|
| Convey("Errors and panics", func() {
|
| Convey("returning an error aborts", func() {
|
| - err := ds.RunInTransaction(func(c context.Context) error {
|
| - ds := wrapper.GetDS(c)
|
| - f := &Foo{ID: 1, Val: 200}
|
| - _, err := ds.Put(f)
|
| + err := rds.RunInTransaction(func(c context.Context) error {
|
| + rds := gae.GetRDS(c)
|
| + f := &Foo{Val: 200}
|
| + _, err := rds.Put(k, f)
|
| So(err, ShouldBeNil)
|
|
|
| return fmt.Errorf("thingy")
|
| }, nil)
|
| So(err.Error(), ShouldEqual, "thingy")
|
|
|
| - f := &Foo{ID: 1}
|
| - So(ds.Get(f), ShouldBeNil)
|
| + f := &Foo{}
|
| + So(rds.Get(k, f), ShouldBeNil)
|
| So(f.Val, ShouldEqual, 10)
|
| })
|
|
|
| Convey("panicing aborts", func() {
|
| So(func() {
|
| - ds.RunInTransaction(func(c context.Context) error {
|
| - ds := wrapper.GetDS(c)
|
| - f := &Foo{ID: 1, Val: 200}
|
| - _, err := ds.Put(f)
|
| + rds.RunInTransaction(func(c context.Context) error {
|
| + rds := gae.GetRDS(c)
|
| + f := &Foo{Val: 200}
|
| + _, err := rds.Put(k, f)
|
| So(err, ShouldBeNil)
|
| panic("wheeeeee")
|
| }, nil)
|
| }, ShouldPanic)
|
|
|
| - f := &Foo{ID: 1}
|
| - So(ds.Get(f), ShouldBeNil)
|
| + f := &Foo{}
|
| + So(rds.Get(k, f), ShouldBeNil)
|
| So(f.Val, ShouldEqual, 10)
|
| })
|
| })
|
| @@ -531,11 +440,11 @@ const IntIs32Bits = int64(MaxInt) < math.MaxInt64
|
| func TestDatastoreQueryer(t *testing.T) {
|
| Convey("Datastore Query suport", t, func() {
|
| c := Use(context.Background())
|
| - ds := wrapper.GetDS(c)
|
| - So(ds, ShouldNotBeNil)
|
| + rds := gae.GetRDS(c)
|
| + So(rds, ShouldNotBeNil)
|
|
|
| Convey("can create good queries", func() {
|
| - q := ds.NewQuery("Foo").KeysOnly().Limit(10).Offset(39)
|
| + q := rds.NewQuery("Foo").KeysOnly().Limit(10).Offset(39)
|
| q = q.Start(queryCursor("kosmik")).End(queryCursor("krabs"))
|
| So(q, ShouldNotBeNil)
|
| So(q.(*queryImpl).err, ShouldBeNil)
|
| @@ -544,7 +453,7 @@ func TestDatastoreQueryer(t *testing.T) {
|
| })
|
|
|
| Convey("normalize ensures orders make sense", func() {
|
| - q := ds.NewQuery("Cool")
|
| + q := rds.NewQuery("Cool")
|
| q = q.Filter("cat =", 19).Filter("bob =", 10).Order("bob").Order("bob")
|
|
|
| Convey("removes dups and equality orders", func() {
|
| @@ -564,7 +473,7 @@ func TestDatastoreQueryer(t *testing.T) {
|
|
|
| Convey("if we equality-filter on __key__, order is ditched", func() {
|
| q = q.Order("wat")
|
| - q := q.Filter("__key__ =", ds.NewKey("Foo", "wat", 0, nil))
|
| + q := q.Filter("__key__ =", rds.NewKey("Foo", "wat", 0, nil))
|
| qi := q.(*queryImpl).normalize().checkCorrectness("", false)
|
| So(qi.order, ShouldResemble, []queryOrder(nil))
|
| So(qi.err, ShouldBeNil)
|
| @@ -579,7 +488,7 @@ func TestDatastoreQueryer(t *testing.T) {
|
| })
|
|
|
| Convey("can create bad queries", func() {
|
| - q := ds.NewQuery("Foo")
|
| + q := rds.NewQuery("Foo")
|
|
|
| Convey("bad filter ops", func() {
|
| q := q.Filter("Bob !", "value")
|
| @@ -620,26 +529,26 @@ func TestDatastoreQueryer(t *testing.T) {
|
| So(q.(*queryImpl).err.Error(), ShouldContainSubstring, "invalid cursor")
|
| })
|
| Convey("Bad ancestors", func() {
|
| - q := q.Ancestor(ds.NewKey("Goop", "wat", 10, nil))
|
| + q := q.Ancestor(rds.NewKey("Goop", "wat", 10, nil))
|
| So(q, ShouldNotBeNil)
|
| qi := q.(*queryImpl).checkCorrectness("", false)
|
| - So(qi.err, ShouldEqual, datastore.ErrInvalidKey)
|
| + So(qi.err, ShouldEqual, gae.ErrDSInvalidKey)
|
| })
|
| Convey("nil ancestors", func() {
|
| qi := q.Ancestor(nil).(*queryImpl).checkCorrectness("", false)
|
| So(qi.err.Error(), ShouldContainSubstring, "nil query ancestor")
|
| })
|
| Convey("Bad key filters", func() {
|
| - q := q.Filter("__key__ =", ds.NewKey("Goop", "wat", 10, nil))
|
| + q := q.Filter("__key__ =", rds.NewKey("Goop", "wat", 10, nil))
|
| qi := q.(*queryImpl).checkCorrectness("", false)
|
| - So(qi.err, ShouldEqual, datastore.ErrInvalidKey)
|
| + So(qi.err, ShouldEqual, gae.ErrDSInvalidKey)
|
| })
|
| Convey("non-ancestor queries in a transaction", func() {
|
| qi := q.(*queryImpl).checkCorrectness("", true)
|
| So(qi.err.Error(), ShouldContainSubstring, "Only ancestor queries")
|
| })
|
| Convey("absurd numbers of filters are prohibited", func() {
|
| - q := q.Ancestor(ds.NewKey("thing", "wat", 0, nil))
|
| + q := q.Ancestor(rds.NewKey("thing", "wat", 0, nil))
|
| for i := 0; i < 100; i++ {
|
| q = q.Filter("something =", 10)
|
| }
|
| @@ -662,17 +571,17 @@ func TestDatastoreQueryer(t *testing.T) {
|
| So(qi.err.Error(), ShouldContainSubstring, "first sort property")
|
| })
|
| Convey("kindless with non-__key__ filters", func() {
|
| - q := ds.NewQuery("").Filter("face <", 25.3)
|
| + q := rds.NewQuery("").Filter("face <", 25.3)
|
| qi := q.(*queryImpl).checkCorrectness("", false)
|
| So(qi.err.Error(), ShouldContainSubstring, "kind is required for non-__key__")
|
| })
|
| Convey("kindless with non-__key__ orders", func() {
|
| - q := ds.NewQuery("").Order("face")
|
| + q := rds.NewQuery("").Order("face")
|
| qi := q.(*queryImpl).checkCorrectness("", false)
|
| So(qi.err.Error(), ShouldContainSubstring, "kind is required for all orders")
|
| })
|
| Convey("kindless with decending-__key__ orders", func() {
|
| - q := ds.NewQuery("").Order("-__key__")
|
| + q := rds.NewQuery("").Order("-__key__")
|
| qi := q.(*queryImpl).checkCorrectness("", false)
|
| So(qi.err.Error(), ShouldContainSubstring, "kind is required for all orders")
|
| })
|
|
|