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

Side by Side Diff: service/datastore/datastore_test.go

Issue 1279703003: Get rid of awkward proto argument to Interface.Run (Closed) Base URL: https://github.com/luci/gae.git@master
Patch Set: rename test helper 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 unified diff | Download patch
« no previous file with comments | « service/datastore/datastore.go ('k') | service/datastore/interface.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // adapted from github.com/golang/appengine/datastore 5 // adapted from github.com/golang/appengine/datastore
6 6
7 package datastore 7 package datastore
8 8
9 import ( 9 import (
10 "fmt" 10 "fmt"
(...skipping 741 matching lines...) Expand 10 before | Expand all | Expand 10 after
752 752
753 Convey("Test Run", t, func() { 753 Convey("Test Run", t, func() {
754 c := info.Set(context.Background(), fakeInfo{}) 754 c := info.Set(context.Background(), fakeInfo{})
755 c = SetRawFactory(c, fakeDatastoreFactory) 755 c = SetRawFactory(c, fakeDatastoreFactory)
756 ds := Get(c) 756 ds := Get(c)
757 So(ds, ShouldNotBeNil) 757 So(ds, ShouldNotBeNil)
758 758
759 q := ds.NewQuery("").Limit(5) 759 q := ds.NewQuery("").Limit(5)
760 760
761 Convey("bad", func() { 761 Convey("bad", func() {
762 assertBadTypePanics := func(cb interface{}) {
763 defer func() {
764 err, _ := recover().(error)
765 So(err, ShouldNotBeNil)
766 So(err.Error(), ShouldContainSubstring,
767 "cb does not match the required callback signature")
768 }()
769 ds.Run(q, cb)
770 }
771
772 Convey("not a function", func() {
773 assertBadTypePanics("I am a potato")
774 })
775
762 Convey("bad proto type", func() { 776 Convey("bad proto type", func() {
763 » » » » So(ds.Run(q, 100, func(obj interface{}, _ func() (Cursor, error)) bool { 777 » » » » assertBadTypePanics(func(v int, _ CursorCB) bool {
764 panic("never here!") 778 panic("never here!")
765 » » » » }).Error(), ShouldContainSubstring, "invalid Run proto type") 779 » » » » })
780 » » » })
781
782 » » » Convey("wrong # args", func() {
783 » » » » assertBadTypePanics(func(v CommonStruct, _ Curso rCB) {
784 » » » » » panic("never here!")
785 » » » » })
786 » » » })
787
788 » » » Convey("wrong ret type", func() {
789 » » » » assertBadTypePanics(func(v CommonStruct, _ Curso rCB) error {
790 » » » » » panic("never here!")
791 » » » » })
792 » » » })
793
794 » » » Convey("bad 2nd arg", func() {
795 » » » » assertBadTypePanics(func(v CommonStruct, _ Curso r) bool {
796 » » » » » panic("never here!")
797 » » » » })
766 }) 798 })
767 799
768 Convey("early abort on error", func() { 800 Convey("early abort on error", func() {
769 rq := q.(*fakeQuery).Fail(3) 801 rq := q.(*fakeQuery).Fail(3)
770 i := 0 802 i := 0
771 » » » » So(ds.Run(rq, CommonStruct{}, func(_ interface{} , _ func() (Cursor, error)) bool { 803 » » » » So(ds.Run(rq, func(c CommonStruct, _ CursorCB) b ool {
772 i++ 804 i++
773 return true 805 return true
774 }).Error(), ShouldEqual, "Query fail") 806 }).Error(), ShouldEqual, "Query fail")
775 So(i, ShouldEqual, 3) 807 So(i, ShouldEqual, 3)
776 }) 808 })
777 809
778 Convey("return error on serialization failure", func() { 810 Convey("return error on serialization failure", func() {
779 » » » » So(ds.Run(q, permaBad{}, func(_ interface{}, _ f unc() (Cursor, error)) bool { 811 » » » » So(ds.Run(q, func(_ permaBad, _ CursorCB) bool {
780 panic("never here") 812 panic("never here")
781 }).Error(), ShouldEqual, "permaBad") 813 }).Error(), ShouldEqual, "permaBad")
782 }) 814 })
783 }) 815 })
784 816
785 Convey("ok", func() { 817 Convey("ok", func() {
786 Convey("*S", func() { 818 Convey("*S", func() {
787 i := 0 819 i := 0
788 » » » » So(ds.Run(q, (*CommonStruct)(nil), func(obj inte rface{}, _ func() (Cursor, error)) bool { 820 » » » » So(ds.Run(q, func(cs *CommonStruct, _ CursorCB) bool {
789 » » » » » cs := obj.(*CommonStruct)
790 So(cs.ID, ShouldEqual, i+1) 821 So(cs.ID, ShouldEqual, i+1)
791 So(cs.Value, ShouldEqual, i) 822 So(cs.Value, ShouldEqual, i)
792 i++ 823 i++
793 return true 824 return true
794 }), ShouldBeNil) 825 }), ShouldBeNil)
795 }) 826 })
796 827
797 Convey("*P", func() { 828 Convey("*P", func() {
798 i := 0 829 i := 0
799 » » » » So(ds.Run(q.Limit(12), (*FakePLS)(nil), func(obj interface{}, _ func() (Cursor, error)) bool { 830 » » » » So(ds.Run(q.Limit(12), func(fpls *FakePLS, _ Cur sorCB) bool {
800 » » » » » fpls := obj.(*FakePLS)
801 So(fpls.gotLoaded, ShouldBeTrue) 831 So(fpls.gotLoaded, ShouldBeTrue)
802 if i == 10 { 832 if i == 10 {
803 So(fpls.StringID, ShouldEqual, " eleven") 833 So(fpls.StringID, ShouldEqual, " eleven")
804 } else { 834 } else {
805 So(fpls.IntID, ShouldEqual, i+1) 835 So(fpls.IntID, ShouldEqual, i+1)
806 } 836 }
807 So(fpls.Value, ShouldEqual, i) 837 So(fpls.Value, ShouldEqual, i)
808 i++ 838 i++
809 return true 839 return true
810 }), ShouldBeNil) 840 }), ShouldBeNil)
811 }) 841 })
812 842
813 Convey("*P (map)", func() { 843 Convey("*P (map)", func() {
814 i := 0 844 i := 0
815 » » » » So(ds.Run(q, (*PropertyMap)(nil), func(obj inter face{}, _ func() (Cursor, error)) bool { 845 » » » » So(ds.Run(q, func(pm *PropertyMap, _ CursorCB) b ool {
816 » » » » » pm := *obj.(*PropertyMap)
817 k, err := pm.GetMeta("key") 846 k, err := pm.GetMeta("key")
818 So(err, ShouldBeNil) 847 So(err, ShouldBeNil)
819 So(k.(Key).IntID(), ShouldEqual, i+1) 848 So(k.(Key).IntID(), ShouldEqual, i+1)
820 » » » » » So(pm["Value"][0].Value(), ShouldEqual, i) 849 » » » » » So((*pm)["Value"][0].Value(), ShouldEqua l, i)
821 i++ 850 i++
822 return true 851 return true
823 }), ShouldBeNil) 852 }), ShouldBeNil)
824 }) 853 })
825 854
826 Convey("S", func() { 855 Convey("S", func() {
827 i := 0 856 i := 0
828 » » » » So(ds.Run(q, CommonStruct{}, func(obj interface{ }, _ func() (Cursor, error)) bool { 857 » » » » So(ds.Run(q, func(cs CommonStruct, _ CursorCB) b ool {
829 » » » » » cs := obj.(CommonStruct)
830 So(cs.ID, ShouldEqual, i+1) 858 So(cs.ID, ShouldEqual, i+1)
831 So(cs.Value, ShouldEqual, i) 859 So(cs.Value, ShouldEqual, i)
832 i++ 860 i++
833 return true 861 return true
834 }), ShouldBeNil) 862 }), ShouldBeNil)
835 }) 863 })
836 864
837 Convey("P", func() { 865 Convey("P", func() {
838 i := 0 866 i := 0
839 » » » » So(ds.Run(q, FakePLS{}, func(obj interface{}, _ func() (Cursor, error)) bool { 867 » » » » So(ds.Run(q, func(fpls FakePLS, _ CursorCB) bool {
840 » » » » » fpls := obj.(FakePLS)
841 So(fpls.gotLoaded, ShouldBeTrue) 868 So(fpls.gotLoaded, ShouldBeTrue)
842 So(fpls.IntID, ShouldEqual, i+1) 869 So(fpls.IntID, ShouldEqual, i+1)
843 So(fpls.Value, ShouldEqual, i) 870 So(fpls.Value, ShouldEqual, i)
844 i++ 871 i++
845 return true 872 return true
846 }), ShouldBeNil) 873 }), ShouldBeNil)
847 }) 874 })
848 875
849 Convey("P (map)", func() { 876 Convey("P (map)", func() {
850 i := 0 877 i := 0
851 » » » » So(ds.Run(q, (PropertyMap)(nil), func(obj interf ace{}, _ func() (Cursor, error)) bool { 878 » » » » So(ds.Run(q, func(pm PropertyMap, _ CursorCB) bo ol {
852 » » » » » pm := obj.(PropertyMap)
853 k, err := pm.GetMeta("key") 879 k, err := pm.GetMeta("key")
854 So(err, ShouldBeNil) 880 So(err, ShouldBeNil)
855 So(k.(Key).IntID(), ShouldEqual, i+1) 881 So(k.(Key).IntID(), ShouldEqual, i+1)
856 So(pm["Value"][0].Value(), ShouldEqual, i) 882 So(pm["Value"][0].Value(), ShouldEqual, i)
857 i++ 883 i++
858 return true 884 return true
859 }), ShouldBeNil) 885 }), ShouldBeNil)
860 }) 886 })
861 887
862 » » » Convey("*Key", func() { 888 » » » Convey("Key", func() {
863 i := 0 889 i := 0
864 » » » » So(ds.Run(q, (*Key)(nil), func(obj interface{}, _ func() (Cursor, error)) bool { 890 » » » » So(ds.Run(q, func(k Key, _ CursorCB) bool {
865 » » » » » So(obj.(Key).IntID(), ShouldEqual, i+1) 891 » » » » » So(k.IntID(), ShouldEqual, i+1)
866 i++ 892 i++
867 return true 893 return true
868 }), ShouldBeNil) 894 }), ShouldBeNil)
869 }) 895 })
870 896
871 }) 897 })
872 }) 898 })
873 } 899 }
OLDNEW
« no previous file with comments | « service/datastore/datastore.go ('k') | service/datastore/interface.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698