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 // +build appengine | 5 // +build appengine |
6 | 6 |
7 package prod | 7 package prod |
8 | 8 |
9 import ( | 9 import ( |
10 "testing" | 10 "testing" |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 }, | 175 }, |
176 { | 176 { |
177 "$key": {mpNI(ds.KeyForObj(&o
rig))}, | 177 "$key": {mpNI(ds.KeyForObj(&o
rig))}, |
178 "ValueBS": {mp("zurple")}, | 178 "ValueBS": {mp("zurple")}, |
179 }, | 179 }, |
180 }) | 180 }) |
181 | 181 |
182 count, err := ds.Count(q) | 182 count, err := ds.Count(q) |
183 So(err, ShouldBeNil) | 183 So(err, ShouldBeNil) |
184 So(count, ShouldEqual, 4) | 184 So(count, ShouldEqual, 4) |
| 185 |
| 186 q = datastore.NewQuery("TestStruct").Lte("ValueI
", 7).Project("ValueS").Distinct(true) |
| 187 rslts = []datastore.PropertyMap{} |
| 188 So(ds.GetAll(q, &rslts), ShouldBeNil) |
| 189 So(rslts, ShouldResemble, []datastore.PropertyMa
p{ |
| 190 { |
| 191 "$key": {mpNI(ds.KeyForObj(&or
ig))}, |
| 192 "ValueI": {mp(1)}, |
| 193 "ValueS": {mp("hello")}, |
| 194 }, |
| 195 { |
| 196 "$key": {mpNI(ds.KeyForObj(&or
ig))}, |
| 197 "ValueI": {mp(1)}, |
| 198 "ValueS": {mp("world")}, |
| 199 }, |
| 200 { |
| 201 "$key": {mpNI(ds.KeyForObj(&or
ig))}, |
| 202 "ValueI": {mp(7)}, |
| 203 "ValueS": {mp("hello")}, |
| 204 }, |
| 205 { |
| 206 "$key": {mpNI(ds.KeyForObj(&or
ig))}, |
| 207 "ValueI": {mp(7)}, |
| 208 "ValueS": {mp("world")}, |
| 209 }, |
| 210 }) |
| 211 |
| 212 count, err = ds.Count(q) |
| 213 So(err, ShouldBeNil) |
| 214 So(count, ShouldEqual, 4) |
185 }) | 215 }) |
186 }) | 216 }) |
187 | 217 |
188 Convey("Can Put/Get (time)", func() { | 218 Convey("Can Put/Get (time)", func() { |
189 // time comparisons in Go are wonky, so this is pulled o
ut | 219 // time comparisons in Go are wonky, so this is pulled o
ut |
190 pm := datastore.PropertyMap{ | 220 pm := datastore.PropertyMap{ |
191 "$key": {mpNI(ds.NewKey("Something", "value", 0,
nil))}, | 221 "$key": {mpNI(ds.NewKey("Something", "value", 0,
nil))}, |
192 "Time": { | 222 "Time": { |
193 mp(time.Date(1938, time.January, 1, 1, 1
, 1, 1, time.UTC)), | 223 mp(time.Date(1938, time.January, 1, 1, 1
, 1, 1, time.UTC)), |
194 mp(time.Time{}), | 224 mp(time.Time{}), |
195 }, | 225 }, |
196 } | 226 } |
197 So(ds.Put(&pm), ShouldBeNil) | 227 So(ds.Put(&pm), ShouldBeNil) |
198 | 228 |
199 rslt := datastore.PropertyMap{} | 229 rslt := datastore.PropertyMap{} |
200 rslt.SetMeta("key", ds.KeyForObj(pm)) | 230 rslt.SetMeta("key", ds.KeyForObj(pm)) |
201 So(ds.Get(&rslt), ShouldBeNil) | 231 So(ds.Get(&rslt), ShouldBeNil) |
202 | 232 |
203 So(pm["Time"][0].Value(), ShouldResemble, rslt["Time"][0
].Value()) | 233 So(pm["Time"][0].Value(), ShouldResemble, rslt["Time"][0
].Value()) |
204 | 234 |
205 q := datastore.NewQuery("Something").Project("Time") | 235 q := datastore.NewQuery("Something").Project("Time") |
206 all := []datastore.PropertyMap{} | 236 all := []datastore.PropertyMap{} |
207 So(ds.GetAll(q, &all), ShouldBeNil) | 237 So(ds.GetAll(q, &all), ShouldBeNil) |
208 So(len(all), ShouldEqual, 2) | 238 So(len(all), ShouldEqual, 2) |
209 prop := all[0]["Time"][0] | 239 prop := all[0]["Time"][0] |
210 So(prop.Type(), ShouldEqual, datastore.PTInt) | 240 So(prop.Type(), ShouldEqual, datastore.PTInt) |
211 | 241 |
212 tval, err := prop.Project(datastore.PTTime) | 242 tval, err := prop.Project(datastore.PTTime) |
213 So(err, ShouldBeNil) | 243 So(err, ShouldBeNil) |
214 » » » So(tval, ShouldResemble, time.Time{}) | 244 » » » So(tval, ShouldResemble, time.Time{}.UTC()) |
215 | 245 |
216 tval, err = all[1]["Time"][0].Project(datastore.PTTime) | 246 tval, err = all[1]["Time"][0].Project(datastore.PTTime) |
217 So(err, ShouldBeNil) | 247 So(err, ShouldBeNil) |
218 So(tval, ShouldResemble, pm["Time"][0].Value()) | 248 So(tval, ShouldResemble, pm["Time"][0].Value()) |
219 | 249 |
220 ent := datastore.PropertyMap{ | 250 ent := datastore.PropertyMap{ |
221 "$key": {mpNI(ds.MakeKey("Something", "value"))}
, | 251 "$key": {mpNI(ds.MakeKey("Something", "value"))}
, |
222 } | 252 } |
223 So(ds.Get(&ent), ShouldBeNil) | 253 So(ds.Get(&ent), ShouldBeNil) |
224 So(ent["Time"], ShouldResemble, pm["Time"]) | 254 So(ent["Time"], ShouldResemble, pm["Time"]) |
225 }) | 255 }) |
226 | 256 |
227 Convey("memcache: Set (nil) is the same as Set ([]byte{})", func
() { | 257 Convey("memcache: Set (nil) is the same as Set ([]byte{})", func
() { |
228 So(mc.Set(mc.NewItem("bob")), ShouldBeNil) // normally w
ould panic because Value is nil | 258 So(mc.Set(mc.NewItem("bob")), ShouldBeNil) // normally w
ould panic because Value is nil |
229 | 259 |
230 bob, err := mc.Get("bob") | 260 bob, err := mc.Get("bob") |
231 So(err, ShouldBeNil) | 261 So(err, ShouldBeNil) |
232 So(bob.Value(), ShouldResemble, []byte{}) | 262 So(bob.Value(), ShouldResemble, []byte{}) |
233 }) | 263 }) |
234 }) | 264 }) |
235 } | 265 } |
OLD | NEW |