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

Unified Diff: impl/memory/raw_datastore_test.go

Issue 1243323002: Refactor a bit. (Closed) Base URL: https://github.com/luci/gae.git@master
Patch Set: fix golint Created 5 years, 5 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
« no previous file with comments | « impl/memory/raw_datastore_query.go ('k') | impl/memory/taskqueue.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: impl/memory/raw_datastore_test.go
diff --git a/memory/raw_datastore_test.go b/impl/memory/raw_datastore_test.go
similarity index 90%
rename from memory/raw_datastore_test.go
rename to impl/memory/raw_datastore_test.go
index 752de54f0af6bf5a4692fa52eb169a856a4738e8..829b3b0fc4cb20351de79196fc6450e6a825d4f8 100644
--- a/memory/raw_datastore_test.go
+++ b/impl/memory/raw_datastore_test.go
@@ -9,8 +9,7 @@ import (
"math"
"testing"
- "github.com/luci/gae"
- "github.com/luci/gae/helper"
+ rdsS "github.com/luci/gae/service/rawdatastore"
. "github.com/smartystreets/goconvey/convey"
"golang.org/x/net/context"
)
@@ -20,7 +19,7 @@ func TestDatastoreKinder(t *testing.T) {
Convey("Datastore keys", t, func() {
c := Use(context.Background())
- rds := gae.GetRDS(c)
+ rds := rdsS.Get(c)
So(rds, ShouldNotBeNil)
Convey("implements DSNewKeyer", func() {
@@ -34,30 +33,30 @@ func TestDatastoreKinder(t *testing.T) {
So(key.AppID(), ShouldEqual, "dev~app")
So(key.Namespace(), ShouldEqual, "")
So(key.String(), ShouldEqual, "/nerd,stringID")
- So(helper.DSKeyIncomplete(key), ShouldBeFalse)
- So(helper.DSKeyValid(key, "", false), ShouldBeTrue)
+ So(rdsS.KeyIncomplete(key), ShouldBeFalse)
+ So(rdsS.KeyValid(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{}
+func testGetMeta(c context.Context, k rdsS.Key) int64 {
+ rds := rdsS.Get(c)
+ k = rds.NewKey("__entity_group__", "", 1, rdsS.KeyRoot(k))
+ pmap := rdsS.PropertyMap{}
rds.Get(k, pmap)
return pmap["__version__"][0].Value().(int64)
}
-var pls = helper.GetPLS
+var pls = rdsS.GetPLS
func TestDatastoreSingleReadWriter(t *testing.T) {
t.Parallel()
Convey("Datastore single reads and writes", t, func() {
c := Use(context.Background())
- rds := gae.GetRDS(c)
+ rds := rdsS.Get(c)
So(rds, ShouldNotBeNil)
Convey("implements DSSingleReadWriter", func() {
@@ -67,15 +66,15 @@ func TestDatastoreSingleReadWriter(t *testing.T) {
Convey("invalid keys break", func() {
k := rds.NewKey("Foo", "", 0, nil)
- So(rds.Get(k, nil), ShouldEqual, gae.ErrDSInvalidKey)
+ So(rds.Get(k, nil), ShouldEqual, rdsS.ErrInvalidKey)
_, err := rds.Put(rds.NewKey("Foo", "", 0, k), pls(&Foo{}))
- So(err, ShouldEqual, gae.ErrDSInvalidKey)
+ So(err, ShouldEqual, rdsS.ErrInvalidKey)
})
Convey("getting objects that DNE is an error", func() {
k := rds.NewKey("Foo", "", 1, nil)
- So(rds.Get(k, nil), ShouldEqual, gae.ErrDSNoSuchEntity)
+ So(rds.Get(k, nil), ShouldEqual, rdsS.ErrNoSuchEntity)
})
Convey("Can Put stuff", func() {
@@ -97,12 +96,12 @@ func TestDatastoreSingleReadWriter(t *testing.T) {
So(err, ShouldBeNil)
err = rds.Get(k, pls(newFoo))
- So(err, ShouldEqual, gae.ErrDSNoSuchEntity)
+ So(err, ShouldEqual, rdsS.ErrNoSuchEntity)
})
})
Convey("Deleteing with a bogus key is bad", func() {
err := rds.Delete(rds.NewKey("Foo", "wat", 100, nil))
- So(err, ShouldEqual, gae.ErrDSInvalidKey)
+ So(err, ShouldEqual, rdsS.ErrInvalidKey)
})
Convey("Deleteing a DNE entity is fine", func() {
err := rds.Delete(rds.NewKey("Foo", "wat", 0, nil))
@@ -112,8 +111,8 @@ func TestDatastoreSingleReadWriter(t *testing.T) {
Convey("with multiple puts", func() {
So(testGetMeta(c, k), ShouldEqual, 1)
- keys := []gae.DSKey{}
- plss := []gae.DSPropertyLoadSaver{}
+ keys := []rdsS.Key{}
+ plss := []rdsS.PropertyLoadSaver{}
pkey := k
for i := 0; i < 10; i++ {
@@ -145,15 +144,15 @@ func TestDatastoreSingleReadWriter(t *testing.T) {
})
Convey("can GetMulti", func() {
- plss := make([]gae.DSPropertyLoadSaver, len(keys))
+ plss := make([]rdsS.PropertyLoadSaver, len(keys))
for i := range plss {
- plss[i] = gae.DSPropertyMap{}
+ plss[i] = rdsS.PropertyMap{}
}
err := rds.GetMulti(keys, plss)
So(err, ShouldBeNil)
for _, pls := range plss {
- So(pls.(gae.DSPropertyMap), ShouldResemble, gae.DSPropertyMap{
- "Val": {gae.MkDSProperty(10)},
+ So(pls.(rdsS.PropertyMap), ShouldResemble, rdsS.PropertyMap{
+ "Val": {rdsS.MkProperty(10)},
})
}
})
@@ -174,7 +173,7 @@ func TestDatastoreSingleReadWriter(t *testing.T) {
Convey("can Put new entity groups", func() {
err := rds.RunInTransaction(func(c context.Context) error {
- rds := gae.GetRDS(c)
+ rds := rdsS.Get(c)
So(rds, ShouldNotBeNil)
f1 := &Foo{Val: 100}
@@ -188,7 +187,7 @@ func TestDatastoreSingleReadWriter(t *testing.T) {
So(k.String(), ShouldEqual, "/Foo,3")
return nil
- }, &gae.DSTransactionOptions{XG: true})
+ }, &rdsS.TransactionOptions{XG: true})
So(err, ShouldBeNil)
f := &Foo{}
@@ -202,7 +201,7 @@ func TestDatastoreSingleReadWriter(t *testing.T) {
Convey("can Put new entities in a current group", func() {
err := rds.RunInTransaction(func(c context.Context) error {
- rds := gae.GetRDS(c)
+ rds := rdsS.Get(c)
So(rds, ShouldNotBeNil)
par := k
@@ -232,19 +231,19 @@ func TestDatastoreSingleReadWriter(t *testing.T) {
Convey("Deletes work too", func() {
err := rds.RunInTransaction(func(c context.Context) error {
- rds := gae.GetRDS(c)
+ rds := rdsS.Get(c)
So(rds, ShouldNotBeNil)
So(rds.Delete(k), ShouldBeNil)
return nil
}, nil)
So(err, ShouldBeNil)
- So(rds.Get(k, nil), ShouldEqual, gae.ErrDSNoSuchEntity)
+ So(rds.Get(k, nil), ShouldEqual, rdsS.ErrNoSuchEntity)
})
Convey("A Get counts against your group count", func() {
err := rds.RunInTransaction(func(c context.Context) error {
- rds := gae.GetRDS(c)
- So(rds.Get(rds.NewKey("Foo", "", 20, nil), nil), ShouldEqual, gae.ErrDSNoSuchEntity)
+ rds := rdsS.Get(c)
+ So(rds.Get(rds.NewKey("Foo", "", 20, nil), nil), ShouldEqual, rdsS.ErrNoSuchEntity)
So(rds.Get(k, nil).Error(), ShouldContainSubstring, "cross-group")
return nil
}, nil)
@@ -253,7 +252,7 @@ func TestDatastoreSingleReadWriter(t *testing.T) {
Convey("Get takes a snapshot", func() {
err := rds.RunInTransaction(func(c context.Context) error {
- txnDS := gae.GetRDS(c)
+ txnDS := rdsS.Get(c)
So(txnDS, ShouldNotBeNil)
So(txnDS.Get(k, pls(f)), ShouldBeNil)
@@ -279,7 +278,7 @@ func TestDatastoreSingleReadWriter(t *testing.T) {
Convey("and snapshots are consistent even after Puts", func() {
err := rds.RunInTransaction(func(c context.Context) error {
- txnDS := gae.GetRDS(c)
+ txnDS := rdsS.Get(c)
So(txnDS, ShouldNotBeNil)
f := &Foo{}
@@ -314,19 +313,19 @@ func TestDatastoreSingleReadWriter(t *testing.T) {
Convey("Reusing a transaction context is bad news", func() {
k := rds.NewKey("Foo", "", 1, nil)
- txnDS := gae.RawDatastore(nil)
+ txnDS := rdsS.Interface(nil)
err := rds.RunInTransaction(func(c context.Context) error {
- txnDS = gae.GetRDS(c)
- So(txnDS.Get(k, gae.DSPropertyMap{}), ShouldBeNil)
+ txnDS = rdsS.Get(c)
+ So(txnDS.Get(k, rdsS.PropertyMap{}), ShouldBeNil)
return nil
}, nil)
So(err, ShouldBeNil)
- So(txnDS.Get(k, gae.DSPropertyMap{}).Error(), ShouldContainSubstring, "expired")
+ So(txnDS.Get(k, rdsS.PropertyMap{}).Error(), ShouldContainSubstring, "expired")
})
Convey("Nested transactions are rejected", func() {
err := rds.RunInTransaction(func(c context.Context) error {
- err := gae.GetRDS(c).RunInTransaction(func(c context.Context) error {
+ err := rdsS.Get(c).RunInTransaction(func(c context.Context) error {
panic("noooo")
}, nil)
So(err.Error(), ShouldContainSubstring, "nested transactions")
@@ -344,13 +343,13 @@ func TestDatastoreSingleReadWriter(t *testing.T) {
//
// That said... I'm not sure if there's really a semantic difference.
err := rds.RunInTransaction(func(c context.Context) error {
- txnDS := gae.GetRDS(c)
+ txnDS := rdsS.Get(c)
f := &Foo{Val: 21}
_, err = txnDS.Put(k, pls(f))
So(err, ShouldBeNil)
err := rds.RunInTransaction(func(c context.Context) error {
- txnDS := gae.GetRDS(c)
+ txnDS := rdsS.Get(c)
f := &Foo{Val: 27}
_, err := txnDS.Put(k, pls(f))
So(err, ShouldBeNil)
@@ -370,7 +369,7 @@ func TestDatastoreSingleReadWriter(t *testing.T) {
Convey("XG", func() {
Convey("Modifying two groups with XG=false is invalid", func() {
err := rds.RunInTransaction(func(c context.Context) error {
- rds := gae.GetRDS(c)
+ rds := rdsS.Get(c)
f := &Foo{Val: 200}
_, err := rds.Put(k, pls(f))
So(err, ShouldBeNil)
@@ -384,7 +383,7 @@ func TestDatastoreSingleReadWriter(t *testing.T) {
Convey("Modifying >25 groups with XG=true is invald", func() {
err := rds.RunInTransaction(func(c context.Context) error {
- rds := gae.GetRDS(c)
+ rds := rdsS.Get(c)
for i := int64(1); i < 26; i++ {
k := rds.NewKey("Foo", "", i, nil)
f := &Foo{Val: 200}
@@ -395,7 +394,7 @@ func TestDatastoreSingleReadWriter(t *testing.T) {
_, err := rds.Put(rds.NewKey("Foo", "", 27, nil), pls(f))
So(err.Error(), ShouldContainSubstring, "too many entity groups")
return err
- }, &gae.DSTransactionOptions{XG: true})
+ }, &rdsS.TransactionOptions{XG: true})
So(err.Error(), ShouldContainSubstring, "too many entity groups")
})
})
@@ -403,7 +402,7 @@ func TestDatastoreSingleReadWriter(t *testing.T) {
Convey("Errors and panics", func() {
Convey("returning an error aborts", func() {
err := rds.RunInTransaction(func(c context.Context) error {
- rds := gae.GetRDS(c)
+ rds := rdsS.Get(c)
f := &Foo{Val: 200}
_, err := rds.Put(k, pls(f))
So(err, ShouldBeNil)
@@ -420,7 +419,7 @@ func TestDatastoreSingleReadWriter(t *testing.T) {
Convey("panicing aborts", func() {
So(func() {
rds.RunInTransaction(func(c context.Context) error {
- rds := gae.GetRDS(c)
+ rds := rdsS.Get(c)
f := &Foo{Val: 200}
_, err := rds.Put(k, pls(f))
So(err, ShouldBeNil)
@@ -446,7 +445,7 @@ const IntIs32Bits = int64(MaxInt) < math.MaxInt64
func TestDatastoreQueryer(t *testing.T) {
Convey("Datastore Query suport", t, func() {
c := Use(context.Background())
- rds := gae.GetRDS(c)
+ rds := rdsS.Get(c)
So(rds, ShouldNotBeNil)
Convey("can create good queries", func() {
@@ -538,7 +537,7 @@ func TestDatastoreQueryer(t *testing.T) {
q := q.Ancestor(rds.NewKey("Goop", "wat", 10, nil))
So(q, ShouldNotBeNil)
qi := q.(*queryImpl).checkCorrectness("", false)
- So(qi.err, ShouldEqual, gae.ErrDSInvalidKey)
+ So(qi.err, ShouldEqual, rdsS.ErrInvalidKey)
})
Convey("nil ancestors", func() {
qi := q.Ancestor(nil).(*queryImpl).checkCorrectness("", false)
@@ -547,7 +546,7 @@ func TestDatastoreQueryer(t *testing.T) {
Convey("Bad key filters", func() {
q := q.Filter("__key__ =", rds.NewKey("Goop", "wat", 10, nil))
qi := q.(*queryImpl).checkCorrectness("", false)
- So(qi.err, ShouldEqual, gae.ErrDSInvalidKey)
+ So(qi.err, ShouldEqual, rdsS.ErrInvalidKey)
})
Convey("non-ancestor queries in a transaction", func() {
qi := q.(*queryImpl).checkCorrectness("", true)
« no previous file with comments | « impl/memory/raw_datastore_query.go ('k') | impl/memory/taskqueue.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698