Index: service/datastore/datastore_test.go |
diff --git a/service/datastore/datastore_test.go b/service/datastore/datastore_test.go |
index 19982929c5d98bf3a14c9f469382092e0eeb8afa..1fb129e6a4d4261e01a3e6c7c5cbb90185d01e0c 100644 |
--- a/service/datastore/datastore_test.go |
+++ b/service/datastore/datastore_test.go |
@@ -17,18 +17,15 @@ import ( |
"github.com/luci/gae/service/info" |
"github.com/luci/luci-go/common/errors" |
+ |
+ "golang.org/x/net/context" |
+ |
. "github.com/luci/luci-go/common/testing/assertions" |
. "github.com/smartystreets/goconvey/convey" |
- "golang.org/x/net/context" |
) |
-func fakeDatastoreFactory(c context.Context, wantTxn bool) RawInterface { |
- i := info.Get(c) |
- fds := fakeDatastore{ |
- aid: i.FullyQualifiedAppID(), |
- } |
- fds.ns, _ = i.GetNamespace() |
- return &fds |
+func fakeDatastoreFactory(c context.Context) RawInterface { |
+ return &fakeDatastore{Context: c} |
} |
var ( |
@@ -37,17 +34,8 @@ var ( |
) |
type fakeDatastore struct { |
+ context.Context |
RawInterface |
- aid string |
- ns string |
-} |
- |
-func (f *fakeDatastore) mkKey(elems ...interface{}) *Key { |
- return MakeKey(f.aid, f.ns, elems...) |
-} |
- |
-func (f *fakeDatastore) newKey(kind, stringID string, intID int64, parent *Key) *Key { |
- return NewKey(f.aid, f.ns, kind, stringID, intID, parent) |
} |
func (f *fakeDatastore) AllocateIDs(keys []*Key, cb NewKeyCB) error { |
@@ -58,7 +46,7 @@ func (f *fakeDatastore) AllocateIDs(keys []*Key, cb NewKeyCB) error { |
if k.Kind() == "Fail" { |
cb(nil, errFail) |
} else { |
- cb(f.newKey(k.Kind(), "", int64(i+1), k.Parent()), nil) |
+ cb(NewKey(f, k.Kind(), "", int64(i+1), k.Parent()), nil) |
} |
} |
return nil |
@@ -78,9 +66,9 @@ func (f *fakeDatastore) Run(fq *FinalizedQuery, cb RawRunCB) error { |
return errors.New(v[0].Value().(string)) |
} |
} |
- k := f.mkKey("Kind", i+1) |
+ k := MakeKey(f, "Kind", i+1) |
if i == 10 { |
- k = f.mkKey("Kind", "eleven") |
+ k = MakeKey(f, "Kind", "eleven") |
} |
pm := PropertyMap{"Value": {MkProperty(i)}} |
if err := cb(k, pm, cursCB); err != nil { |
@@ -108,7 +96,7 @@ func (f *fakeDatastore) PutMulti(keys []*Key, vals []PropertyMap, cb NewKeyCB) e |
So(vals[i]["Extra"], ShouldResemble, []Property{MkProperty("whoa")}) |
} |
if k.IsIncomplete() { |
- k = NewKey(k.AppID(), k.Namespace(), k.Kind(), "", int64(i+1), k.Parent()) |
+ k = k.KeyContext().NewKey(k.Kind(), "", int64(i+1), k.Parent()) |
} |
} |
cb(k, err) |
@@ -330,9 +318,8 @@ func TestKeyForObj(t *testing.T) { |
Convey("Test interface.KeyForObj", t, func() { |
c := info.Set(context.Background(), fakeInfo{}) |
c = SetRawFactory(c, fakeDatastoreFactory) |
- ds := Get(c) |
- k := ds.MakeKey("Hello", "world") |
+ k := MakeKey(c, "Hello", "world") |
Convey("good", func() { |
Convey("struct containing $key", func() { |
@@ -341,7 +328,7 @@ func TestKeyForObj(t *testing.T) { |
} |
ks := &keyStruct{k} |
- So(ds.KeyForObj(ks), ShouldEqual, k) |
+ So(KeyForObj(c, ks), ShouldEqual, k) |
}) |
Convey("struct containing default $id and $kind", func() { |
@@ -350,37 +337,37 @@ func TestKeyForObj(t *testing.T) { |
knd string `gae:"$kind,SuperKind"` |
} |
- So(ds.KeyForObj(&idStruct{}).String(), ShouldEqual, `s~aid:ns:/SuperKind,"wut"`) |
+ So(KeyForObj(c, &idStruct{}).String(), ShouldEqual, `s~aid:ns:/SuperKind,"wut"`) |
}) |
Convey("struct containing $id and $parent", func() { |
- So(ds.KeyForObj(&CommonStruct{ID: 4}).String(), ShouldEqual, `s~aid:ns:/CommonStruct,4`) |
+ So(KeyForObj(c, &CommonStruct{ID: 4}).String(), ShouldEqual, `s~aid:ns:/CommonStruct,4`) |
- So(ds.KeyForObj(&CommonStruct{ID: 4, Parent: k}).String(), ShouldEqual, `s~aid:ns:/Hello,"world"/CommonStruct,4`) |
+ So(KeyForObj(c, &CommonStruct{ID: 4, Parent: k}).String(), ShouldEqual, `s~aid:ns:/Hello,"world"/CommonStruct,4`) |
}) |
Convey("a propmap with $key", func() { |
pm := PropertyMap{} |
So(pm.SetMeta("key", k), ShouldBeTrue) |
- So(ds.KeyForObj(pm).String(), ShouldEqual, `s~aid:ns:/Hello,"world"`) |
+ So(KeyForObj(c, pm).String(), ShouldEqual, `s~aid:ns:/Hello,"world"`) |
}) |
Convey("a propmap with $id, $kind, $parent", func() { |
pm := PropertyMap{} |
So(pm.SetMeta("id", 100), ShouldBeTrue) |
So(pm.SetMeta("kind", "Sup"), ShouldBeTrue) |
- So(ds.KeyForObj(pm).String(), ShouldEqual, `s~aid:ns:/Sup,100`) |
+ So(KeyForObj(c, pm).String(), ShouldEqual, `s~aid:ns:/Sup,100`) |
So(pm.SetMeta("parent", k), ShouldBeTrue) |
- So(ds.KeyForObj(pm).String(), ShouldEqual, `s~aid:ns:/Hello,"world"/Sup,100`) |
+ So(KeyForObj(c, pm).String(), ShouldEqual, `s~aid:ns:/Hello,"world"/Sup,100`) |
}) |
Convey("a pls with $id, $parent", func() { |
pls := GetPLS(&CommonStruct{ID: 1}) |
- So(ds.KeyForObj(pls).String(), ShouldEqual, `s~aid:ns:/CommonStruct,1`) |
+ So(KeyForObj(c, pls).String(), ShouldEqual, `s~aid:ns:/CommonStruct,1`) |
So(pls.SetMeta("parent", k), ShouldBeTrue) |
- So(ds.KeyForObj(pls).String(), ShouldEqual, `s~aid:ns:/Hello,"world"/CommonStruct,1`) |
+ So(KeyForObj(c, pls).String(), ShouldEqual, `s~aid:ns:/Hello,"world"/CommonStruct,1`) |
}) |
}) |
@@ -388,7 +375,7 @@ func TestKeyForObj(t *testing.T) { |
Convey("a propmap without $kind", func() { |
pm := PropertyMap{} |
So(pm.SetMeta("id", 100), ShouldBeTrue) |
- So(func() { ds.KeyForObj(pm) }, ShouldPanic) |
+ So(func() { KeyForObj(c, pm) }, ShouldPanic) |
}) |
Convey("a bad object", func() { |
@@ -398,7 +385,7 @@ func TestKeyForObj(t *testing.T) { |
NonSerializableField complex64 |
} |
- So(func() { ds.KeyForObjErr(&BadObj{ID: 1}) }, ShouldPanicLike, |
+ So(func() { KeyForObj(c, &BadObj{ID: 1}) }, ShouldPanicLike, |
`field "NonSerializableField" has invalid type: complex64`) |
}) |
}) |
@@ -409,7 +396,7 @@ func TestPopulateKey(t *testing.T) { |
t.Parallel() |
Convey("Test PopulateKey", t, func() { |
- k := NewKey("app", "namespace", "kind", "", 1337, nil) |
+ k := KeyContext{"app", "namespace"}.NewKey("kind", "", 1337, nil) |
Convey("Can set the key of a common struct.", func() { |
var cs CommonStruct |
@@ -445,54 +432,53 @@ func TestAllocateIDs(t *testing.T) { |
Convey("A testing environment", t, func() { |
c := info.Set(context.Background(), fakeInfo{}) |
c = SetRawFactory(c, fakeDatastoreFactory) |
- ds := Get(c) |
Convey("Testing AllocateIDs", func() { |
Convey("Will return nil if no entities are supplied.", func() { |
- So(ds.AllocateIDs(), ShouldBeNil) |
+ So(AllocateIDs(c), ShouldBeNil) |
}) |
Convey("single struct", func() { |
cs := CommonStruct{Value: 1} |
- So(ds.AllocateIDs(&cs), ShouldBeNil) |
+ So(AllocateIDs(c, &cs), ShouldBeNil) |
So(cs.ID, ShouldEqual, 1) |
}) |
Convey("struct slice", func() { |
csSlice := []*CommonStruct{{Value: 1}, {Value: 2}} |
- So(ds.AllocateIDs(csSlice), ShouldBeNil) |
+ So(AllocateIDs(c, csSlice), ShouldBeNil) |
So(csSlice, ShouldResemble, []*CommonStruct{{ID: 1, Value: 1}, {ID: 2, Value: 2}}) |
}) |
Convey("single key will fail", func() { |
- singleKey := ds.MakeKey("FooParent", "BarParent", "Foo", "Bar") |
- So(func() { ds.AllocateIDs(singleKey) }, ShouldPanicLike, |
+ singleKey := MakeKey(c, "FooParent", "BarParent", "Foo", "Bar") |
+ So(func() { AllocateIDs(c, singleKey) }, ShouldPanicLike, |
"invalid input type (*datastore.Key): not a PLS, pointer-to-struct, or slice thereof") |
}) |
Convey("key slice", func() { |
- k0 := ds.MakeKey("Foo", "Bar") |
- k1 := ds.MakeKey("Baz", "Qux") |
+ k0 := MakeKey(c, "Foo", "Bar") |
+ k1 := MakeKey(c, "Baz", "Qux") |
keySlice := []*Key{k0, k1} |
- So(ds.AllocateIDs(keySlice), ShouldBeNil) |
- So(keySlice[0].Equal(ds.MakeKey("Foo", 1)), ShouldBeTrue) |
- So(keySlice[1].Equal(ds.MakeKey("Baz", 2)), ShouldBeTrue) |
+ So(AllocateIDs(c, keySlice), ShouldBeNil) |
+ So(keySlice[0].Equal(MakeKey(c, "Foo", 1)), ShouldBeTrue) |
+ So(keySlice[1].Equal(MakeKey(c, "Baz", 2)), ShouldBeTrue) |
// The original keys should not have changed. |
- So(k0.Equal(ds.MakeKey("Foo", "Bar")), ShouldBeTrue) |
- So(k1.Equal(ds.MakeKey("Baz", "Qux")), ShouldBeTrue) |
+ So(k0.Equal(MakeKey(c, "Foo", "Bar")), ShouldBeTrue) |
+ So(k1.Equal(MakeKey(c, "Baz", "Qux")), ShouldBeTrue) |
}) |
Convey("fail all key slice", func() { |
- keySlice := []*Key{ds.MakeKey("FailAll", "oops"), ds.MakeKey("Baz", "Qux")} |
- So(ds.AllocateIDs(keySlice), ShouldEqual, errFailAll) |
+ keySlice := []*Key{MakeKey(c, "FailAll", "oops"), MakeKey(c, "Baz", "Qux")} |
+ So(AllocateIDs(c, keySlice), ShouldEqual, errFailAll) |
So(keySlice[0].StringID(), ShouldEqual, "oops") |
So(keySlice[1].StringID(), ShouldEqual, "Qux") |
}) |
Convey("fail key slice", func() { |
- keySlice := []*Key{ds.MakeKey("Fail", "oops"), ds.MakeKey("Baz", "Qux")} |
- So(ds.AllocateIDs(keySlice), ShouldResemble, errors.MultiError{errFail, nil}) |
+ keySlice := []*Key{MakeKey(c, "Fail", "oops"), MakeKey(c, "Baz", "Qux")} |
+ So(AllocateIDs(c, keySlice), ShouldResemble, errors.MultiError{errFail, nil}) |
So(keySlice[0].StringID(), ShouldEqual, "oops") |
So(keySlice[1].IntID(), ShouldEqual, 2) |
}) |
@@ -503,18 +489,18 @@ func TestAllocateIDs(t *testing.T) { |
emptySlice := []CommonStruct(nil) |
cs0 := CommonStruct{Value: 4} |
cs1 := FakePLS{Kind: "Fail", Value: 5} |
- keySlice := []*Key{ds.MakeKey("Foo", "Bar"), ds.MakeKey("Baz", "Qux")} |
+ keySlice := []*Key{MakeKey(c, "Foo", "Bar"), MakeKey(c, "Baz", "Qux")} |
fpls := FakePLS{StringID: "ohai", Value: 6} |
- err := ds.AllocateIDs(successSlice, failSlice, emptySlice, &cs0, &cs1, keySlice, &fpls) |
+ err := AllocateIDs(c, successSlice, failSlice, emptySlice, &cs0, &cs1, keySlice, &fpls) |
So(err, ShouldResemble, errors.MultiError{ |
nil, errors.MultiError{errFail, nil}, nil, nil, errFail, nil, nil}) |
So(successSlice[0].ID, ShouldEqual, 1) |
So(successSlice[1].ID, ShouldEqual, 2) |
So(failSlice[1].IntID, ShouldEqual, 4) |
So(cs0.ID, ShouldEqual, 5) |
- So(keySlice[0].Equal(ds.MakeKey("Foo", 7)), ShouldBeTrue) |
- So(keySlice[1].Equal(ds.MakeKey("Baz", 8)), ShouldBeTrue) |
+ So(keySlice[0].Equal(MakeKey(c, "Foo", 7)), ShouldBeTrue) |
+ So(keySlice[1].Equal(MakeKey(c, "Baz", 8)), ShouldBeTrue) |
So(fpls.IntID, ShouldEqual, 9) |
}) |
}) |
@@ -527,60 +513,59 @@ func TestPut(t *testing.T) { |
Convey("A testing environment", t, func() { |
c := info.Set(context.Background(), fakeInfo{}) |
c = SetRawFactory(c, fakeDatastoreFactory) |
- ds := Get(c) |
Convey("Testing Put", func() { |
Convey("bad", func() { |
Convey("static can't serialize", func() { |
bss := []badStruct{{}, {}} |
- So(func() { ds.Put(bss) }, ShouldPanicLike, |
+ So(func() { Put(c, bss) }, ShouldPanicLike, |
`field "Compy" has invalid type`) |
}) |
Convey("static ptr can't serialize", func() { |
bss := []*badStruct{{}, {}} |
- So(func() { ds.Put(bss) }, ShouldPanicLike, |
+ So(func() { Put(c, bss) }, ShouldPanicLike, |
`field "Compy" has invalid type: complex64`) |
}) |
Convey("static bad type", func() { |
- So(func() { ds.Put(100) }, ShouldPanicLike, |
+ So(func() { Put(c, 100) }, ShouldPanicLike, |
"invalid input type (int): not a PLS, pointer-to-struct, or slice thereof") |
}) |
Convey("static bad type (slice of bad type)", func() { |
- So(func() { ds.Put([]int{}) }, ShouldPanicLike, |
+ So(func() { Put(c, []int{}) }, ShouldPanicLike, |
"invalid input type ([]int): not a PLS, pointer-to-struct, or slice thereof") |
}) |
Convey("dynamic can't serialize", func() { |
fplss := []FakePLS{{failSave: true}, {}} |
- So(ds.Put(fplss), ShouldErrLike, "FakePLS.Save") |
+ So(Put(c, fplss), ShouldErrLike, "FakePLS.Save") |
}) |
Convey("can't get keys", func() { |
fplss := []FakePLS{{failGetMeta: true}, {}} |
- So(ds.Put(fplss), ShouldErrLike, "unable to extract $kind") |
+ So(Put(c, fplss), ShouldErrLike, "unable to extract $kind") |
}) |
Convey("get single error for RPC failure", func() { |
fplss := []FakePLS{{Kind: "FailAll"}, {}} |
- So(ds.Put(fplss), ShouldEqual, errFailAll) |
+ So(Put(c, fplss), ShouldEqual, errFailAll) |
}) |
Convey("get multi error for individual failures", func() { |
fplss := []FakePLS{{}, {Kind: "Fail"}} |
- So(ds.Put(fplss), ShouldResemble, errors.MultiError{nil, errFail}) |
+ So(Put(c, fplss), ShouldResemble, errors.MultiError{nil, errFail}) |
}) |
Convey("get with *Key is an error", func() { |
- So(func() { ds.Get(&Key{}) }, ShouldPanicLike, |
+ So(func() { Get(c, &Key{}) }, ShouldPanicLike, |
"invalid input type (*datastore.Key): not a PLS, pointer-to-struct, or slice thereof") |
}) |
Convey("struct with no $kind is an error", func() { |
s := MGSWithNoKind{} |
- So(ds.Put(&s), ShouldErrLike, "unable to extract $kind") |
+ So(Put(c, &s), ShouldErrLike, "unable to extract $kind") |
}) |
Convey("struct with invalid but non-nil key is an error", func() { |
@@ -589,8 +574,8 @@ func TestPut(t *testing.T) { |
Parent *Key `gae:"$parent"` |
} |
// having an Incomplete parent makes an invalid key |
- bp := &BadParent{ID: 1, Parent: ds.MakeKey("Something", 0)} |
- So(ds.Put(bp), ShouldErrLike, ErrInvalidKey) |
+ bp := &BadParent{ID: 1, Parent: MakeKey(c, "Something", 0)} |
+ So(Put(c, bp), ShouldErrLike, ErrInvalidKey) |
}) |
Convey("vararg with errors", func() { |
@@ -601,7 +586,7 @@ func TestPut(t *testing.T) { |
failPLS := FakePLS{Kind: "Fail", Value: 5} |
fpls := FakePLS{StringID: "ohai", Value: 6} |
- err := ds.Put(successSlice, failSlice, emptySlice, &cs0, &failPLS, &fpls) |
+ err := Put(c, successSlice, failSlice, emptySlice, &cs0, &failPLS, &fpls) |
So(err, ShouldResemble, errors.MultiError{ |
nil, errors.MultiError{errFail, nil}, nil, nil, errFail, nil}) |
So(successSlice[0].ID, ShouldEqual, 1) |
@@ -619,7 +604,7 @@ func TestPut(t *testing.T) { |
} |
css[i].Value = int64(i) |
} |
- So(ds.Put(css), ShouldBeNil) |
+ So(Put(c, css), ShouldBeNil) |
for i, cs := range css { |
expect := int64(i + 1) |
if i == 4 { |
@@ -637,7 +622,7 @@ func TestPut(t *testing.T) { |
css[i].ID = 200 |
} |
} |
- So(ds.Put(css), ShouldBeNil) |
+ So(Put(c, css), ShouldBeNil) |
for i, cs := range css { |
expect := int64(i + 1) |
if i == 4 { |
@@ -647,7 +632,7 @@ func TestPut(t *testing.T) { |
} |
s := &CommonStruct{} |
- So(ds.Put(s), ShouldBeNil) |
+ So(Put(c, s), ShouldBeNil) |
So(s.ID, ShouldEqual, 1) |
}) |
@@ -659,7 +644,7 @@ func TestPut(t *testing.T) { |
fplss[i].IntID = int64(200) |
} |
} |
- So(ds.Put(fplss), ShouldBeNil) |
+ So(Put(c, fplss), ShouldBeNil) |
for i, fpls := range fplss { |
expect := int64(i + 1) |
if i == 4 { |
@@ -669,8 +654,8 @@ func TestPut(t *testing.T) { |
} |
pm := PropertyMap{"Value": {MkProperty(0)}, "$kind": {MkPropertyNI("Pmap")}} |
- So(ds.Put(pm), ShouldBeNil) |
- So(ds.KeyForObj(pm).IntID(), ShouldEqual, 1) |
+ So(Put(c, pm), ShouldBeNil) |
+ So(KeyForObj(c, pm).IntID(), ShouldEqual, 1) |
}) |
Convey("[]P (map)", func() { |
@@ -684,13 +669,13 @@ func TestPut(t *testing.T) { |
So(pms[i].SetMeta("id", int64(200)), ShouldBeTrue) |
} |
} |
- So(ds.Put(pms), ShouldBeNil) |
+ So(Put(c, pms), ShouldBeNil) |
for i, pm := range pms { |
expect := int64(i + 1) |
if i == 4 { |
expect = 200 |
} |
- So(ds.KeyForObj(pm).String(), ShouldEqual, fmt.Sprintf("s~aid:ns:/Pmap,%d", expect)) |
+ So(KeyForObj(c, pm).String(), ShouldEqual, fmt.Sprintf("s~aid:ns:/Pmap,%d", expect)) |
} |
}) |
@@ -702,7 +687,7 @@ func TestPut(t *testing.T) { |
fplss[i].IntID = int64(200) |
} |
} |
- So(ds.Put(fplss), ShouldBeNil) |
+ So(Put(c, fplss), ShouldBeNil) |
for i, fpls := range fplss { |
expect := int64(i + 1) |
if i == 4 { |
@@ -723,13 +708,13 @@ func TestPut(t *testing.T) { |
So(pms[i].SetMeta("id", int64(200)), ShouldBeTrue) |
} |
} |
- So(ds.Put(pms), ShouldBeNil) |
+ So(Put(c, pms), ShouldBeNil) |
for i, pm := range pms { |
expect := int64(i + 1) |
if i == 4 { |
expect = 200 |
} |
- So(ds.KeyForObj(*pm).String(), ShouldEqual, fmt.Sprintf("s~aid:ns:/Pmap,%d", expect)) |
+ So(KeyForObj(c, *pm).String(), ShouldEqual, fmt.Sprintf("s~aid:ns:/Pmap,%d", expect)) |
} |
}) |
@@ -740,7 +725,7 @@ func TestPut(t *testing.T) { |
PropertyMap{"Value": {MkProperty(2)}, "$kind": {MkPropertyNI("Pmap")}}, |
&PropertyMap{"Value": {MkProperty(3)}, "$kind": {MkPropertyNI("Pmap")}}, |
} |
- So(ds.Put(ifs), ShouldBeNil) |
+ So(Put(c, ifs), ShouldBeNil) |
for i := range ifs { |
switch i { |
case 0: |
@@ -749,36 +734,14 @@ func TestPut(t *testing.T) { |
fpls := ifs[i].(*FakePLS) |
So(fpls.IntID, ShouldEqual, 2) |
case 2: |
- So(ds.KeyForObj(ifs[i].(PropertyMap)).String(), ShouldEqual, "s~aid:ns:/Pmap,3") |
+ So(KeyForObj(c, ifs[i].(PropertyMap)).String(), ShouldEqual, "s~aid:ns:/Pmap,3") |
case 3: |
- So(ds.KeyForObj(*ifs[i].(*PropertyMap)).String(), ShouldEqual, "s~aid:ns:/Pmap,4") |
+ So(KeyForObj(c, *ifs[i].(*PropertyMap)).String(), ShouldEqual, "s~aid:ns:/Pmap,4") |
} |
} |
}) |
}) |
}) |
- |
- Convey("Testing PutMulti", func() { |
- Convey("Fails for something other than a slice.", func() { |
- cs := CommonStruct{} |
- So(func() { ds.PutMulti(&cs) }, ShouldPanicLike, |
- "argument must be a slice, not *datastore.CommonStruct") |
- }) |
- |
- Convey("Succeeds for a slice.", func() { |
- cs := []CommonStruct{{Value: 0}, {Value: 1}} |
- So(ds.PutMulti(cs), ShouldBeNil) |
- So(cs[0].ID, ShouldEqual, 1) |
- So(cs[1].ID, ShouldEqual, 2) |
- }) |
- |
- Convey("Returns an item error in a MultiError.", func() { |
- cs := []FakePLS{{Value: 0}, {Kind: "Fail"}} |
- err := ds.PutMulti(cs) |
- So(err, ShouldResemble, errors.MultiError{nil, errFail}) |
- So(cs[0].IntID, ShouldEqual, 1) |
- }) |
- }) |
}) |
} |
@@ -788,56 +751,55 @@ func TestExists(t *testing.T) { |
Convey("A testing environment", t, func() { |
c := info.Set(context.Background(), fakeInfo{}) |
c = SetRawFactory(c, fakeDatastoreFactory) |
- ds := Get(c) |
- k := ds.MakeKey("Hello", "world") |
+ k := MakeKey(c, "Hello", "world") |
Convey("Exists", func() { |
// Single key. |
- er, err := ds.Exists(k) |
+ er, err := Exists(c, k) |
So(err, ShouldBeNil) |
So(er.All(), ShouldBeTrue) |
// Single key failure. |
- _, err = ds.Exists(ds.MakeKey("Fail", "boom")) |
+ _, err = Exists(c, MakeKey(c, "Fail", "boom")) |
So(err, ShouldEqual, errFail) |
// Single slice of keys. |
- er, err = ds.Exists([]*Key{k, ds.MakeKey("hello", "other")}) |
+ er, err = Exists(c, []*Key{k, MakeKey(c, "hello", "other")}) |
So(err, ShouldBeNil) |
So(er.All(), ShouldBeTrue) |
// Single slice of keys failure. |
- er, err = ds.Exists([]*Key{k, ds.MakeKey("Fail", "boom")}) |
+ er, err = Exists(c, []*Key{k, MakeKey(c, "Fail", "boom")}) |
So(err, ShouldResemble, errors.MultiError{nil, errFail}) |
So(er.Get(0, 0), ShouldBeTrue) |
// Single key missing. |
- er, err = ds.Exists(ds.MakeKey("DNE", "nope")) |
+ er, err = Exists(c, MakeKey(c, "DNE", "nope")) |
So(err, ShouldBeNil) |
So(er.Any(), ShouldBeFalse) |
// Multi-arg keys with one missing. |
- er, err = ds.Exists(k, ds.MakeKey("DNE", "other")) |
+ er, err = Exists(c, k, MakeKey(c, "DNE", "other")) |
So(err, ShouldBeNil) |
So(er.Get(0), ShouldBeTrue) |
So(er.Get(1), ShouldBeFalse) |
// Multi-arg keys with two missing. |
- er, err = ds.Exists(ds.MakeKey("DNE", "nope"), ds.MakeKey("DNE", "other")) |
+ er, err = Exists(c, MakeKey(c, "DNE", "nope"), MakeKey(c, "DNE", "other")) |
So(err, ShouldBeNil) |
So(er.Any(), ShouldBeFalse) |
// Single struct pointer. |
- er, err = ds.Exists(&CommonStruct{ID: 1}) |
+ er, err = Exists(c, &CommonStruct{ID: 1}) |
So(err, ShouldBeNil) |
So(er.All(), ShouldBeTrue) |
// Multi-arg mixed key/struct/slices. |
- er, err = ds.Exists( |
+ er, err = Exists(c, |
&CommonStruct{ID: 1}, |
[]*CommonStruct(nil), |
- []*Key{ds.MakeKey("DNE", "nope"), ds.MakeKey("hello", "ohai")}, |
+ []*Key{MakeKey(c, "DNE", "nope"), MakeKey(c, "hello", "ohai")}, |
) |
So(err, ShouldBeNil) |
So(er.Get(0), ShouldBeTrue) |
@@ -846,19 +808,6 @@ func TestExists(t *testing.T) { |
So(er.Get(2, 0), ShouldBeFalse) |
So(er.Get(2, 1), ShouldBeTrue) |
}) |
- |
- Convey("ExistsMulti", func() { |
- Convey("Returns no error if there are no failures.", func() { |
- bl, err := ds.ExistsMulti([]*Key{k, ds.MakeKey("DNE", "nope"), ds.MakeKey("hello", "ohai")}) |
- So(err, ShouldBeNil) |
- So(bl, ShouldResemble, BoolList{true, false, true}) |
- }) |
- |
- Convey("Returns an item error in a MultiError.", func() { |
- _, err := ds.ExistsMulti([]*Key{k, ds.MakeKey("Fail", "boom")}) |
- So(err, ShouldResemble, errors.MultiError{nil, errFail}) |
- }) |
- }) |
}) |
} |
@@ -868,71 +817,58 @@ func TestDelete(t *testing.T) { |
Convey("A testing environment", t, func() { |
c := info.Set(context.Background(), fakeInfo{}) |
c = SetRawFactory(c, fakeDatastoreFactory) |
- ds := Get(c) |
- So(ds, ShouldNotBeNil) |
Convey("Testing Delete", func() { |
Convey("bad", func() { |
Convey("get single error for RPC failure", func() { |
keys := []*Key{ |
- MakeKey("s~aid", "ns", "FailAll", 1), |
- MakeKey("s~aid", "ns", "Ok", 1), |
+ MakeKey(c, "s~aid", "ns", "FailAll", 1), |
+ MakeKey(c, "s~aid", "ns", "Ok", 1), |
} |
- So(ds.Delete(keys), ShouldEqual, errFailAll) |
+ So(Delete(c, keys), ShouldEqual, errFailAll) |
}) |
Convey("get multi error for individual failure", func() { |
keys := []*Key{ |
- ds.MakeKey("Ok", 1), |
- ds.MakeKey("Fail", 2), |
+ MakeKey(c, "Ok", 1), |
+ MakeKey(c, "Fail", 2), |
} |
- So(ds.Delete(keys), ShouldResemble, errors.MultiError{nil, errFail}) |
+ So(Delete(c, keys), ShouldResemble, errors.MultiError{nil, errFail}) |
}) |
Convey("put with non-modifyable type is an error", func() { |
cs := CommonStruct{} |
- So(func() { ds.Put(cs) }, ShouldPanicLike, |
+ So(func() { Put(c, cs) }, ShouldPanicLike, |
"invalid input type (datastore.CommonStruct): not a pointer") |
}) |
Convey("get single error when deleting a single", func() { |
- k := ds.MakeKey("Fail", 1) |
- So(ds.Delete(k), ShouldEqual, errFail) |
+ k := MakeKey(c, "Fail", 1) |
+ So(Delete(c, k), ShouldEqual, errFail) |
}) |
}) |
Convey("good", func() { |
// Single struct pointer. |
- So(ds.Delete(&CommonStruct{ID: 1}), ShouldBeNil) |
+ So(Delete(c, &CommonStruct{ID: 1}), ShouldBeNil) |
// Single key. |
- So(ds.Delete(ds.MakeKey("hello", "ohai")), ShouldBeNil) |
+ So(Delete(c, MakeKey(c, "hello", "ohai")), ShouldBeNil) |
// Single struct DNE. |
- So(ds.Delete(&CommonStruct{ID: noSuchEntityID}), ShouldEqual, ErrNoSuchEntity) |
+ So(Delete(c, &CommonStruct{ID: noSuchEntityID}), ShouldEqual, ErrNoSuchEntity) |
// Single key DNE. |
- So(ds.Delete(ds.MakeKey("DNE", "nope")), ShouldEqual, ErrNoSuchEntity) |
+ So(Delete(c, MakeKey(c, "DNE", "nope")), ShouldEqual, ErrNoSuchEntity) |
// Mixed key/struct/slices. |
- err := ds.Delete( |
+ err := Delete(c, |
&CommonStruct{ID: 1}, |
- []*Key{ds.MakeKey("hello", "ohai"), ds.MakeKey("DNE", "nope")}, |
+ []*Key{MakeKey(c, "hello", "ohai"), MakeKey(c, "DNE", "nope")}, |
) |
So(err, ShouldResemble, errors.MultiError{nil, errors.MultiError{nil, ErrNoSuchEntity}}) |
}) |
}) |
- |
- Convey("Testing DeleteMulti", func() { |
- Convey("Succeeds for valid keys.", func() { |
- So(ds.DeleteMulti([]*Key{ds.MakeKey("hello", "ohai")}), ShouldBeNil) |
- So(ds.DeleteMulti([]*Key{ds.MakeKey("hello", "ohai"), ds.MakeKey("hello", "sup")}), ShouldBeNil) |
- }) |
- |
- Convey("Returns an item error in a MultiError.", func() { |
- So(ds.DeleteMulti([]*Key{ds.MakeKey("DNE", "oops")}), ShouldResemble, errors.MultiError{ErrNoSuchEntity}) |
- }) |
- }) |
}) |
} |
@@ -942,20 +878,18 @@ func TestGet(t *testing.T) { |
Convey("A testing environment", t, func() { |
c := info.Set(context.Background(), fakeInfo{}) |
c = SetRawFactory(c, fakeDatastoreFactory) |
- ds := Get(c) |
- So(ds, ShouldNotBeNil) |
Convey("Testing Get", func() { |
Convey("bad", func() { |
Convey("static can't serialize", func() { |
toGet := []badStruct{{}, {}} |
- So(func() { ds.Get(toGet) }, ShouldPanicLike, |
+ So(func() { Get(c, toGet) }, ShouldPanicLike, |
`field "Compy" has invalid type: complex64`) |
}) |
Convey("can't get keys", func() { |
fplss := []FakePLS{{failGetMeta: true}, {}} |
- So(ds.Get(fplss), ShouldErrLike, "unable to extract $kind") |
+ So(Get(c, fplss), ShouldErrLike, "unable to extract $kind") |
}) |
Convey("get single error for RPC failure", func() { |
@@ -963,35 +897,35 @@ func TestGet(t *testing.T) { |
{IntID: 1, Kind: "FailAll"}, |
{IntID: 2}, |
} |
- So(ds.Get(fplss), ShouldEqual, errFailAll) |
+ So(Get(c, fplss), ShouldEqual, errFailAll) |
}) |
Convey("get multi error for individual failures", func() { |
fplss := []FakePLS{{IntID: 1}, {IntID: 2, Kind: "Fail"}} |
- So(ds.Get(fplss), ShouldResemble, errors.MultiError{nil, errFail}) |
+ So(Get(c, fplss), ShouldResemble, errors.MultiError{nil, errFail}) |
}) |
Convey("get with non-modifiable type is an error", func() { |
cs := CommonStruct{} |
- So(func() { ds.Get(cs) }, ShouldPanicLike, |
+ So(func() { Get(c, cs) }, ShouldPanicLike, |
"invalid input type (datastore.CommonStruct): not a pointer") |
}) |
Convey("get with nil is an error", func() { |
- So(func() { ds.Get(nil) }, ShouldPanicLike, |
+ So(func() { Get(c, nil) }, ShouldPanicLike, |
"cannot use nil as single argument") |
}) |
Convey("get with ptr-to-nonstruct is an error", func() { |
val := 100 |
- So(func() { ds.Get(&val) }, ShouldPanicLike, |
+ So(func() { Get(c, &val) }, ShouldPanicLike, |
"invalid input type (*int): not a PLS, pointer-to-struct, or slice thereof") |
}) |
Convey("failure to save metadata is no problem though", func() { |
// It just won't save the key |
cs := &FakePLS{IntID: 10, failSetMeta: true} |
- So(ds.Get(cs), ShouldBeNil) |
+ So(Get(c, cs), ShouldBeNil) |
}) |
Convey("vararg with errors", func() { |
@@ -1002,7 +936,7 @@ func TestGet(t *testing.T) { |
failPLS := CommonStruct{ID: noSuchEntityID} |
fpls := FakePLS{StringID: "ohai"} |
- err := ds.Get(successSlice, failSlice, emptySlice, &cs0, &failPLS, &fpls) |
+ err := Get(c, successSlice, failSlice, emptySlice, &cs0, &failPLS, &fpls) |
So(err, ShouldResemble, errors.MultiError{ |
nil, errors.MultiError{ErrNoSuchEntity, nil}, nil, nil, ErrNoSuchEntity, nil}) |
So(successSlice[0].Value, ShouldEqual, 1) |
@@ -1015,13 +949,13 @@ func TestGet(t *testing.T) { |
Convey("ok", func() { |
Convey("Get", func() { |
cs := &CommonStruct{ID: 1} |
- So(ds.Get(cs), ShouldBeNil) |
+ So(Get(c, cs), ShouldBeNil) |
So(cs.Value, ShouldEqual, 1) |
}) |
Convey("Raw access too", func() { |
- rds := ds.Raw() |
- keys := []*Key{ds.MakeKey("Kind", 1)} |
+ rds := Raw(c) |
+ keys := []*Key{MakeKey(c, "Kind", 1)} |
So(rds.GetMulti(keys, nil, func(pm PropertyMap, err error) error { |
So(err, ShouldBeNil) |
So(pm["Value"][0].Value(), ShouldEqual, 1) |
@@ -1031,14 +965,14 @@ func TestGet(t *testing.T) { |
Convey("but general failure to save is fine on a Get", func() { |
cs := &FakePLS{failSave: true, IntID: 7} |
- So(ds.Get(cs), ShouldBeNil) |
+ So(Get(c, cs), ShouldBeNil) |
}) |
Convey("vararg", func() { |
successSlice := []CommonStruct{{ID: 1}, {ID: 2}} |
cs := CommonStruct{ID: 3} |
- err := ds.Get(successSlice, &cs) |
+ err := Get(c, successSlice, &cs) |
So(err, ShouldBeNil) |
So(successSlice[0].Value, ShouldEqual, 1) |
So(successSlice[1].Value, ShouldEqual, 2) |
@@ -1046,27 +980,6 @@ func TestGet(t *testing.T) { |
}) |
}) |
}) |
- |
- Convey("Testing GetMulti", func() { |
- Convey("Fails for something other than a slice.", func() { |
- cs := CommonStruct{} |
- So(func() { ds.GetMulti(&cs) }, ShouldPanicLike, |
- "argument must be a slice, not *datastore.CommonStruct") |
- }) |
- |
- Convey("Succeeds for a slice.", func() { |
- cs := []CommonStruct{{ID: 1}} |
- So(ds.GetMulti(cs), ShouldBeNil) |
- So(cs[0].Value, ShouldEqual, 1) |
- }) |
- |
- Convey("Returns an item error in a MultiError.", func() { |
- cs := []CommonStruct{{ID: 1}, {ID: noSuchEntityID}} |
- err := ds.GetMulti(cs) |
- So(err, ShouldResemble, errors.MultiError{nil, ErrNoSuchEntity}) |
- So(cs[0].Value, ShouldEqual, 1) |
- }) |
- }) |
}) |
} |
@@ -1076,31 +989,29 @@ func TestGetAll(t *testing.T) { |
Convey("Test GetAll", t, func() { |
c := info.Set(context.Background(), fakeInfo{}) |
c = SetRawFactory(c, fakeDatastoreFactory) |
- ds := Get(c) |
- So(ds, ShouldNotBeNil) |
q := NewQuery("").Limit(5) |
Convey("bad", func() { |
Convey("nil target", func() { |
- So(func() { ds.GetAll(q, (*[]PropertyMap)(nil)) }, ShouldPanicLike, |
+ So(func() { GetAll(c, q, (*[]PropertyMap)(nil)) }, ShouldPanicLike, |
"invalid GetAll dst: <nil>") |
}) |
Convey("bad type", func() { |
output := 100 |
- So(func() { ds.GetAll(q, &output) }, ShouldPanicLike, |
+ So(func() { GetAll(c, q, &output) }, ShouldPanicLike, |
"invalid argument type: expected slice, got int") |
}) |
Convey("bad type (non pointer)", func() { |
- So(func() { ds.GetAll(q, "moo") }, ShouldPanicLike, |
+ So(func() { GetAll(c, q, "moo") }, ShouldPanicLike, |
"invalid GetAll dst: must have a ptr-to-slice") |
}) |
Convey("bad type (underspecified)", func() { |
output := []PropertyLoadSaver(nil) |
- So(func() { ds.GetAll(q, &output) }, ShouldPanicLike, |
+ So(func() { GetAll(c, q, &output) }, ShouldPanicLike, |
"invalid GetAll dst (non-concrete element type): *[]datastore.PropertyLoadSaver") |
}) |
}) |
@@ -1108,7 +1019,7 @@ func TestGetAll(t *testing.T) { |
Convey("ok", func() { |
Convey("*[]S", func() { |
output := []CommonStruct(nil) |
- So(ds.GetAll(q, &output), ShouldBeNil) |
+ So(GetAll(c, q, &output), ShouldBeNil) |
So(len(output), ShouldEqual, 5) |
for i, o := range output { |
So(o.ID, ShouldEqual, i+1) |
@@ -1118,7 +1029,7 @@ func TestGetAll(t *testing.T) { |
Convey("*[]*S", func() { |
output := []*CommonStruct(nil) |
- So(ds.GetAll(q, &output), ShouldBeNil) |
+ So(GetAll(c, q, &output), ShouldBeNil) |
So(len(output), ShouldEqual, 5) |
for i, o := range output { |
So(o.ID, ShouldEqual, i+1) |
@@ -1128,7 +1039,7 @@ func TestGetAll(t *testing.T) { |
Convey("*[]P", func() { |
output := []FakePLS(nil) |
- So(ds.GetAll(q, &output), ShouldBeNil) |
+ So(GetAll(c, q, &output), ShouldBeNil) |
So(len(output), ShouldEqual, 5) |
for i, o := range output { |
So(o.gotLoaded, ShouldBeTrue) |
@@ -1139,7 +1050,7 @@ func TestGetAll(t *testing.T) { |
Convey("*[]P (map)", func() { |
output := []PropertyMap(nil) |
- So(ds.GetAll(q, &output), ShouldBeNil) |
+ So(GetAll(c, q, &output), ShouldBeNil) |
So(len(output), ShouldEqual, 5) |
for i, o := range output { |
k, ok := o.GetMeta("key") |
@@ -1151,16 +1062,16 @@ func TestGetAll(t *testing.T) { |
Convey("*[]P (chan)", func() { |
output := []plsChan(nil) |
- So(ds.GetAll(q, &output), ShouldBeNil) |
+ So(GetAll(c, q, &output), ShouldBeNil) |
So(output, ShouldHaveLength, 5) |
for _, o := range output { |
- So(ds.KeyForObj(o).StringID(), ShouldEqual, "whyDoIExist") |
+ So(KeyForObj(c, o).StringID(), ShouldEqual, "whyDoIExist") |
} |
}) |
Convey("*[]*P", func() { |
output := []*FakePLS(nil) |
- So(ds.GetAll(q, &output), ShouldBeNil) |
+ So(GetAll(c, q, &output), ShouldBeNil) |
So(len(output), ShouldEqual, 5) |
for i, o := range output { |
So(o.gotLoaded, ShouldBeTrue) |
@@ -1171,7 +1082,7 @@ func TestGetAll(t *testing.T) { |
Convey("*[]*P (map)", func() { |
output := []*PropertyMap(nil) |
- So(ds.GetAll(q, &output), ShouldBeNil) |
+ So(GetAll(c, q, &output), ShouldBeNil) |
So(len(output), ShouldEqual, 5) |
for i, op := range output { |
o := *op |
@@ -1184,16 +1095,16 @@ func TestGetAll(t *testing.T) { |
Convey("*[]*P (chan)", func() { |
output := []*plsChan(nil) |
- So(ds.GetAll(q, &output), ShouldBeNil) |
+ So(GetAll(c, q, &output), ShouldBeNil) |
So(output, ShouldHaveLength, 5) |
for _, o := range output { |
- So(ds.KeyForObj(o).StringID(), ShouldEqual, "whyDoIExist") |
+ So(KeyForObj(c, o).StringID(), ShouldEqual, "whyDoIExist") |
} |
}) |
Convey("*[]*Key", func() { |
output := []*Key(nil) |
- So(ds.GetAll(q, &output), ShouldBeNil) |
+ So(GetAll(c, q, &output), ShouldBeNil) |
So(len(output), ShouldEqual, 5) |
for i, k := range output { |
So(k.IntID(), ShouldEqual, i+1) |
@@ -1210,14 +1121,12 @@ func TestRun(t *testing.T) { |
Convey("Test Run", t, func() { |
c := info.Set(context.Background(), fakeInfo{}) |
c = SetRawFactory(c, fakeDatastoreFactory) |
- ds := Get(c) |
- So(ds, ShouldNotBeNil) |
q := NewQuery("kind").Limit(5) |
Convey("bad", func() { |
assertBadTypePanics := func(cb interface{}) { |
- So(func() { ds.Run(q, cb) }, ShouldPanicLike, |
+ So(func() { Run(c, q, cb) }, ShouldPanicLike, |
"cb does not match the required callback signature") |
} |
@@ -1237,7 +1146,7 @@ func TestRun(t *testing.T) { |
cb := func(v int) { |
panic("never here!") |
} |
- So(func() { ds.Run(q, cb) }, ShouldPanicLike, |
+ So(func() { Run(c, q, cb) }, ShouldPanicLike, |
"invalid argument type: int is not a PLS or pointer-to-struct") |
}) |
@@ -1268,14 +1177,14 @@ func TestRun(t *testing.T) { |
Convey("early abort on error", func() { |
q = q.Eq("$err_single", "Query fail").Eq("$err_single_idx", 3) |
i := 0 |
- So(ds.Run(q, func(c CommonStruct) { |
+ So(Run(c, q, func(c CommonStruct) { |
i++ |
}), ShouldErrLike, "Query fail") |
So(i, ShouldEqual, 3) |
}) |
Convey("return error on serialization failure", func() { |
- So(ds.Run(q, func(_ permaBad) { |
+ So(Run(c, q, func(_ permaBad) { |
panic("never here") |
}).Error(), ShouldEqual, "permaBad") |
}) |
@@ -1284,14 +1193,14 @@ func TestRun(t *testing.T) { |
Convey("ok", func() { |
Convey("can return error to stop", func() { |
i := 0 |
- So(ds.Run(q, func(c CommonStruct) error { |
+ So(Run(c, q, func(c CommonStruct) error { |
i++ |
return Stop |
}), ShouldBeNil) |
So(i, ShouldEqual, 1) |
i = 0 |
- So(ds.Run(q, func(c CommonStruct, _ CursorCB) error { |
+ So(Run(c, q, func(c CommonStruct, _ CursorCB) error { |
i++ |
return fmt.Errorf("my error") |
}), ShouldErrLike, "my error") |
@@ -1300,7 +1209,7 @@ func TestRun(t *testing.T) { |
Convey("Can optionally get cursor function", func() { |
i := 0 |
- So(ds.Run(q, func(c CommonStruct, ccb CursorCB) { |
+ So(Run(c, q, func(c CommonStruct, ccb CursorCB) { |
i++ |
curs, err := ccb() |
So(err, ShouldBeNil) |
@@ -1311,7 +1220,7 @@ func TestRun(t *testing.T) { |
Convey("*S", func() { |
i := 0 |
- So(ds.Run(q, func(cs *CommonStruct) { |
+ So(Run(c, q, func(cs *CommonStruct) { |
So(cs.ID, ShouldEqual, i+1) |
So(cs.Value, ShouldEqual, i) |
i++ |
@@ -1320,7 +1229,7 @@ func TestRun(t *testing.T) { |
Convey("*P", func() { |
i := 0 |
- So(ds.Run(q.Limit(12), func(fpls *FakePLS) { |
+ So(Run(c, q.Limit(12), func(fpls *FakePLS) { |
So(fpls.gotLoaded, ShouldBeTrue) |
if i == 10 { |
So(fpls.StringID, ShouldEqual, "eleven") |
@@ -1334,7 +1243,7 @@ func TestRun(t *testing.T) { |
Convey("*P (map)", func() { |
i := 0 |
- So(ds.Run(q, func(pm *PropertyMap) { |
+ So(Run(c, q, func(pm *PropertyMap) { |
k, ok := pm.GetMeta("key") |
So(ok, ShouldBeTrue) |
So(k.(*Key).IntID(), ShouldEqual, i+1) |
@@ -1344,14 +1253,14 @@ func TestRun(t *testing.T) { |
}) |
Convey("*P (chan)", func() { |
- So(ds.Run(q, func(c *plsChan) { |
- So(ds.KeyForObj(c).StringID(), ShouldEqual, "whyDoIExist") |
+ So(Run(c, q, func(ch *plsChan) { |
+ So(KeyForObj(c, ch).StringID(), ShouldEqual, "whyDoIExist") |
}), ShouldBeNil) |
}) |
Convey("S", func() { |
i := 0 |
- So(ds.Run(q, func(cs CommonStruct) { |
+ So(Run(c, q, func(cs CommonStruct) { |
So(cs.ID, ShouldEqual, i+1) |
So(cs.Value, ShouldEqual, i) |
i++ |
@@ -1360,7 +1269,7 @@ func TestRun(t *testing.T) { |
Convey("P", func() { |
i := 0 |
- So(ds.Run(q, func(fpls FakePLS) { |
+ So(Run(c, q, func(fpls FakePLS) { |
So(fpls.gotLoaded, ShouldBeTrue) |
So(fpls.IntID, ShouldEqual, i+1) |
So(fpls.Value, ShouldEqual, i) |
@@ -1370,7 +1279,7 @@ func TestRun(t *testing.T) { |
Convey("P (map)", func() { |
i := 0 |
- So(ds.Run(q, func(pm PropertyMap) { |
+ So(Run(c, q, func(pm PropertyMap) { |
k, ok := pm.GetMeta("key") |
So(ok, ShouldBeTrue) |
So(k.(*Key).IntID(), ShouldEqual, i+1) |
@@ -1380,14 +1289,14 @@ func TestRun(t *testing.T) { |
}) |
Convey("P (chan)", func() { |
- So(ds.Run(q, func(c plsChan) { |
- So(ds.KeyForObj(c).StringID(), ShouldEqual, "whyDoIExist") |
+ So(Run(c, q, func(ch plsChan) { |
+ So(KeyForObj(c, ch).StringID(), ShouldEqual, "whyDoIExist") |
}), ShouldBeNil) |
}) |
Convey("Key", func() { |
i := 0 |
- So(ds.Run(q, func(k *Key) { |
+ So(Run(c, q, func(k *Key) { |
So(k.IntID(), ShouldEqual, i+1) |
i++ |
}), ShouldBeNil) |
@@ -1434,14 +1343,15 @@ func TestSchemaChange(t *testing.T) { |
Convey("Test changing schemas", t, func() { |
fds := fixedDataDatastore{} |
- ds := &datastoreImpl{&fds, "", ""} |
+ c := info.Set(context.Background(), fakeInfo{}) |
+ c = SetRaw(c, &fds) |
Convey("Can add fields", func() { |
initial := PropertyMap{ |
- "$key": {mpNI(ds.MakeKey("Val", 10))}, |
+ "$key": {mpNI(MakeKey(c, "Val", 10))}, |
"Val": {mp(100)}, |
} |
- So(ds.Put(initial), ShouldBeNil) |
+ So(Put(c, initial), ShouldBeNil) |
type Val struct { |
ID int64 `gae:"$id"` |
@@ -1450,17 +1360,17 @@ func TestSchemaChange(t *testing.T) { |
TwoVal int64 // whoa, TWO vals! amazing |
} |
tv := &Val{ID: 10, TwoVal: 2} |
- So(ds.Get(tv), ShouldBeNil) |
+ So(Get(c, tv), ShouldBeNil) |
So(tv, ShouldResemble, &Val{ID: 10, Val: 100, TwoVal: 2}) |
}) |
Convey("Removing fields", func() { |
initial := PropertyMap{ |
- "$key": {mpNI(ds.MakeKey("Val", 10))}, |
+ "$key": {mpNI(MakeKey(c, "Val", 10))}, |
"Val": {mp(100)}, |
"TwoVal": {mp(200)}, |
} |
- So(ds.Put(initial), ShouldBeNil) |
+ So(Put(c, initial), ShouldBeNil) |
Convey("is normally an error", func() { |
type Val struct { |
@@ -1469,7 +1379,7 @@ func TestSchemaChange(t *testing.T) { |
Val int64 |
} |
tv := &Val{ID: 10} |
- So(ds.Get(tv), ShouldErrLike, |
+ So(Get(c, tv), ShouldErrLike, |
`gae: cannot load field "TwoVal" into a "datastore.Val`) |
So(tv, ShouldResemble, &Val{ID: 10, Val: 100}) |
}) |
@@ -1482,7 +1392,7 @@ func TestSchemaChange(t *testing.T) { |
Extra PropertyMap `gae:",extra"` |
} |
tv := &Val{ID: 10} |
- So(ds.Get(tv), ShouldBeNil) |
+ So(Get(c, tv), ShouldBeNil) |
So(tv, ShouldResemble, &Val{ |
ID: 10, |
Val: 100, |
@@ -1504,10 +1414,10 @@ func TestSchemaChange(t *testing.T) { |
"Hello": {mp("Hello")}, |
"World": {mp(true)}, |
}} |
- So(ds.Put(ex), ShouldBeNil) |
+ So(Put(c, ex), ShouldBeNil) |
ex = &Expando{ID: 10} |
- So(ds.Get(ex), ShouldBeNil) |
+ So(Get(c, ex), ShouldBeNil) |
So(ex, ShouldResemble, &Expando{ |
ID: 10, |
Something: 17, |
@@ -1520,11 +1430,11 @@ func TestSchemaChange(t *testing.T) { |
Convey("Can read-but-not-write", func() { |
initial := PropertyMap{ |
- "$key": {mpNI(ds.MakeKey("Convert", 10))}, |
+ "$key": {mpNI(MakeKey(c, "Convert", 10))}, |
"Val": {mp(100)}, |
"TwoVal": {mp(200)}, |
} |
- So(ds.Put(initial), ShouldBeNil) |
+ So(Put(c, initial), ShouldBeNil) |
type Convert struct { |
ID int64 `gae:"$id"` |
@@ -1532,28 +1442,28 @@ func TestSchemaChange(t *testing.T) { |
NewVal int64 |
Extra PropertyMap `gae:"-,extra"` |
} |
- c := &Convert{ID: 10} |
- So(ds.Get(c), ShouldBeNil) |
- So(c, ShouldResemble, &Convert{ |
+ cnv := &Convert{ID: 10} |
+ So(Get(c, cnv), ShouldBeNil) |
+ So(cnv, ShouldResemble, &Convert{ |
ID: 10, Val: 100, NewVal: 0, Extra: PropertyMap{"TwoVal": {mp(200)}}, |
}) |
- c.NewVal = c.Extra["TwoVal"][0].Value().(int64) |
- So(ds.Put(c), ShouldBeNil) |
+ cnv.NewVal = cnv.Extra["TwoVal"][0].Value().(int64) |
+ So(Put(c, cnv), ShouldBeNil) |
- c = &Convert{ID: 10} |
- So(ds.Get(c), ShouldBeNil) |
- So(c, ShouldResemble, &Convert{ |
+ cnv = &Convert{ID: 10} |
+ So(Get(c, cnv), ShouldBeNil) |
+ So(cnv, ShouldResemble, &Convert{ |
ID: 10, Val: 100, NewVal: 200, Extra: nil, |
}) |
}) |
Convey("Can black hole", func() { |
initial := PropertyMap{ |
- "$key": {mpNI(ds.MakeKey("BlackHole", 10))}, |
+ "$key": {mpNI(MakeKey(c, "BlackHole", 10))}, |
"Val": {mp(100)}, |
"TwoVal": {mp(200)}, |
} |
- So(ds.Put(initial), ShouldBeNil) |
+ So(Put(c, initial), ShouldBeNil) |
type BlackHole struct { |
ID int64 `gae:"$id"` |
@@ -1561,16 +1471,16 @@ func TestSchemaChange(t *testing.T) { |
blackHole PropertyMap `gae:"-,extra"` |
} |
b := &BlackHole{ID: 10, NewStuff: "(╯°□°)╯︵ ┻━┻"} |
- So(ds.Get(b), ShouldBeNil) |
+ So(Get(c, b), ShouldBeNil) |
So(b, ShouldResemble, &BlackHole{ID: 10, NewStuff: "(╯°□°)╯︵ ┻━┻"}) |
}) |
Convey("Can change field types", func() { |
initial := PropertyMap{ |
- "$key": {mpNI(ds.MakeKey("IntChange", 10))}, |
+ "$key": {mpNI(MakeKey(c, "IntChange", 10))}, |
"Val": {mp(100)}, |
} |
- So(ds.Put(initial), ShouldBeNil) |
+ So(Put(c, initial), ShouldBeNil) |
type IntChange struct { |
ID int64 `gae:"$id"` |
@@ -1578,13 +1488,13 @@ func TestSchemaChange(t *testing.T) { |
Extra PropertyMap `gae:"-,extra"` |
} |
i := &IntChange{ID: 10} |
- So(ds.Get(i), ShouldBeNil) |
+ So(Get(c, i), ShouldBeNil) |
So(i, ShouldResemble, &IntChange{ID: 10, Extra: PropertyMap{"Val": {mp(100)}}}) |
i.Val = fmt.Sprint(i.Extra["Val"][0].Value()) |
- So(ds.Put(i), ShouldBeNil) |
+ So(Put(c, i), ShouldBeNil) |
i = &IntChange{ID: 10} |
- So(ds.Get(i), ShouldBeNil) |
+ So(Get(c, i), ShouldBeNil) |
So(i, ShouldResemble, &IntChange{ID: 10, Val: "100"}) |
}) |
@@ -1598,10 +1508,10 @@ func TestSchemaChange(t *testing.T) { |
"Val": {mp(200)}, |
"Other": {mp("other")}, |
}} |
- So(ds.Put(d), ShouldBeNil) |
+ So(Put(c, d), ShouldBeNil) |
d = &Dup{ID: 10} |
- So(ds.Get(d), ShouldBeNil) |
+ So(Get(c, d), ShouldBeNil) |
So(d, ShouldResemble, &Dup{ |
ID: 10, Val: 100, Extra: PropertyMap{"Other": {mp("other")}}, |
}) |
@@ -1609,10 +1519,10 @@ func TestSchemaChange(t *testing.T) { |
Convey("Can change repeated field to non-repeating field", func() { |
initial := PropertyMap{ |
- "$key": {mpNI(ds.MakeKey("NonRepeating", 10))}, |
+ "$key": {mpNI(MakeKey(c, "NonRepeating", 10))}, |
"Val": {mp(100), mp(200), mp(400)}, |
} |
- So(ds.Put(initial), ShouldBeNil) |
+ So(Put(c, initial), ShouldBeNil) |
type NonRepeating struct { |
ID int64 `gae:"$id"` |
@@ -1620,7 +1530,7 @@ func TestSchemaChange(t *testing.T) { |
Extra PropertyMap `gae:",extra"` |
} |
n := &NonRepeating{ID: 10} |
- So(ds.Get(n), ShouldBeNil) |
+ So(Get(c, n), ShouldBeNil) |
So(n, ShouldResemble, &NonRepeating{ |
ID: 10, Val: 0, Extra: PropertyMap{ |
"Val": {mp(100), mp(200), mp(400)}, |
@@ -1630,12 +1540,12 @@ func TestSchemaChange(t *testing.T) { |
Convey("Deals correctly with recursive types", func() { |
initial := PropertyMap{ |
- "$key": {mpNI(ds.MakeKey("Outer", 10))}, |
+ "$key": {mpNI(MakeKey(c, "Outer", 10))}, |
"I.A": {mp(1), mp(2), mp(4)}, |
"I.B": {mp(10), mp(20), mp(40)}, |
"I.C": {mp(100), mp(200), mp(400)}, |
} |
- So(ds.Put(initial), ShouldBeNil) |
+ So(Put(c, initial), ShouldBeNil) |
type Inner struct { |
A int64 |
B int64 |
@@ -1647,7 +1557,7 @@ func TestSchemaChange(t *testing.T) { |
Extra PropertyMap `gae:",extra"` |
} |
o := &Outer{ID: 10} |
- So(ds.Get(o), ShouldBeNil) |
+ So(Get(c, o), ShouldBeNil) |
So(o, ShouldResemble, &Outer{ |
ID: 10, |
I: []Inner{ |