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

Side by Side Diff: impl/memory/datastore_query_execution_test.go

Issue 1550903002: impl/memory: Fix time serialization encoding. (Closed) Base URL: https://github.com/luci/gae@master
Patch Set: Convert when building the query, not serializing in general. Created 4 years, 11 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 unified diff | Download patch
OLDNEW
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 "fmt" 8 "fmt"
9 "strings" 9 "strings"
10 "testing" 10 "testing"
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 pmap("$key", key("Kind", 3, "Kind", 2), Next, 78 pmap("$key", key("Kind", 3, "Kind", 2), Next,
79 "Val", 3, 4, Next, 79 "Val", 3, 4, Next,
80 "Extra", "hello", "waffle", 80 "Extra", "hello", "waffle",
81 ), 81 ),
82 pmap("$key", key("Kind", 3, "Kind", 3), Next, 82 pmap("$key", key("Kind", 3, "Kind", 3), Next,
83 "Val", 3, 4, 2, 1, Next, 83 "Val", 3, 4, 2, 1, Next,
84 "Extra", "nuts", 84 "Extra", "nuts",
85 ), 85 ),
86 } 86 }
87 87
88 var timeData = []ds.PropertyMap{
89 pmap("$key", key("Kind", 1), Next,
90 "Date", time.Date(2000, time.January, 1, 1, 1, 1, 1, time.UTC), Next,
91 ),
92 pmap("$key", key("Kind", 2), Next,
93 "Date", time.Date(2000, time.March, 1, 1, 1, 1, 1, time.UTC), Ne xt,
94 ),
95 }
96
88 var queryExecutionTests = []qExTest{ 97 var queryExecutionTests = []qExTest{
89 {"basic", []qExStage{ 98 {"basic", []qExStage{
90 { 99 {
91 addIdxs: []*ds.IndexDefinition{ 100 addIdxs: []*ds.IndexDefinition{
92 indx("Unrelated", "-thing", "bob", "-__key__"), 101 indx("Unrelated", "-thing", "bob", "-__key__"),
93 indx("Wat", "deep", "opt", "other"), 102 indx("Wat", "deep", "opt", "other"),
94 indx("Wat", "meep", "opt", "other"), 103 indx("Wat", "meep", "opt", "other"),
95 }, 104 },
96 }, 105 },
97 106
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 {q: nq("Unique").Gt("__key__", key("AKind", 5)). Lte("__key__", key("Zeta", "prime")), 387 {q: nq("Unique").Gt("__key__", key("AKind", 5)). Lte("__key__", key("Zeta", "prime")),
379 keys: []*ds.Key{key("Unique", 1)}, 388 keys: []*ds.Key{key("Unique", 1)},
380 get: []ds.PropertyMap{}}, 389 get: []ds.PropertyMap{}},
381 390
382 {q: nq("Kind").Eq("Val", 1, 3), get: []ds.Proper tyMap{ 391 {q: nq("Kind").Eq("Val", 1, 3), get: []ds.Proper tyMap{
383 stage1Data[0], stage2Data[2], 392 stage1Data[0], stage2Data[2],
384 }}, 393 }},
385 }, 394 },
386 }, 395 },
387 }}, 396 }},
397 {"time range", []qExStage{
398 {
399 addIdxs: []*ds.IndexDefinition{
400 indx("Kind!", "Date"),
401 },
402 },
403 {
404 putEnts: timeData,
405 },
406 {
407 expect: []qExpect{
408 {
409 q: nq("Kind").Lte("Date", time.Date(2000 , time.February, 1, 1, 1, 1, 1, time.UTC)),
410 get: []ds.PropertyMap{
411 timeData[0],
412 },
413 },
414 },
415 },
416 }},
388 } 417 }
389 418
390 func TestQueryExecution(t *testing.T) { 419 func TestQueryExecution(t *testing.T) {
391 t.Parallel() 420 t.Parallel()
392 421
393 Convey("Test query execution", t, func() { 422 Convey("Test query execution", t, func() {
394 c, err := info.Get(Use(context.Background())).Namespace("ns") 423 c, err := info.Get(Use(context.Background())).Namespace("ns")
395 if err != nil { 424 if err != nil {
396 panic(err) 425 panic(err)
397 } 426 }
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 err := r unner(func(c context.Context) error { 490 err := r unner(func(c context.Context) error {
462 data := ds.Get(c) 491 data := ds.Get(c)
463 count, err := data.Count(expect.q) 492 count, err := data.Count(expect.q)
464 So(err, ShouldBeNil) 493 So(err, ShouldBeNil)
465 So(count, ShouldEqual, expect.count) 494 So(count, ShouldEqual, expect.count)
466 495
467 rslt := []ds.PropertyMap(nil) 496 rslt := []ds.PropertyMap(nil)
468 So(data.GetAll(expect.q, &rslt), ShouldBeNil) 497 So(data.GetAll(expect.q, &rslt), ShouldBeNil)
469 So(len(rslt), ShouldEqual, len(expect.get)) 498 So(len(rslt), ShouldEqual, len(expect.get))
470 for i, r := range rslt { 499 for i, r := range rslt {
471 » » » » » » » » » » » So(r, ShouldResemble, expect.get[i]) 500 » » » » » » » » » » » So(r, ShouldResembleV, expect.get[i])
472 } 501 }
473 return nil 502 return nil
474 }, &ds.T ransactionOptions{XG: true}) 503 }, &ds.T ransactionOptions{XG: true})
475 So(err, ShouldBeNil) 504 So(err, ShouldBeNil)
476 }) 505 })
477 } 506 }
478 } 507 }
479 508
480 for j, fn := range stage.extraFn s { 509 for j, fn := range stage.extraFn s {
481 Convey(fmt.Sprintf("extr aFn %d", j), func() { 510 Convey(fmt.Sprintf("extr aFn %d", j), func() {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
513 count, err := data.Count(q) 542 count, err := data.Count(q)
514 So(err, ShouldErrLike, "Insufficient indexes") 543 So(err, ShouldErrLike, "Insufficient indexes")
515 544
516 testing.AutoIndex(true) 545 testing.AutoIndex(true)
517 546
518 count, err = data.Count(q) 547 count, err = data.Count(q)
519 So(err, ShouldBeNil) 548 So(err, ShouldBeNil)
520 So(count, ShouldEqual, 2) 549 So(count, ShouldEqual, 2)
521 }) 550 })
522 } 551 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698