| 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 // 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 742 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 Convey("bad proto type", func() { | 762 Convey("bad proto type", func() { |
| 763 » » » » So(ds.Run(q, 100, func(obj interface{}, _ func()
(Cursor, error)) bool { | 763 » » » » So(ds.Run(q, func(v int, _ CursorCB) bool { |
| 764 panic("never here!") | 764 panic("never here!") |
| 765 » » » » }).Error(), ShouldContainSubstring, "invalid Run
proto type") | 765 » » » » }).Error(), ShouldContainSubstring, "cb has a ba
d first argument") |
| 766 }) | 766 }) |
| 767 | 767 |
| 768 Convey("early abort on error", func() { | 768 Convey("early abort on error", func() { |
| 769 rq := q.(*fakeQuery).Fail(3) | 769 rq := q.(*fakeQuery).Fail(3) |
| 770 i := 0 | 770 i := 0 |
| 771 » » » » So(ds.Run(rq, CommonStruct{}, func(_ interface{}
, _ func() (Cursor, error)) bool { | 771 » » » » So(ds.Run(rq, func(c CommonStruct, _ CursorCB) b
ool { |
| 772 i++ | 772 i++ |
| 773 return true | 773 return true |
| 774 }).Error(), ShouldEqual, "Query fail") | 774 }).Error(), ShouldEqual, "Query fail") |
| 775 So(i, ShouldEqual, 3) | 775 So(i, ShouldEqual, 3) |
| 776 }) | 776 }) |
| 777 | 777 |
| 778 Convey("return error on serialization failure", func() { | 778 Convey("return error on serialization failure", func() { |
| 779 » » » » So(ds.Run(q, permaBad{}, func(_ interface{}, _ f
unc() (Cursor, error)) bool { | 779 » » » » So(ds.Run(q, func(_ permaBad, _ CursorCB) bool { |
| 780 panic("never here") | 780 panic("never here") |
| 781 }).Error(), ShouldEqual, "permaBad") | 781 }).Error(), ShouldEqual, "permaBad") |
| 782 }) | 782 }) |
| 783 }) | 783 }) |
| 784 | 784 |
| 785 Convey("ok", func() { | 785 Convey("ok", func() { |
| 786 Convey("*S", func() { | 786 Convey("*S", func() { |
| 787 i := 0 | 787 i := 0 |
| 788 » » » » So(ds.Run(q, (*CommonStruct)(nil), func(obj inte
rface{}, _ func() (Cursor, error)) bool { | 788 » » » » So(ds.Run(q, func(cs *CommonStruct, _ CursorCB)
bool { |
| 789 » » » » » cs := obj.(*CommonStruct) | |
| 790 So(cs.ID, ShouldEqual, i+1) | 789 So(cs.ID, ShouldEqual, i+1) |
| 791 So(cs.Value, ShouldEqual, i) | 790 So(cs.Value, ShouldEqual, i) |
| 792 i++ | 791 i++ |
| 793 return true | 792 return true |
| 794 }), ShouldBeNil) | 793 }), ShouldBeNil) |
| 795 }) | 794 }) |
| 796 | 795 |
| 797 Convey("*P", func() { | 796 Convey("*P", func() { |
| 798 i := 0 | 797 i := 0 |
| 799 » » » » So(ds.Run(q.Limit(12), (*FakePLS)(nil), func(obj
interface{}, _ func() (Cursor, error)) bool { | 798 » » » » So(ds.Run(q.Limit(12), func(fpls *FakePLS, _ Cur
sorCB) bool { |
| 800 » » » » » fpls := obj.(*FakePLS) | |
| 801 So(fpls.gotLoaded, ShouldBeTrue) | 799 So(fpls.gotLoaded, ShouldBeTrue) |
| 802 if i == 10 { | 800 if i == 10 { |
| 803 So(fpls.StringID, ShouldEqual, "
eleven") | 801 So(fpls.StringID, ShouldEqual, "
eleven") |
| 804 } else { | 802 } else { |
| 805 So(fpls.IntID, ShouldEqual, i+1) | 803 So(fpls.IntID, ShouldEqual, i+1) |
| 806 } | 804 } |
| 807 So(fpls.Value, ShouldEqual, i) | 805 So(fpls.Value, ShouldEqual, i) |
| 808 i++ | 806 i++ |
| 809 return true | 807 return true |
| 810 }), ShouldBeNil) | 808 }), ShouldBeNil) |
| 811 }) | 809 }) |
| 812 | 810 |
| 813 Convey("*P (map)", func() { | 811 Convey("*P (map)", func() { |
| 814 i := 0 | 812 i := 0 |
| 815 » » » » So(ds.Run(q, (*PropertyMap)(nil), func(obj inter
face{}, _ func() (Cursor, error)) bool { | 813 » » » » So(ds.Run(q, func(pm *PropertyMap, _ CursorCB) b
ool { |
| 816 » » » » » pm := *obj.(*PropertyMap) | |
| 817 k, err := pm.GetMeta("key") | 814 k, err := pm.GetMeta("key") |
| 818 So(err, ShouldBeNil) | 815 So(err, ShouldBeNil) |
| 819 So(k.(Key).IntID(), ShouldEqual, i+1) | 816 So(k.(Key).IntID(), ShouldEqual, i+1) |
| 820 » » » » » So(pm["Value"][0].Value(), ShouldEqual,
i) | 817 » » » » » So((*pm)["Value"][0].Value(), ShouldEqua
l, i) |
| 821 i++ | 818 i++ |
| 822 return true | 819 return true |
| 823 }), ShouldBeNil) | 820 }), ShouldBeNil) |
| 824 }) | 821 }) |
| 825 | 822 |
| 826 Convey("S", func() { | 823 Convey("S", func() { |
| 827 i := 0 | 824 i := 0 |
| 828 » » » » So(ds.Run(q, CommonStruct{}, func(obj interface{
}, _ func() (Cursor, error)) bool { | 825 » » » » So(ds.Run(q, func(cs CommonStruct, _ CursorCB) b
ool { |
| 829 » » » » » cs := obj.(CommonStruct) | |
| 830 So(cs.ID, ShouldEqual, i+1) | 826 So(cs.ID, ShouldEqual, i+1) |
| 831 So(cs.Value, ShouldEqual, i) | 827 So(cs.Value, ShouldEqual, i) |
| 832 i++ | 828 i++ |
| 833 return true | 829 return true |
| 834 }), ShouldBeNil) | 830 }), ShouldBeNil) |
| 835 }) | 831 }) |
| 836 | 832 |
| 837 Convey("P", func() { | 833 Convey("P", func() { |
| 838 i := 0 | 834 i := 0 |
| 839 » » » » So(ds.Run(q, FakePLS{}, func(obj interface{}, _
func() (Cursor, error)) bool { | 835 » » » » So(ds.Run(q, func(fpls FakePLS, _ CursorCB) bool
{ |
| 840 » » » » » fpls := obj.(FakePLS) | |
| 841 So(fpls.gotLoaded, ShouldBeTrue) | 836 So(fpls.gotLoaded, ShouldBeTrue) |
| 842 So(fpls.IntID, ShouldEqual, i+1) | 837 So(fpls.IntID, ShouldEqual, i+1) |
| 843 So(fpls.Value, ShouldEqual, i) | 838 So(fpls.Value, ShouldEqual, i) |
| 844 i++ | 839 i++ |
| 845 return true | 840 return true |
| 846 }), ShouldBeNil) | 841 }), ShouldBeNil) |
| 847 }) | 842 }) |
| 848 | 843 |
| 849 Convey("P (map)", func() { | 844 Convey("P (map)", func() { |
| 850 i := 0 | 845 i := 0 |
| 851 » » » » So(ds.Run(q, (PropertyMap)(nil), func(obj interf
ace{}, _ func() (Cursor, error)) bool { | 846 » » » » So(ds.Run(q, func(pm PropertyMap, _ CursorCB) bo
ol { |
| 852 » » » » » pm := obj.(PropertyMap) | |
| 853 k, err := pm.GetMeta("key") | 847 k, err := pm.GetMeta("key") |
| 854 So(err, ShouldBeNil) | 848 So(err, ShouldBeNil) |
| 855 So(k.(Key).IntID(), ShouldEqual, i+1) | 849 So(k.(Key).IntID(), ShouldEqual, i+1) |
| 856 So(pm["Value"][0].Value(), ShouldEqual,
i) | 850 So(pm["Value"][0].Value(), ShouldEqual,
i) |
| 857 i++ | 851 i++ |
| 858 return true | 852 return true |
| 859 }), ShouldBeNil) | 853 }), ShouldBeNil) |
| 860 }) | 854 }) |
| 861 | 855 |
| 862 Convey("*Key", func() { | 856 Convey("*Key", func() { |
| 863 i := 0 | 857 i := 0 |
| 864 » » » » So(ds.Run(q, (*Key)(nil), func(obj interface{},
_ func() (Cursor, error)) bool { | 858 » » » » So(ds.Run(q, func(k Key, _ CursorCB) bool { |
| 865 » » » » » So(obj.(Key).IntID(), ShouldEqual, i+1) | 859 » » » » » So(k.IntID(), ShouldEqual, i+1) |
| 866 i++ | 860 i++ |
| 867 return true | 861 return true |
| 868 }), ShouldBeNil) | 862 }), ShouldBeNil) |
| 869 }) | 863 }) |
| 870 | 864 |
| 871 }) | 865 }) |
| 872 }) | 866 }) |
| 873 } | 867 } |
| OLD | NEW |