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

Unified Diff: impl/memory/datastore_test.go

Issue 1286943002: impl/memory: Make queries self-validate (Closed) Base URL: https://github.com/luci/gae.git@add_datastore_testable
Patch Set: rebase 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/datastore_query_test.go ('k') | service/datastore/errors.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: impl/memory/datastore_test.go
diff --git a/impl/memory/datastore_test.go b/impl/memory/datastore_test.go
index 29de8ac6ca58bea3ebefc8174f1b7349fea8cf2d..03c20c14a41e277b4943152b9692a68075315728 100644
--- a/impl/memory/datastore_test.go
+++ b/impl/memory/datastore_test.go
@@ -7,7 +7,6 @@ package memory
import (
"bytes"
"fmt"
- "math"
"testing"
dsS "github.com/luci/gae/service/datastore"
@@ -423,163 +422,6 @@ func TestDatastoreSingleReadWriter(t *testing.T) {
})
}
-const MaxUint = ^uint(0)
-const MaxInt = int(MaxUint >> 1)
-const IntIs32Bits = int64(MaxInt) < math.MaxInt64
-
-func TestDatastoreQueryer(t *testing.T) {
- Convey("Datastore Query suport", t, func() {
- c := Use(context.Background())
- ds := dsS.Get(c)
- So(ds, ShouldNotBeNil)
-
- Convey("can create good queries", func() {
- 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)
- qi := q.(*queryImpl).checkCorrectness("", false)
- So(qi.err, ShouldBeNil)
- })
-
- Convey("normalize ensures orders make sense", func() {
- q := ds.NewQuery("Cool")
- q = q.Filter("cat =", 19).Filter("bob =", 10).Order("bob").Order("bob")
-
- Convey("removes dups and equality orders", func() {
- q = q.Order("wat")
- qi := q.(*queryImpl).normalize().checkCorrectness("", false)
- So(qi.err, ShouldBeNil)
- So(qi.order, ShouldResemble, []dsS.IndexColumn{{Property: "wat"}})
- })
-
- Convey("keeps inequality orders", func() {
- q = q.Order("wat")
- q := q.Filter("bob >", 10).Filter("wat <", 29)
- qi := q.(*queryImpl).normalize().checkCorrectness("", false)
- So(qi.order, ShouldResemble, []dsS.IndexColumn{{Property: "bob"}, {Property: "wat"}})
- So(qi.err.Error(), ShouldContainSubstring, "Only one inequality")
- })
-
- Convey("if we equality-filter on __key__, order is ditched", func() {
- q = q.Order("wat")
- q := q.Filter("__key__ =", ds.NewKey("Foo", "wat", 0, nil))
- qi := q.(*queryImpl).normalize().checkCorrectness("", false)
- So(qi.order, ShouldResemble, []dsS.IndexColumn(nil))
- So(qi.err, ShouldBeNil)
- })
-
- Convey("if we order by key and something else, key dominates", func() {
- q := q.Order("__key__").Order("wat")
- qi := q.(*queryImpl).normalize().checkCorrectness("", false)
- So(qi.order, ShouldResemble, []dsS.IndexColumn{{Property: "__key__"}})
- So(qi.err, ShouldBeNil)
- })
- })
-
- Convey("can create bad queries", func() {
- q := ds.NewQuery("Foo")
-
- Convey("bad filter ops", func() {
- q := q.Filter("Bob !", "value")
- So(q.(*queryImpl).err.Error(), ShouldContainSubstring, "invalid operator \"!\"")
- })
- Convey("bad filter", func() {
- q := q.Filter("Bob", "value")
- So(q.(*queryImpl).err.Error(), ShouldContainSubstring, "invalid filter")
- })
- Convey("bad order", func() {
- q := q.Order("+Bob")
- So(q.(*queryImpl).err.Error(), ShouldContainSubstring, "invalid order")
- })
- Convey("empty", func() {
- q := q.Order("")
- So(q.(*queryImpl).err.Error(), ShouldContainSubstring, "empty order")
- })
- Convey("OOB limit", func() {
- // this is supremely stupid. The SDK uses 'int' which measn we have to
- // use it too, but then THEY BOUNDS CHECK IT FOR 32 BITS... *sigh*
- if !IntIs32Bits {
- q := q.Limit(MaxInt)
- So(q.(*queryImpl).err.Error(), ShouldContainSubstring, "query limit overflow")
- }
- })
- Convey("underflow offset", func() {
- q := q.Offset(-29)
- So(q.(*queryImpl).err.Error(), ShouldContainSubstring, "negative query offset")
- })
- Convey("OOB offset", func() {
- if !IntIs32Bits {
- q := q.Offset(MaxInt)
- So(q.(*queryImpl).err.Error(), ShouldContainSubstring, "query offset overflow")
- }
- })
- Convey("Bad cursors", func() {
- q := q.Start(queryCursor("")).End(queryCursor(""))
- So(q.(*queryImpl).err.Error(), ShouldContainSubstring, "invalid cursor")
- })
- Convey("Bad ancestors", func() {
- q := q.Ancestor(ds.NewKey("Goop", "wat", 10, nil))
- So(q, ShouldNotBeNil)
- qi := q.(*queryImpl).checkCorrectness("", false)
- 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__ =", ds.NewKey("Goop", "wat", 10, nil))
- qi := q.(*queryImpl).checkCorrectness("", false)
- 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(ds.NewKey("thing", "wat", 0, nil))
- for i := 0; i < 100; i++ {
- q = q.Filter("something =", 10)
- }
- qi := q.(*queryImpl).checkCorrectness("", false)
- So(qi.err.Error(), ShouldContainSubstring, "query is too large")
- })
- Convey("filters for __key__ that aren't keys", func() {
- q := q.Filter("__key__ = ", 10)
- qi := q.(*queryImpl).checkCorrectness("", false)
- So(qi.err.Error(), ShouldContainSubstring, "must be a Key")
- })
- Convey("multiple inequalities", func() {
- q := q.Filter("bob > ", 19).Filter("charlie < ", 20)
- qi := q.(*queryImpl).checkCorrectness("", false)
- So(qi.err.Error(), ShouldContainSubstring, "one inequality filter")
- })
- Convey("bad sort orders", func() {
- q := q.Filter("bob > ", 19).Order("-charlie")
- qi := q.(*queryImpl).checkCorrectness("", false)
- So(qi.err.Error(), ShouldContainSubstring, "first sort property")
- })
- Convey("kindless with non-__key__ filters", func() {
- 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 := 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 := ds.NewQuery("").Order("-__key__")
- qi := q.(*queryImpl).checkCorrectness("", false)
- So(qi.err.Error(), ShouldContainSubstring, "kind is required for all orders")
- })
- })
-
- })
-}
-
func TestCompoundIndexes(t *testing.T) {
t.Parallel()
« no previous file with comments | « impl/memory/datastore_query_test.go ('k') | service/datastore/errors.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698