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

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: inequalities work now 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/testing_utils_test.go
diff --git a/impl/memory/testing_utils_test.go b/impl/memory/testing_utils_test.go
index 42089586997a7def196ccc522fddec056cc7f6d6..cc9a8c8411dc364f7a2bbbe440ed6c8309de6b8f 100644
--- a/impl/memory/testing_utils_test.go
+++ b/impl/memory/testing_utils_test.go
@@ -15,7 +15,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] == '$' {
+ 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 +101,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 +135,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))
}

Powered by Google App Engine
This is Rietveld 408576698