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

Side by Side Diff: filter/txnBuf/txnbuf_test.go

Issue 1516173002: Fix error message from KeyForObj when passing an invalid struct. (Closed) Base URL: https://github.com/luci/gae.git@master
Patch Set: Fix GetMetaDefault silliness Created 5 years 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 txnBuf 5 package txnBuf
6 6
7 import ( 7 import (
8 "bytes" 8 "bytes"
9 "fmt" 9 "fmt"
10 "math/rand" 10 "math/rand"
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 {2, 4}, 488 {2, 4},
489 {3, 4}, 489 {3, 4},
490 {2, 5}, 490 {2, 5},
491 {3, 5}, 491 {3, 5},
492 {4, 5}, 492 {4, 5},
493 {2, 6}, 493 {2, 6},
494 {3, 6}, 494 {3, 6},
495 } 495 }
496 496
497 for i, pm := range vals { 497 for i, pm := range vals {
498 » » » » » » So(pm.GetMetaDefault("key", nil) , ShouldResemble, ds.MakeKey("Parent", 1, "Foo", expect[i].id)) 498 » » » » » » v, err := datastore.GetMetaDefau lt(pm, "key", nil)
499 » » » » » » So(err, ShouldBeNil)
500 » » » » » » So(v, ShouldResemble, ds.MakeKey ("Parent", 1, "Foo", expect[i].id))
499 So(pm["Value"][0].Value(), Shoul dEqual, expect[i].val) 501 So(pm["Value"][0].Value(), Shoul dEqual, expect[i].val)
500 } 502 }
501 503
502 // should remove 4 entries, but there ar e plenty more to fill 504 // should remove 4 entries, but there ar e plenty more to fill
503 So(ds.Delete(ds.MakeKey("Parent", 1, "Fo o", 2)), ShouldBeNil) 505 So(ds.Delete(ds.MakeKey("Parent", 1, "Fo o", 2)), ShouldBeNil)
504 506
505 vals = []datastore.PropertyMap{} 507 vals = []datastore.PropertyMap{}
506 So(ds.GetAll(q, &vals), ShouldBeNil) 508 So(ds.GetAll(q, &vals), ShouldBeNil)
507 So(len(vals), ShouldEqual, 10) 509 So(len(vals), ShouldEqual, 10)
508 510
509 expect = []struct { 511 expect = []struct {
510 id int64 512 id int64
511 val int64 513 val int64
512 }{ 514 }{
513 // note (3, 3) and (4, 3) are co rrectly missing because deleting 515 // note (3, 3) and (4, 3) are co rrectly missing because deleting
514 // 2 removed two entries which a re hidden by the Offset(4). 516 // 2 removed two entries which a re hidden by the Offset(4).
515 {3, 4}, 517 {3, 4},
516 {3, 5}, 518 {3, 5},
517 {4, 5}, 519 {4, 5},
518 {3, 6}, 520 {3, 6},
519 {3, 7}, 521 {3, 7},
520 {4, 7}, 522 {4, 7},
521 {3, 8}, 523 {3, 8},
522 {3, 9}, 524 {3, 9},
523 {4, 9}, 525 {4, 9},
524 {4, 11}, 526 {4, 11},
525 } 527 }
526 528
527 for i, pm := range vals { 529 for i, pm := range vals {
528 » » » » » » So(pm.GetMetaDefault("key", nil) , ShouldResemble, ds.MakeKey("Parent", 1, "Foo", expect[i].id)) 530 » » » » » » v, err := datastore.GetMetaDefau lt(pm, "key", nil)
531 » » » » » » So(err, ShouldBeNil)
532 » » » » » » So(v, ShouldResemble, ds.MakeKey ("Parent", 1, "Foo", expect[i].id))
529 So(pm["Value"][0].Value(), Shoul dEqual, expect[i].val) 533 So(pm["Value"][0].Value(), Shoul dEqual, expect[i].val)
530 } 534 }
531 535
532 So(ds.Put(&Foo{ID: 1, Parent: root, Valu e: []int64{3, 9}}), ShouldBeNil) 536 So(ds.Put(&Foo{ID: 1, Parent: root, Valu e: []int64{3, 9}}), ShouldBeNil)
533 537
534 vals = []datastore.PropertyMap{} 538 vals = []datastore.PropertyMap{}
535 So(ds.GetAll(q, &vals), ShouldBeNil) 539 So(ds.GetAll(q, &vals), ShouldBeNil)
536 So(len(vals), ShouldEqual, 10) 540 So(len(vals), ShouldEqual, 10)
537 541
538 expect = []struct { 542 expect = []struct {
539 id int64 543 id int64
540 val int64 544 val int64
541 }{ 545 }{
542 // 'invisible' {1, 3} entry bump s the {4, 3} into view. 546 // 'invisible' {1, 3} entry bump s the {4, 3} into view.
543 {4, 3}, 547 {4, 3},
544 {3, 4}, 548 {3, 4},
545 {3, 5}, 549 {3, 5},
546 {4, 5}, 550 {4, 5},
547 {3, 6}, 551 {3, 6},
548 {3, 7}, 552 {3, 7},
549 {4, 7}, 553 {4, 7},
550 {3, 8}, 554 {3, 8},
551 {1, 9}, 555 {1, 9},
552 {3, 9}, 556 {3, 9},
553 {4, 9}, 557 {4, 9},
554 } 558 }
555 559
556 for i, pm := range vals { 560 for i, pm := range vals {
557 » » » » » » So(pm.GetMetaDefault("key", nil) , ShouldResemble, ds.MakeKey("Parent", 1, "Foo", expect[i].id)) 561 » » » » » » v, err := datastore.GetMetaDefau lt(pm, "key", nil)
562 » » » » » » So(err, ShouldBeNil)
563 » » » » » » So(v, ShouldResemble, ds.MakeKey ("Parent", 1, "Foo", expect[i].id))
558 So(pm["Value"][0].Value(), Shoul dEqual, expect[i].val) 564 So(pm["Value"][0].Value(), Shoul dEqual, expect[i].val)
559 } 565 }
560 566
561 return nil 567 return nil
562 }, nil), ShouldBeNil) 568 }, nil), ShouldBeNil)
563 569
564 }) 570 })
565 571
566 Convey("project+distinct", func() { 572 Convey("project+distinct", func() {
567 _, _, ds := mkds([]*Foo{ 573 _, _, ds := mkds([]*Foo{
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
602 {3, 8}, 608 {3, 8},
603 {3, 9}, 609 {3, 9},
604 {4, 11}, 610 {4, 11},
605 {5, 70}, 611 {5, 70},
606 {4, 100}, 612 {4, 100},
607 {5, 101}, 613 {5, 101},
608 } 614 }
609 615
610 for i, pm := range vals { 616 for i, pm := range vals {
611 So(pm["Value"][0].Value(), Shoul dEqual, expect[i].val) 617 So(pm["Value"][0].Value(), Shoul dEqual, expect[i].val)
612 » » » » » » So(pm.GetMetaDefault("key", nil) , ShouldResemble, ds.MakeKey("Parent", 1, "Foo", expect[i].id)) 618
619 » » » » » » v, err := datastore.GetMetaDefau lt(pm, "key", nil)
620 » » » » » » So(err, ShouldBeNil)
621 » » » » » » So(v, ShouldResemble, ds.MakeKey ("Parent", 1, "Foo", expect[i].id))
613 } 622 }
614 623
615 return nil 624 return nil
616 }, nil), ShouldBeNil) 625 }, nil), ShouldBeNil)
617 }) 626 })
618 627
619 Convey("overwrite", func() { 628 Convey("overwrite", func() {
620 data := []*Foo{ 629 data := []*Foo{
621 {ID: 2, Parent: root, Value: []int64{1, 2, 3, 4, 5, 6, 7}}, 630 {ID: 2, Parent: root, Value: []int64{1, 2, 3, 4, 5, 6, 7}},
622 {ID: 3, Parent: root, Value: []int64{3, 4, 5, 6, 7, 8, 9}}, 631 {ID: 3, Parent: root, Value: []int64{3, 4, 5, 6, 7, 8, 9}},
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
709 {5, 101}, 718 {5, 101},
710 {5, 70}, 719 {5, 70},
711 {3, 9}, 720 {3, 9},
712 {3, 8}, 721 {3, 8},
713 {4, 100}, 722 {4, 100},
714 {4, 11}, 723 {4, 11},
715 } 724 }
716 725
717 for i, pm := range vals { 726 for i, pm := range vals {
718 So(pm["Value"][0].Value(), Shoul dEqual, expect[i].val) 727 So(pm["Value"][0].Value(), Shoul dEqual, expect[i].val)
719 » » » » » » So(pm.GetMetaDefault("key", nil) , ShouldResemble, ds.MakeKey("Parent", 1, "Foo", expect[i].id)) 728
729 » » » » » » v, err := datastore.GetMetaDefau lt(pm, "key", nil)
730 » » » » » » So(err, ShouldBeNil)
731 » » » » » » So(v, ShouldResemble, ds.MakeKey ("Parent", 1, "Foo", expect[i].id))
720 } 732 }
721 733
722 return nil 734 return nil
723 }, nil), ShouldBeNil) 735 }, nil), ShouldBeNil)
724 }) 736 })
725 737
726 Convey("buffered entity sorts before ineq, but after fir st parent entity", func() { 738 Convey("buffered entity sorts before ineq, but after fir st parent entity", func() {
727 // If we got this wrong, we'd see Foo,3 come bef ore Foo,2. This might 739 // If we got this wrong, we'd see Foo,3 come bef ore Foo,2. This might
728 // happen because we calculate the comparison st ring for each entity 740 // happen because we calculate the comparison st ring for each entity
729 // based on the whole entity, but we forgot to l imit the comparison 741 // based on the whole entity, but we forgot to l imit the comparison
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
866 So(val[len(val)-1].Value(), ShouldResemb le, "wat") 878 So(val[len(val)-1].Value(), ShouldResemb le, "wat")
867 return true 879 return true
868 }), ShouldBeNil) 880 }), ShouldBeNil)
869 }) 881 })
870 882
871 }) 883 })
872 884
873 }) 885 })
874 886
875 } 887 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698