OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package memory | 5 package memory |
6 | 6 |
7 import ( | 7 import ( |
8 "bytes" | 8 "bytes" |
9 "testing" | 9 "testing" |
10 | 10 |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 {"silly inequality (=> v <=)", | 109 {"silly inequality (=> v <=)", |
110 nq().Gte("bob", 10).Lte("bob", 10), | 110 nq().Gte("bob", 10).Lte("bob", 10), |
111 nil, nil}, | 111 nil, nil}, |
112 | 112 |
113 {"cursors get smooshed into the inquality range", | 113 {"cursors get smooshed into the inquality range", |
114 (nq().Gt("Foo", 3).Lt("Foo", 10). | 114 (nq().Gt("Foo", 3).Lt("Foo", 10). |
115 Start(curs("Foo", 2, "__key__", key("Something", 1))). | 115 Start(curs("Foo", 2, "__key__", key("Something", 1))). |
116 End(curs("Foo", 20, "__key__", key("Something", 20)))), | 116 End(curs("Foo", 20, "__key__", key("Something", 20)))), |
117 nil, | 117 nil, |
118 &reducedQuery{ | 118 &reducedQuery{ |
119 » » » "ns", "Foo", map[string]stringset.Set{}, []dstore.IndexC
olumn{ | 119 » » » "dev~app", "ns", "Foo", map[string]stringset.Set{}, []ds
tore.IndexColumn{ |
120 {Property: "Foo"}, | 120 {Property: "Foo"}, |
121 {Property: "__key__"}, | 121 {Property: "__key__"}, |
122 }, | 122 }, |
123 increment(serialize.ToBytes(dstore.MkProperty(3))), | 123 increment(serialize.ToBytes(dstore.MkProperty(3))), |
124 serialize.ToBytes(dstore.MkProperty(10)), | 124 serialize.ToBytes(dstore.MkProperty(10)), |
125 2, | 125 2, |
126 }}, | 126 }}, |
127 | 127 |
128 {"cursors could cause the whole query to be useless", | 128 {"cursors could cause the whole query to be useless", |
129 (nq().Gt("Foo", 3).Lt("Foo", 10). | 129 (nq().Gt("Foo", 3).Lt("Foo", 10). |
130 Start(curs("Foo", 200, "__key__", key("Something", 1))). | 130 Start(curs("Foo", 200, "__key__", key("Something", 1))). |
131 End(curs("Foo", 1, "__key__", key("Something", 20)))), | 131 End(curs("Foo", 1, "__key__", key("Something", 20)))), |
132 dstore.ErrNullQuery, | 132 dstore.ErrNullQuery, |
133 nil}, | 133 nil}, |
134 } | 134 } |
135 | 135 |
136 func TestQueries(t *testing.T) { | 136 func TestQueries(t *testing.T) { |
137 t.Parallel() | 137 t.Parallel() |
138 | 138 |
139 Convey("queries have tons of condition checking", t, func() { | 139 Convey("queries have tons of condition checking", t, func() { |
140 Convey("non-ancestor queries in a transaction", func() { | 140 Convey("non-ancestor queries in a transaction", func() { |
141 fq, err := nq().Finalize() | 141 fq, err := nq().Finalize() |
142 So(err, ShouldErrLike, nil) | 142 So(err, ShouldErrLike, nil) |
143 » » » _, err = reduce(fq, "ns", true) | 143 » » » _, err = reduce(fq, "dev~app", "ns", true) |
144 So(err, ShouldErrLike, "must include an Ancestor") | 144 So(err, ShouldErrLike, "must include an Ancestor") |
145 }) | 145 }) |
146 | 146 |
147 Convey("absurd numbers of filters are prohibited", func() { | 147 Convey("absurd numbers of filters are prohibited", func() { |
148 q := nq().Ancestor(key("thing", "wat")) | 148 q := nq().Ancestor(key("thing", "wat")) |
149 for i := 0; i < 100; i++ { | 149 for i := 0; i < 100; i++ { |
150 q = q.Eq("something", i) | 150 q = q.Eq("something", i) |
151 } | 151 } |
152 fq, err := q.Finalize() | 152 fq, err := q.Finalize() |
153 So(err, ShouldErrLike, nil) | 153 So(err, ShouldErrLike, nil) |
154 » » » _, err = reduce(fq, "ns", false) | 154 » » » _, err = reduce(fq, "dev~app", "ns", false) |
155 So(err, ShouldErrLike, "query is too large") | 155 So(err, ShouldErrLike, "query is too large") |
156 }) | 156 }) |
157 | 157 |
158 Convey("bulk check", func() { | 158 Convey("bulk check", func() { |
159 for _, tc := range queryTests { | 159 for _, tc := range queryTests { |
160 Convey(tc.name, func() { | 160 Convey(tc.name, func() { |
161 rq := (*reducedQuery)(nil) | 161 rq := (*reducedQuery)(nil) |
162 fq, err := tc.q.Finalize() | 162 fq, err := tc.q.Finalize() |
163 if err == nil { | 163 if err == nil { |
164 err = fq.Valid("s~aid", "ns") | 164 err = fq.Valid("s~aid", "ns") |
165 if err == nil { | 165 if err == nil { |
166 » » » » » » » rq, err = reduce(fq, "ns
", false) | 166 » » » » » » » rq, err = reduce(fq, "de
v~app", "ns", false) |
167 } | 167 } |
168 } | 168 } |
169 So(err, ShouldErrLike, tc.err) | 169 So(err, ShouldErrLike, tc.err) |
170 | 170 |
171 if tc.equivalentQuery != nil { | 171 if tc.equivalentQuery != nil { |
172 So(rq, ShouldResemble, tc.equiva
lentQuery) | 172 So(rq, ShouldResemble, tc.equiva
lentQuery) |
173 } | 173 } |
174 }) | 174 }) |
175 } | 175 } |
176 }) | 176 }) |
177 }) | 177 }) |
178 } | 178 } |
OLD | NEW |