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

Unified Diff: impl/memory/raw_datastore_test.go

Issue 1259593005: Add 'user friendly' datastore API. (Closed) Base URL: https://github.com/luci/gae.git@master
Patch Set: 100% coverage of new code Created 5 years, 4 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/raw_datastore_test.go
diff --git a/impl/memory/raw_datastore_test.go b/impl/memory/raw_datastore_test.go
index b0ca0b4abcedb49eb1a1495a3208ed5382709564..a19badc22bcbef38ce6ead960cc9913b0d311a3e 100644
--- a/impl/memory/raw_datastore_test.go
+++ b/impl/memory/raw_datastore_test.go
@@ -9,7 +9,8 @@ import (
"math"
"testing"
- rdsS "github.com/luci/gae/service/rawdatastore"
+ dsS "github.com/luci/gae/service/datastore"
+ infoS "github.com/luci/gae/service/info"
. "github.com/smartystreets/goconvey/convey"
"golang.org/x/net/context"
)
@@ -19,12 +20,12 @@ func TestDatastoreKinder(t *testing.T) {
Convey("Datastore keys", t, func() {
c := Use(context.Background())
- rds := rdsS.Get(c)
- So(rds, ShouldNotBeNil)
+ ds := dsS.Get(c)
+ So(ds, ShouldNotBeNil)
Convey("implements DSNewKeyer", func() {
Convey("NewKey", func() {
- key := rds.NewKey("nerd", "stringID", 0, nil)
+ key := ds.NewKey("nerd", "stringID", 0, nil)
So(key, ShouldNotBeNil)
So(key.Kind(), ShouldEqual, "nerd")
So(key.StringID(), ShouldEqual, "stringID")
@@ -33,338 +34,294 @@ func TestDatastoreKinder(t *testing.T) {
So(key.AppID(), ShouldEqual, "dev~app")
So(key.Namespace(), ShouldEqual, "")
So(key.String(), ShouldEqual, "/nerd,stringID")
- So(rdsS.KeyIncomplete(key), ShouldBeFalse)
- So(rdsS.KeyValid(key, false, "dev~app", ""), ShouldBeTrue)
+ So(dsS.KeyIncomplete(key), ShouldBeFalse)
+ So(dsS.KeyValid(key, false, "dev~app", ""), ShouldBeTrue)
})
})
})
}
-func testGetMeta(c context.Context, k rdsS.Key) int64 {
- rds := rdsS.Get(c)
- retval := int64(0)
- err := rds.GetMulti([]rdsS.Key{rds.NewKey("__entity_group__", "", 1, rdsS.KeyRoot(k))}, func(val rdsS.PropertyMap, err error) {
- if err != nil {
- panic(err)
- }
- retval = val["__version__"][0].Value().(int64)
- })
- if err != nil {
+type MetaGroup struct {
+ _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 {
+ ds := dsS.Get(c)
+ mg := &MetaGroup{Parent: dsS.KeyRoot(k)}
+ if err := ds.Get(mg); err != nil {
panic(err)
}
- return retval
+ return mg.Version
}
-var pls = rdsS.GetPLS
+var pls = dsS.GetPLS
+
+type Foo struct {
+ Id int64 `gae:"$id"`
+ Parent dsS.Key `gae:"$parent"`
+
+ Val int
+}
func TestDatastoreSingleReadWriter(t *testing.T) {
t.Parallel()
- getOnePM := func(rds rdsS.Interface, key rdsS.Key) (pmap rdsS.PropertyMap, err error) {
- blankErr := rds.GetMulti([]rdsS.Key{key}, func(itmPmap rdsS.PropertyMap, itmErr error) {
- pmap = itmPmap
- err = itmErr
- })
- So(blankErr, ShouldBeNil)
- return
- }
+ Convey("Datastore single reads and writes", t, func() {
+ c := Use(context.Background())
+ ds := dsS.Get(c)
+ So(ds, ShouldNotBeNil)
- delOneErr := func(rds rdsS.Interface, key rdsS.Key) (err error) {
- blankErr := rds.DeleteMulti([]rdsS.Key{key}, func(itmErr error) {
- err = itmErr
+ Convey("getting objects that DNE is an error", func() {
+ So(ds.Get(&Foo{Id: 1}), ShouldEqual, dsS.ErrNoSuchEntity)
})
- So(blankErr, ShouldBeNil)
- return
- }
- delOne := func(rds rdsS.Interface, key rdsS.Key) {
- So(delOneErr(rds, key), ShouldBeNil)
- }
-
- getOne := func(rds rdsS.Interface, key rdsS.Key, dst interface{}) {
- pm, err := getOnePM(rds, key)
- So(err, ShouldBeNil)
- So(pls(dst).Load(pm), ShouldBeNil)
- }
-
- putOneErr := func(rds rdsS.Interface, key rdsS.Key, val interface{}) (retKey rdsS.Key, err error) {
- blankErr := rds.PutMulti([]rdsS.Key{key}, []rdsS.PropertyLoadSaver{pls(val)}, func(itmKey rdsS.Key, itmErr error) {
- err = itmErr
- retKey = itmKey
+ Convey("bad namespaces fail", func() {
+ _, err := infoS.Get(c).Namespace("$$blzyall")
+ So(err.Error(), ShouldContainSubstring, "namespace \"$$blzyall\" does not match")
})
- So(blankErr, ShouldBeNil)
- return
- }
- putOne := func(rds rdsS.Interface, key rdsS.Key, val interface{}) (retKey rdsS.Key) {
- key, err := putOneErr(rds, key, val)
- So(err, ShouldBeNil)
- return key
- }
+ Convey("Can Put stuff", func() {
+ // with an incomplete key!
+ f := &Foo{Val: 10}
+ So(ds.Put(f), ShouldBeNil)
+ k := ds.KeyForObj(f)
+ So(k.String(), ShouldEqual, "/Foo,1")
- Convey("Datastore single reads and writes", t, func() {
- c := Use(context.Background())
- rds := rdsS.Get(c)
- So(rds, ShouldNotBeNil)
-
- Convey("implements DSSingleReadWriter", func() {
- type Foo struct {
- Val int
- }
+ Convey("and Get it back", func() {
+ newFoo := &Foo{Id: 1}
+ So(ds.Get(newFoo), ShouldBeNil)
+ So(newFoo, ShouldResemble, f)
- Convey("getting objects that DNE is an error", func() {
- _, err := getOnePM(rds, rds.NewKey("Foo", "", 1, nil))
- So(err, ShouldEqual, rdsS.ErrNoSuchEntity)
- })
+ Convey("but it's hidden from a different namespace", func() {
+ c, err := infoS.Get(c).Namespace("whombat")
+ So(err, ShouldBeNil)
+ ds = dsS.Get(c)
+ So(ds.Get(f), ShouldEqual, dsS.ErrNoSuchEntity)
+ })
- Convey("Can Put stuff", func() {
- // with an incomplete key!
- k := rds.NewKey("Foo", "", 0, nil)
- f := &Foo{Val: 10}
- k = putOne(rds, k, f)
- So(k.String(), ShouldEqual, "/Foo,1")
+ Convey("and we can Delete it", func() {
+ So(ds.Delete(k), ShouldBeNil)
+ So(ds.Get(newFoo), ShouldEqual, dsS.ErrNoSuchEntity)
+ })
- Convey("and Get it back", func() {
- newFoo := &Foo{}
- getOne(rds, k, newFoo)
- So(newFoo, ShouldResemble, f)
+ })
+ Convey("Deleteing with a bogus key is bad", func() {
+ So(ds.Delete(ds.NewKey("Foo", "wat", 100, nil)), ShouldEqual, dsS.ErrInvalidKey)
+ })
+ Convey("Deleteing a DNE entity is fine", func() {
+ So(ds.Delete(ds.NewKey("Foo", "wat", 0, nil)), ShouldBeNil)
+ })
- Convey("and we can Delete it", func() {
- delOne(rds, k)
- _, err := getOnePM(rds, k)
- So(err, ShouldEqual, rdsS.ErrNoSuchEntity)
- })
- })
- Convey("Deleteing with a bogus key is bad", func() {
- So(delOneErr(rds, rds.NewKey("Foo", "wat", 100, nil)), ShouldEqual, rdsS.ErrInvalidKey)
- })
- Convey("Deleteing a DNE entity is fine", func() {
- delOne(rds, rds.NewKey("Foo", "wat", 0, nil))
- })
+ Convey("with multiple puts", func() {
+ So(testGetMeta(c, k), ShouldEqual, 1)
- Convey("with multiple puts", func() {
- So(testGetMeta(c, k), ShouldEqual, 1)
+ foos := make([]Foo, 10)
+ for i := range foos {
+ foos[i].Val = 10
+ foos[i].Parent = k
+ }
+ So(ds.PutMulti(foos), ShouldBeNil)
+ So(testGetMeta(c, k), ShouldEqual, 11)
- keys := []rdsS.Key{}
- vals := []rdsS.PropertyLoadSaver{}
+ keys := make([]dsS.Key, len(foos))
+ for i, f := range foos {
+ keys[i] = ds.KeyForObj(&f)
+ }
- pkey := k
- for i := 0; i < 10; i++ {
- keys = append(keys, rds.NewKey("Foo", "", 0, pkey))
- vals = append(vals, pls(&Foo{Val: 10}))
- }
- i := 0
- err := rds.PutMulti(keys, vals, func(k rdsS.Key, err error) {
- So(err, ShouldBeNil)
- keys[i] = k
- i++
- })
- So(err, ShouldBeNil)
- So(testGetMeta(c, k), ShouldEqual, 11)
+ Convey("ensure that group versions persist across deletes", func() {
+ So(ds.DeleteMulti(append(keys, k)), ShouldBeNil)
- Convey("ensure that group versions persist across deletes", func() {
- keys = append(keys, pkey)
- err := rds.DeleteMulti(keys, func(err error) {
- So(err, ShouldBeNil)
- })
- So(err, ShouldBeNil)
+ // TODO(riannucci): replace with a Count query instead of this cast
+ /*
+ ents := ds.(*dsImpl).data.store.GetCollection("ents:")
+ num, _ := ents.GetTotals()
+ // /__entity_root_ids__,Foo
+ // /Foo,1/__entity_group__,1
+ // /Foo,1/__entity_group_ids__,1
+ So(num, ShouldEqual, 3)
+ */
- // TODO(riannucci): replace with a Count query instead of this cast
- /*
- ents := rds.(*dsImpl).data.store.GetCollection("ents:")
- num, _ := ents.GetTotals()
- // /__entity_root_ids__,Foo
- // /Foo,1/__entity_group__,1
- // /Foo,1/__entity_group_ids__,1
- So(num, ShouldEqual, 3)
- */
+ So(testGetMeta(c, k), ShouldEqual, 22)
- So(testGetMeta(c, k), ShouldEqual, 22)
+ So(ds.Put(&Foo{Id: 1}), ShouldBeNil)
+ So(testGetMeta(c, k), ShouldEqual, 23)
+ })
- putOne(rds, k, f)
- So(testGetMeta(c, k), ShouldEqual, 23)
- })
+ Convey("can Get", func() {
+ vals := make([]dsS.PropertyMap, len(keys))
+ for i := range vals {
+ vals[i] = dsS.PropertyMap{}
+ vals[i].SetMeta("key", keys[i])
+ }
+ So(ds.GetMulti(vals), ShouldBeNil)
- Convey("can Get", func() {
- vals := []rdsS.PropertyMap{}
- err := rds.GetMulti(keys, func(pm rdsS.PropertyMap, err error) {
- So(err, ShouldBeNil)
- vals = append(vals, pm)
+ for i, val := range vals {
+ So(val, ShouldResemble, dsS.PropertyMap{
+ "Val": {dsS.MkProperty(10)},
+ "$key": {dsS.MkPropertyNI(keys[i])},
})
- So(err, ShouldBeNil)
-
- for _, val := range vals {
- So(val, ShouldResemble, rdsS.PropertyMap{"Val": {rdsS.MkProperty(10)}})
- }
- })
+ }
})
+
})
})
Convey("implements DSTransactioner", func() {
- type Foo struct {
- Val int
- }
Convey("Put", func() {
f := &Foo{Val: 10}
- origKey := rds.NewKey("Foo", "", 0, nil)
- k := putOne(rds, origKey, f)
+ So(ds.Put(f), ShouldBeNil)
+ k := ds.KeyForObj(f)
So(k.String(), ShouldEqual, "/Foo,1")
Convey("can Put new entity groups", func() {
- err := rds.RunInTransaction(func(c context.Context) error {
- rds := rdsS.Get(c)
+ err := ds.RunInTransaction(func(c context.Context) error {
+ ds := dsS.Get(c)
- f1 := &Foo{Val: 100}
- k := putOne(rds, origKey, f1)
- So(k.String(), ShouldEqual, "/Foo,2")
+ f := &Foo{Val: 100}
+ So(ds.Put(f), ShouldBeNil)
+ So(f.Id, ShouldEqual, 2)
- f2 := &Foo{Val: 200}
- k = putOne(rds, origKey, f2)
- So(k.String(), ShouldEqual, "/Foo,3")
+ f.Id = 0
+ f.Val = 200
+ So(ds.Put(f), ShouldBeNil)
+ So(f.Id, ShouldEqual, 3)
return nil
- }, &rdsS.TransactionOptions{XG: true})
+ }, &dsS.TransactionOptions{XG: true})
So(err, ShouldBeNil)
- f := &Foo{}
- getOne(rds, rds.NewKey("Foo", "", 2, nil), f)
+ f := &Foo{Id: 2}
+ So(ds.Get(f), ShouldBeNil)
So(f.Val, ShouldEqual, 100)
- getOne(rds, rds.NewKey("Foo", "", 3, nil), f)
+ f.Id = 3
+ So(ds.Get(f), ShouldBeNil)
So(f.Val, ShouldEqual, 200)
})
Convey("can Put new entities in a current group", func() {
- par := k
- err := rds.RunInTransaction(func(c context.Context) error {
- rds := rdsS.Get(c)
- So(rds, ShouldNotBeNil)
+ err := ds.RunInTransaction(func(c context.Context) error {
+ ds := dsS.Get(c)
- f1 := &Foo{Val: 100}
- k := putOne(rds, rds.NewKey("Foo", "", 0, par), f1)
- So(k.String(), ShouldEqual, "/Foo,1/Foo,1")
+ f := &Foo{Val: 100, Parent: k}
+ So(ds.Put(f), ShouldBeNil)
+ So(ds.KeyForObj(f).String(), ShouldEqual, "/Foo,1/Foo,1")
- f2 := &Foo{Val: 200}
- k = putOne(rds, rds.NewKey("Foo", "", 0, par), f2)
- So(k.String(), ShouldEqual, "/Foo,1/Foo,2")
+ f.Id = 0
+ f.Val = 200
+ So(ds.Put(f), ShouldBeNil)
+ So(ds.KeyForObj(f).String(), ShouldEqual, "/Foo,1/Foo,2")
return nil
}, nil)
So(err, ShouldBeNil)
- f := &Foo{}
- getOne(rds, rds.NewKey("Foo", "", 1, k), f)
+ f := &Foo{Id: 1, Parent: k}
+ So(ds.Get(f), ShouldBeNil)
So(f.Val, ShouldEqual, 100)
- getOne(rds, rds.NewKey("Foo", "", 2, k), f)
+ f.Id = 2
+ So(ds.Get(f), ShouldBeNil)
So(f.Val, ShouldEqual, 200)
})
Convey("Deletes work too", func() {
- err := rds.RunInTransaction(func(c context.Context) error {
- rds := rdsS.Get(c)
- So(rds, ShouldNotBeNil)
- delOne(rds, k)
- return nil
+ err := ds.RunInTransaction(func(c context.Context) error {
+ return dsS.Get(c).Delete(k)
}, nil)
So(err, ShouldBeNil)
- _, err = getOnePM(rds, k)
- So(err, ShouldEqual, rdsS.ErrNoSuchEntity)
+ So(ds.Get(&Foo{Id: 1}), ShouldEqual, dsS.ErrNoSuchEntity)
})
Convey("A Get counts against your group count", func() {
- err := rds.RunInTransaction(func(c context.Context) error {
- rds := rdsS.Get(c)
+ err := ds.RunInTransaction(func(c context.Context) error {
+ ds := dsS.Get(c)
- _, err := getOnePM(rds, rds.NewKey("Foo", "", 20, nil))
- So(err, ShouldEqual, rdsS.ErrNoSuchEntity)
+ pm := dsS.PropertyMap{}
+ pm.SetMeta("key", ds.NewKey("Foo", "", 20, nil))
+ So(ds.Get(pm), ShouldEqual, dsS.ErrNoSuchEntity)
- err = rds.GetMulti([]rdsS.Key{k}, func(_ rdsS.PropertyMap, err error) {
- So(err, ShouldBeNil)
- })
- So(err.Error(), ShouldContainSubstring, "cross-group")
+ pm.SetMeta("key", k)
+ So(ds.Get(pm).Error(), ShouldContainSubstring, "cross-group")
return nil
}, nil)
So(err, ShouldBeNil)
})
Convey("Get takes a snapshot", func() {
- err := rds.RunInTransaction(func(c context.Context) error {
- txnDS := rdsS.Get(c)
- So(txnDS, ShouldNotBeNil)
+ err := ds.RunInTransaction(func(c context.Context) error {
+ txnDS := dsS.Get(c)
- getOne(txnDS, k, f)
+ So(txnDS.Get(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
- putOne(rds, k, f)
+ So(ds.Put(f), ShouldBeNil)
- getOne(txnDS, k, f)
+ So(txnDS.Get(f), ShouldBeNil)
So(f.Val, ShouldEqual, 10)
return nil
}, nil)
So(err, ShouldBeNil)
- f := &Foo{}
- getOne(rds, k, f)
+ f := &Foo{Id: 1}
+ So(ds.Get(f), ShouldBeNil)
So(f.Val, ShouldEqual, 11)
})
Convey("and snapshots are consistent even after Puts", func() {
- err := rds.RunInTransaction(func(c context.Context) error {
- txnDS := rdsS.Get(c)
- So(txnDS, ShouldNotBeNil)
+ err := ds.RunInTransaction(func(c context.Context) error {
+ txnDS := dsS.Get(c)
- f := &Foo{}
- getOne(txnDS, k, f)
+ f := &Foo{Id: 1}
+ So(txnDS.Get(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
- putOne(rds, k, f)
+ So(ds.Put(f), ShouldBeNil)
- getOne(txnDS, k, f)
+ So(txnDS.Get(f), ShouldBeNil)
So(f.Val, ShouldEqual, 10)
f.Val = 20
- putOne(txnDS, k, f)
+ So(txnDS.Put(f), ShouldBeNil)
- getOne(txnDS, k, f)
+ So(txnDS.Get(f), ShouldBeNil)
So(f.Val, ShouldEqual, 10) // still gets 10
return nil
}, nil)
So(err.Error(), ShouldContainSubstring, "concurrent")
- f := &Foo{}
- getOne(rds, k, f)
+ f := &Foo{Id: 1}
+ So(ds.Get(f), ShouldBeNil)
So(f.Val, ShouldEqual, 11)
})
Convey("Reusing a transaction context is bad news", func() {
- k := rds.NewKey("Foo", "", 1, nil)
- txnDS := rdsS.Interface(nil)
- err := rds.RunInTransaction(func(c context.Context) error {
- txnDS = rdsS.Get(c)
- getOnePM(txnDS, k)
+ txnDS := dsS.Interface(nil)
+ err := ds.RunInTransaction(func(c context.Context) error {
+ txnDS = dsS.Get(c)
+ So(txnDS.Get(f), ShouldBeNil)
return nil
}, nil)
So(err, ShouldBeNil)
- err = txnDS.GetMulti([]rdsS.Key{k}, func(_ rdsS.PropertyMap, err error) {
- So(err, ShouldBeNil)
- })
- So(err.Error(), ShouldContainSubstring, "expired")
+ So(txnDS.Get(f).Error(), ShouldContainSubstring, "expired")
})
Convey("Nested transactions are rejected", func() {
- err := rds.RunInTransaction(func(c context.Context) error {
- err := rdsS.Get(c).RunInTransaction(func(c context.Context) error {
+ err := ds.RunInTransaction(func(c context.Context) error {
+ err := dsS.Get(c).RunInTransaction(func(c context.Context) error {
panic("noooo")
}, nil)
So(err.Error(), ShouldContainSubstring, "nested transactions")
@@ -381,15 +338,11 @@ 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 := rds.RunInTransaction(func(c context.Context) error {
- txnDS := rdsS.Get(c)
- f := &Foo{Val: 21}
- putOne(txnDS, k, f)
-
- err := rds.RunInTransaction(func(c context.Context) error {
- txnDS := rdsS.Get(c)
- f := &Foo{Val: 27}
- putOne(txnDS, k, f)
+ err := ds.RunInTransaction(func(c context.Context) error {
+ So(dsS.Get(c).Put(&Foo{Id: 1, Val: 21}), ShouldBeNil)
+
+ err := ds.RunInTransaction(func(c context.Context) error {
+ So(dsS.Get(c).Put(&Foo{Id: 1, Val: 27}), ShouldBeNil)
return nil
}, nil)
So(err, ShouldBeNil)
@@ -398,19 +351,20 @@ func TestDatastoreSingleReadWriter(t *testing.T) {
}, nil)
So(err.Error(), ShouldContainSubstring, "concurrent")
- f := &Foo{}
- getOne(rds, k, f)
+ f := &Foo{Id: 1}
+ So(ds.Get(f), ShouldBeNil)
So(f.Val, ShouldEqual, 27)
})
Convey("XG", func() {
Convey("Modifying two groups with XG=false is invalid", func() {
- err := rds.RunInTransaction(func(c context.Context) error {
- rds := rdsS.Get(c)
- f := &Foo{Val: 200}
- putOne(rds, k, f)
+ err := ds.RunInTransaction(func(c context.Context) error {
+ ds := dsS.Get(c)
+ f := &Foo{Id: 1, Val: 200}
+ So(ds.Put(f), ShouldBeNil)
- _, err := putOneErr(rds, rds.NewKey("Foo", "", 2, nil), f)
+ f.Id = 2
+ err := ds.Put(f)
So(err.Error(), ShouldContainSubstring, "cross-group")
return err
}, nil)
@@ -418,50 +372,47 @@ func TestDatastoreSingleReadWriter(t *testing.T) {
})
Convey("Modifying >25 groups with XG=true is invald", func() {
- err := rds.RunInTransaction(func(c context.Context) error {
- rds := rdsS.Get(c)
+ err := ds.RunInTransaction(func(c context.Context) error {
+ ds := dsS.Get(c)
+ foos := make([]Foo, 25)
for i := int64(1); i < 26; i++ {
- k := rds.NewKey("Foo", "", i, nil)
- f := &Foo{Val: 200}
- putOne(rds, k, f)
+ foos[i-1].Id = i
+ foos[i-1].Val = 200
}
- f := &Foo{Val: 200}
- _, err := putOneErr(rds, rds.NewKey("Foo", "", 27, nil), f)
+ So(ds.PutMulti(foos), ShouldBeNil)
+ err := ds.Put(&Foo{Id: 26})
So(err.Error(), ShouldContainSubstring, "too many entity groups")
return err
- }, &rdsS.TransactionOptions{XG: true})
+ }, &dsS.TransactionOptions{XG: true})
So(err.Error(), ShouldContainSubstring, "too many entity groups")
})
})
Convey("Errors and panics", func() {
Convey("returning an error aborts", func() {
- err := rds.RunInTransaction(func(c context.Context) error {
- rds := rdsS.Get(c)
- f := &Foo{Val: 200}
- putOne(rds, k, f)
-
+ err := ds.RunInTransaction(func(c context.Context) error {
+ ds := dsS.Get(c)
+ So(ds.Put(&Foo{Id: 1, Val: 200}), ShouldBeNil)
return fmt.Errorf("thingy")
}, nil)
So(err.Error(), ShouldEqual, "thingy")
- f := &Foo{}
- getOne(rds, k, f)
+ f := &Foo{Id: 1}
+ So(ds.Get(f), ShouldBeNil)
So(f.Val, ShouldEqual, 10)
})
Convey("panicing aborts", func() {
So(func() {
- rds.RunInTransaction(func(c context.Context) error {
- rds := rdsS.Get(c)
- f := &Foo{Val: 200}
- putOne(rds, k, f)
+ ds.RunInTransaction(func(c context.Context) error {
+ ds := dsS.Get(c)
+ So(ds.Put(&Foo{Val: 200}), ShouldBeNil)
panic("wheeeeee")
}, nil)
}, ShouldPanic)
- f := &Foo{}
- getOne(rds, k, f)
+ f := &Foo{Id: 1}
+ So(ds.Get(f), ShouldBeNil)
So(f.Val, ShouldEqual, 10)
})
})
@@ -478,11 +429,11 @@ const IntIs32Bits = int64(MaxInt) < math.MaxInt64
func TestDatastoreQueryer(t *testing.T) {
Convey("Datastore Query suport", t, func() {
c := Use(context.Background())
- rds := rdsS.Get(c)
- So(rds, ShouldNotBeNil)
+ ds := dsS.Get(c)
+ So(ds, ShouldNotBeNil)
Convey("can create good queries", func() {
- q := rds.NewQuery("Foo").KeysOnly().Limit(10).Offset(39)
+ q := ds.NewQuery("Foo").KeysOnly().Limit(10).Offset(39)
q = q.Start(queryCursor("kosmik")).End(queryCursor("krabs"))
So(q, ShouldNotBeNil)
So(q.(*queryImpl).err, ShouldBeNil)
@@ -491,7 +442,7 @@ func TestDatastoreQueryer(t *testing.T) {
})
Convey("normalize ensures orders make sense", func() {
- q := rds.NewQuery("Cool")
+ q := ds.NewQuery("Cool")
q = q.Filter("cat =", 19).Filter("bob =", 10).Order("bob").Order("bob")
Convey("removes dups and equality orders", func() {
@@ -511,7 +462,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__ =", rds.NewKey("Foo", "wat", 0, nil))
+ q := q.Filter("__key__ =", ds.NewKey("Foo", "wat", 0, nil))
qi := q.(*queryImpl).normalize().checkCorrectness("", false)
So(qi.order, ShouldResemble, []queryOrder(nil))
So(qi.err, ShouldBeNil)
@@ -526,7 +477,7 @@ func TestDatastoreQueryer(t *testing.T) {
})
Convey("can create bad queries", func() {
- q := rds.NewQuery("Foo")
+ q := ds.NewQuery("Foo")
Convey("bad filter ops", func() {
q := q.Filter("Bob !", "value")
@@ -567,26 +518,26 @@ func TestDatastoreQueryer(t *testing.T) {
So(q.(*queryImpl).err.Error(), ShouldContainSubstring, "invalid cursor")
})
Convey("Bad ancestors", func() {
- q := q.Ancestor(rds.NewKey("Goop", "wat", 10, nil))
+ q := q.Ancestor(ds.NewKey("Goop", "wat", 10, nil))
So(q, ShouldNotBeNil)
qi := q.(*queryImpl).checkCorrectness("", false)
- So(qi.err, ShouldEqual, rdsS.ErrInvalidKey)
+ So(qi.err, ShouldEqual, dsS.ErrInvalidKey)
})
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__ =", rds.NewKey("Goop", "wat", 10, nil))
+ q := q.Filter("__key__ =", ds.NewKey("Goop", "wat", 10, nil))
qi := q.(*queryImpl).checkCorrectness("", false)
- So(qi.err, ShouldEqual, rdsS.ErrInvalidKey)
+ So(qi.err, ShouldEqual, dsS.ErrInvalidKey)
})
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(rds.NewKey("thing", "wat", 0, nil))
+ q := q.Ancestor(ds.NewKey("thing", "wat", 0, nil))
for i := 0; i < 100; i++ {
q = q.Filter("something =", 10)
}
@@ -609,17 +560,17 @@ func TestDatastoreQueryer(t *testing.T) {
So(qi.err.Error(), ShouldContainSubstring, "first sort property")
})
Convey("kindless with non-__key__ filters", func() {
- q := rds.NewQuery("").Filter("face <", 25.3)
+ q := ds.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 := rds.NewQuery("").Order("face")
+ q := ds.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 := rds.NewQuery("").Order("-__key__")
+ q := ds.NewQuery("").Order("-__key__")
qi := q.(*queryImpl).checkCorrectness("", false)
So(qi.err.Error(), ShouldContainSubstring, "kind is required for all orders")
})

Powered by Google App Engine
This is Rietveld 408576698