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

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

Issue 2342063003: Differentiate between single- and multi- props. (Closed)
Patch Set: Slice is now always a clone. This is marginally worse performance, but a much safer UI. Created 4 years, 3 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/properties.go ('k') | service/datastore/serialize/serialize.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 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
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
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 }
OLDNEW
« no previous file with comments | « service/datastore/properties.go ('k') | service/datastore/serialize/serialize.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698