OLD | NEW |
1 // Copyright 2015 The LUCI Authors. All rights reserved. | 1 // Copyright 2015 The LUCI Authors. All rights reserved. |
2 // Use of this source code is governed under the Apache License, Version 2.0 | 2 // Use of this source code is governed under the Apache License, Version 2.0 |
3 // that can be found in the LICENSE file. | 3 // that can be found in the LICENSE file. |
4 | 4 |
5 package datastore | 5 package datastore |
6 | 6 |
7 import ( | 7 import ( |
8 "fmt" | 8 "fmt" |
9 "math" | 9 "math" |
10 "sort" | 10 "sort" |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 }) | 187 }) |
188 }) | 188 }) |
189 } | 189 } |
190 | 190 |
191 func TestDSPropertyMapImpl(t *testing.T) { | 191 func TestDSPropertyMapImpl(t *testing.T) { |
192 t.Parallel() | 192 t.Parallel() |
193 | 193 |
194 Convey("PropertyMap load/save err conditions", t, func() { | 194 Convey("PropertyMap load/save err conditions", t, func() { |
195 Convey("empty", func() { | 195 Convey("empty", func() { |
196 pm := PropertyMap{} | 196 pm := PropertyMap{} |
197 » » » err := pm.Load(PropertyMap{"hello": {Property{}}}) | 197 » » » err := pm.Load(PropertyMap{"hello": Property{}}) |
198 So(err, ShouldBeNil) | 198 So(err, ShouldBeNil) |
199 » » » So(pm, ShouldResemble, PropertyMap{"hello": {Property{}}
}) | 199 » » » So(pm, ShouldResemble, PropertyMap{"hello": Property{}}) |
200 | 200 |
201 npm, _ := pm.Save(false) | 201 npm, _ := pm.Save(false) |
202 So(npm, ShouldResemble, pm) | 202 So(npm, ShouldResemble, pm) |
203 }) | 203 }) |
204 Convey("meta", func() { | 204 Convey("meta", func() { |
205 Convey("working", func() { | 205 Convey("working", func() { |
206 » » » » pm := PropertyMap{"": {MkProperty("trap!")}} | 206 » » » » pm := PropertyMap{"": MkProperty("trap!")} |
207 _, ok := pm.GetMeta("foo") | 207 _, ok := pm.GetMeta("foo") |
208 So(ok, ShouldBeFalse) | 208 So(ok, ShouldBeFalse) |
209 | 209 |
210 So(pm.SetMeta("foo", 100), ShouldBeTrue) | 210 So(pm.SetMeta("foo", 100), ShouldBeTrue) |
211 | 211 |
212 v, ok := pm.GetMeta("foo") | 212 v, ok := pm.GetMeta("foo") |
213 So(ok, ShouldBeTrue) | 213 So(ok, ShouldBeTrue) |
214 So(v, ShouldEqual, 100) | 214 So(v, ShouldEqual, 100) |
215 | 215 |
216 So(GetMetaDefault(pm, "foo", 100), ShouldEqual,
100) | 216 So(GetMetaDefault(pm, "foo", 100), ShouldEqual,
100) |
217 | 217 |
218 So(GetMetaDefault(pm, "bar", 100), ShouldEqual,
100) | 218 So(GetMetaDefault(pm, "bar", 100), ShouldEqual,
100) |
219 | 219 |
220 npm, err := pm.Save(false) | 220 npm, err := pm.Save(false) |
221 So(err, ShouldBeNil) | 221 So(err, ShouldBeNil) |
222 So(len(npm), ShouldEqual, 0) | 222 So(len(npm), ShouldEqual, 0) |
223 }) | 223 }) |
224 | 224 |
225 Convey("too many values picks the first one", func() { | 225 Convey("too many values picks the first one", func() { |
226 pm := PropertyMap{ | 226 pm := PropertyMap{ |
227 » » » » » "$thing": {MkProperty(100), MkProperty(2
00)}, | 227 » » » » » "$thing": PropertySlice{MkProperty(100),
MkProperty(200)}, |
228 } | 228 } |
229 v, ok := pm.GetMeta("thing") | 229 v, ok := pm.GetMeta("thing") |
230 So(ok, ShouldBeTrue) | 230 So(ok, ShouldBeTrue) |
231 So(v, ShouldEqual, 100) | 231 So(v, ShouldEqual, 100) |
232 }) | 232 }) |
233 | 233 |
234 Convey("errors", func() { | 234 Convey("errors", func() { |
235 | 235 |
236 Convey("weird value", func() { | 236 Convey("weird value", func() { |
237 pm := PropertyMap{} | 237 pm := PropertyMap{} |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 cmpBS, _ := c.co
nv(tc.cmpS) | 309 cmpBS, _ := c.co
nv(tc.cmpS) |
310 So(cmpByteSequen
ce(bs, cmpBS), tc.assertion, 0) | 310 So(cmpByteSequen
ce(bs, cmpBS), tc.assertion, 0) |
311 }) | 311 }) |
312 } | 312 } |
313 } | 313 } |
314 }) | 314 }) |
315 } | 315 } |
316 } | 316 } |
317 }) | 317 }) |
318 } | 318 } |
OLD | NEW |