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

Unified Diff: impl/memory/testing_utils_test.go

Issue 1302813003: impl/memory: Implement Queries (Closed) Base URL: https://github.com/luci/gae.git@add_multi_iterator
Patch Set: stringSet everywhere 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
« no previous file with comments | « impl/memory/taskqueue_data.go ('k') | service/datastore/datastore.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: impl/memory/testing_utils_test.go
diff --git a/impl/memory/testing_utils_test.go b/impl/memory/testing_utils_test.go
index 42089586997a7def196ccc522fddec056cc7f6d6..513c0985098b1622968f578a96c646ecffdd3400 100644
--- a/impl/memory/testing_utils_test.go
+++ b/impl/memory/testing_utils_test.go
@@ -7,6 +7,7 @@ package memory
import (
"bytes"
"fmt"
+ "strings"
"time"
ds "github.com/luci/gae/service/datastore"
@@ -15,7 +16,57 @@ import (
"github.com/luci/luci-go/common/cmpbin"
)
-type kv struct{ k, v []byte }
+func init() {
+ serializationDeterministic = true
+ serialize.WritePropertyMapDeterministic = true
+}
+
+var NEXT_STR = "NEXT MARKER"
+var NEXT = &NEXT_STR
+
+// Use like:
+// pmap(
+// "prop", "val", 0, 100, NEXT,
+// "other", "val", 0, 100, NEXT,
+// )
+//
+func pmap(stuff ...interface{}) ds.PropertyMap {
+ ret := ds.PropertyMap{}
+
+ nom := func() interface{} {
+ if len(stuff) > 0 {
+ ret := stuff[0]
+ stuff = stuff[1:]
+ return ret
+ }
+ return nil
+ }
+
+ for len(stuff) > 0 {
+ pname := nom().(string)
+ if pname[0] == '$' || (strings.HasPrefix(pname, "__") && strings.HasSuffix(pname, "__")) {
+ for len(stuff) > 0 && stuff[0] != NEXT {
+ ret[pname] = append(ret[pname], propNI(nom()))
+ }
+ } else {
+ for len(stuff) > 0 && stuff[0] != NEXT {
+ ret[pname] = append(ret[pname], prop(nom()))
+ }
+ }
+ nom()
+ }
+
+ return ret
+}
+
+func nq(kind_ns ...string) ds.Query {
+ if len(kind_ns) == 2 {
+ return &queryImpl{kind: kind_ns[0], ns: kind_ns[1]}
+ } else if len(kind_ns) == 1 {
+ return &queryImpl{kind: kind_ns[0], ns: "ns"}
+ }
+ return &queryImpl{kind: "Foo", ns: "ns"}
+}
func indx(kind string, orders ...string) *ds.IndexDefinition {
ancestor := false
@@ -51,7 +102,7 @@ func key(kind string, id interface{}, parent ...ds.Key) ds.Key {
case int:
return dskey.New(globalAppID, "ns", kind, "", int64(x), p)
default:
- panic(fmt.Errorf("what the %T: %v", id, id))
+ return dskey.New(globalAppID, "ns", kind, "invalid", 100, p)
}
}
@@ -85,6 +136,8 @@ func cat(bytethings ...interface{}) []byte {
serialize.WriteKey(buf, serialize.WithoutContext, x)
case *ds.IndexDefinition:
serialize.WriteIndexDefinition(buf, *x)
+ case ds.Property:
+ serialize.WriteProperty(buf, serialize.WithoutContext, x)
default:
panic(fmt.Errorf("I don't know how to deal with %T: %#v", thing, thing))
}
« no previous file with comments | « impl/memory/taskqueue_data.go ('k') | service/datastore/datastore.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698