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 package datastore | 5 package datastore |
6 | 6 |
7 import ( | 7 import ( |
8 "math" | 8 "math" |
9 "testing" | 9 "testing" |
10 "time" | 10 "time" |
(...skipping 18 matching lines...) Expand all Loading... |
29 So(pv.IndexSetting(), ShouldEqual, ShouldIndex) | 29 So(pv.IndexSetting(), ShouldEqual, ShouldIndex) |
30 So(pv.Type().String(), ShouldEqual, "PTNull") | 30 So(pv.Type().String(), ShouldEqual, "PTNull") |
31 }) | 31 }) |
32 Convey("set", func() { | 32 Convey("set", func() { |
33 pv := MkPropertyNI(100) | 33 pv := MkPropertyNI(100) |
34 So(pv.Value(), ShouldHaveSameTypeAs, int64(100)) | 34 So(pv.Value(), ShouldHaveSameTypeAs, int64(100)) |
35 So(pv.Value(), ShouldEqual, 100) | 35 So(pv.Value(), ShouldEqual, 100) |
36 So(pv.IndexSetting(), ShouldEqual, NoIndex) | 36 So(pv.IndexSetting(), ShouldEqual, NoIndex) |
37 So(pv.Type().String(), ShouldEqual, "PTInt") | 37 So(pv.Type().String(), ShouldEqual, "PTInt") |
38 | 38 |
39 » » » » pv.SetValue(nil, ShouldIndex) | 39 » » » » So(pv.SetValue(nil, ShouldIndex), ShouldBeNil) |
40 So(pv.Value(), ShouldBeNil) | 40 So(pv.Value(), ShouldBeNil) |
41 So(pv.IndexSetting(), ShouldEqual, ShouldIndex) | 41 So(pv.IndexSetting(), ShouldEqual, ShouldIndex) |
42 So(pv.Type().String(), ShouldEqual, "PTNull") | 42 So(pv.Type().String(), ShouldEqual, "PTNull") |
43 }) | 43 }) |
44 Convey("derived types", func() { | 44 Convey("derived types", func() { |
45 Convey("int", func() { | 45 Convey("int", func() { |
46 pv := MkProperty(19) | 46 pv := MkProperty(19) |
47 So(pv.Value(), ShouldHaveSameTypeAs, int
64(19)) | 47 So(pv.Value(), ShouldHaveSameTypeAs, int
64(19)) |
48 So(pv.Value(), ShouldEqual, 19) | 48 So(pv.Value(), ShouldEqual, 19) |
49 So(pv.IndexSetting(), ShouldEqual, Shoul
dIndex) | 49 So(pv.IndexSetting(), ShouldEqual, Shoul
dIndex) |
(...skipping 12 matching lines...) Expand all Loading... |
62 So(pv.Type().String(), ShouldEqual, "PTS
tring") | 62 So(pv.Type().String(), ShouldEqual, "PTS
tring") |
63 }) | 63 }) |
64 Convey("blobstore.Key is distinquished", func()
{ | 64 Convey("blobstore.Key is distinquished", func()
{ |
65 pv := MkProperty(blobstore.Key("sup")) | 65 pv := MkProperty(blobstore.Key("sup")) |
66 So(pv.Value(), ShouldEqual, blobstore.Ke
y("sup")) | 66 So(pv.Value(), ShouldEqual, blobstore.Ke
y("sup")) |
67 So(pv.IndexSetting(), ShouldEqual, Shoul
dIndex) | 67 So(pv.IndexSetting(), ShouldEqual, Shoul
dIndex) |
68 So(pv.Type().String(), ShouldEqual, "PTB
lobKey") | 68 So(pv.Type().String(), ShouldEqual, "PTB
lobKey") |
69 }) | 69 }) |
70 Convey("float", func() { | 70 Convey("float", func() { |
71 pv := Property{} | 71 pv := Property{} |
72 » » » » » pv.SetValue(myfloat(19.7), ShouldIndex) | 72 » » » » » So(pv.SetValue(myfloat(19.7), ShouldInde
x), ShouldBeNil) |
73 So(pv.Value(), ShouldHaveSameTypeAs, flo
at64(19.7)) | 73 So(pv.Value(), ShouldHaveSameTypeAs, flo
at64(19.7)) |
74 So(pv.Value(), ShouldEqual, float32(19.7
)) | 74 So(pv.Value(), ShouldEqual, float32(19.7
)) |
75 So(pv.IndexSetting(), ShouldEqual, Shoul
dIndex) | 75 So(pv.IndexSetting(), ShouldEqual, Shoul
dIndex) |
76 So(pv.Type().String(), ShouldEqual, "PTF
loat") | 76 So(pv.Type().String(), ShouldEqual, "PTF
loat") |
77 }) | 77 }) |
78 }) | 78 }) |
79 Convey("bad type", func() { | 79 Convey("bad type", func() { |
80 pv := Property{} | 80 pv := Property{} |
81 err := pv.SetValue(complex(100, 29), ShouldIndex
) | 81 err := pv.SetValue(complex(100, 29), ShouldIndex
) |
82 So(err.Error(), ShouldContainSubstring, "has bad
type complex") | 82 So(err.Error(), ShouldContainSubstring, "has bad
type complex") |
(...skipping 21 matching lines...) Expand all Loading... |
104 err = pv.SetValue(time.Unix(math.MaxInt64, 0).UT
C(), ShouldIndex) | 104 err = pv.SetValue(time.Unix(math.MaxInt64, 0).UT
C(), ShouldIndex) |
105 So(err.Error(), ShouldContainSubstring, "time va
lue out of range") | 105 So(err.Error(), ShouldContainSubstring, "time va
lue out of range") |
106 So(pv.Value(), ShouldBeNil) | 106 So(pv.Value(), ShouldBeNil) |
107 So(pv.IndexSetting(), ShouldEqual, ShouldIndex) | 107 So(pv.IndexSetting(), ShouldEqual, ShouldIndex) |
108 So(pv.Type().String(), ShouldEqual, "PTNull") | 108 So(pv.Type().String(), ShouldEqual, "PTNull") |
109 }) | 109 }) |
110 Convey("time gets rounded", func() { | 110 Convey("time gets rounded", func() { |
111 pv := Property{} | 111 pv := Property{} |
112 now := time.Now().In(time.UTC) | 112 now := time.Now().In(time.UTC) |
113 now = now.Round(time.Microsecond).Add(time.Nanos
econd * 313) | 113 now = now.Round(time.Microsecond).Add(time.Nanos
econd * 313) |
114 » » » » pv.SetValue(now, ShouldIndex) | 114 » » » » So(pv.SetValue(now, ShouldIndex), ShouldBeNil) |
115 So(pv.Value(), ShouldHappenBefore, now) | 115 So(pv.Value(), ShouldHappenBefore, now) |
116 So(pv.IndexSetting(), ShouldEqual, ShouldIndex) | 116 So(pv.IndexSetting(), ShouldEqual, ShouldIndex) |
117 So(pv.Type().String(), ShouldEqual, "PTTime") | 117 So(pv.Type().String(), ShouldEqual, "PTTime") |
118 }) | 118 }) |
119 Convey("[]byte allows IndexSetting", func() { | 119 Convey("[]byte allows IndexSetting", func() { |
120 pv := Property{} | 120 pv := Property{} |
121 » » » » pv.SetValue([]byte("hello"), ShouldIndex) | 121 » » » » So(pv.SetValue([]byte("hello"), ShouldIndex), Sh
ouldBeNil) |
122 So(pv.Value(), ShouldResemble, []byte("hello")) | 122 So(pv.Value(), ShouldResemble, []byte("hello")) |
123 So(pv.IndexSetting(), ShouldEqual, ShouldIndex) | 123 So(pv.IndexSetting(), ShouldEqual, ShouldIndex) |
124 So(pv.Type().String(), ShouldEqual, "PTBytes") | 124 So(pv.Type().String(), ShouldEqual, "PTBytes") |
125 }) | 125 }) |
126 }) | 126 }) |
127 }) | 127 }) |
128 } | 128 } |
129 | 129 |
130 func TestDSPropertyMapImpl(t *testing.T) { | 130 func TestDSPropertyMapImpl(t *testing.T) { |
131 t.Parallel() | 131 t.Parallel() |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 | 171 |
172 Convey("weird value", func() { | 172 Convey("weird value", func() { |
173 pm := PropertyMap{} | 173 pm := PropertyMap{} |
174 err := pm.SetMeta("sup", complex(100, 20
)) | 174 err := pm.SetMeta("sup", complex(100, 20
)) |
175 So(err.Error(), ShouldContainSubstring,
"bad type") | 175 So(err.Error(), ShouldContainSubstring,
"bad type") |
176 }) | 176 }) |
177 }) | 177 }) |
178 }) | 178 }) |
179 }) | 179 }) |
180 } | 180 } |
OLD | NEW |