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

Side by Side Diff: service/datastore/serialize/serialize_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/serialize/serialize.go ('k') | service/datastore/size_test.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 serialize 5 package serialize
6 6
7 import ( 7 import (
8 "bytes" 8 "bytes"
9 "fmt" 9 "fmt"
10 "io" 10 "io"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 } 50 }
51 51
52 func TestPropertyMapSerialization(t *testing.T) { 52 func TestPropertyMapSerialization(t *testing.T) {
53 t.Parallel() 53 t.Parallel()
54 54
55 now := time.Now().UTC() 55 now := time.Now().UTC()
56 tests := []dspmapTC{ 56 tests := []dspmapTC{
57 { 57 {
58 "basic", 58 "basic",
59 ds.PropertyMap{ 59 ds.PropertyMap{
60 » » » » "R": {mp(false), mp(2.1), mpNI(3)}, 60 » » » » "R": ds.PropertySlice{mp(false), mp(2.1), mpNI(3 )},
61 » » » » "S": {mp("hello"), mp("world")}, 61 » » » » "S": ds.PropertySlice{mp("hello"), mp("world")},
62 }, 62 },
63 }, 63 },
64 { 64 {
65 "keys", 65 "keys",
66 ds.PropertyMap{ 66 ds.PropertyMap{
67 » » » » "DS": { 67 » » » » "DS": ds.PropertySlice{
68 mp(mkKey("appy", "ns", "Foo", 7)), 68 mp(mkKey("appy", "ns", "Foo", 7)),
69 mp(mkKey("other", "", "Yot", "wheeep")), 69 mp(mkKey("other", "", "Yot", "wheeep")),
70 mp((*ds.Key)(nil)), 70 mp((*ds.Key)(nil)),
71 }, 71 },
72 » » » » "blobstore": {mp(blobstore.Key("sup")), mp(blobs tore.Key("nerds"))}, 72 » » » » "blobstore": ds.PropertySlice{mp(blobstore.Key(" sup")), mp(blobstore.Key("nerds"))},
73 }, 73 },
74 }, 74 },
75 { 75 {
76 "geo", 76 "geo",
77 ds.PropertyMap{ 77 ds.PropertyMap{
78 » » » » "G": {mp(ds.GeoPoint{Lat: 1, Lng: 2})}, 78 » » » » "G": mp(ds.GeoPoint{Lat: 1, Lng: 2}),
79 }, 79 },
80 }, 80 },
81 { 81 {
82 "data", 82 "data",
83 ds.PropertyMap{ 83 ds.PropertyMap{
84 » » » » "S": {mp("sup"), mp("fool"), mp("nerd") }, 84 » » » » "S": ds.PropertySlice{mp("sup"), mp("fo ol"), mp("nerd")},
85 » » » » "D.Foo.Nerd": {mp([]byte("sup")), mp([]byte("foo l"))}, 85 » » » » "D.Foo.Nerd": ds.PropertySlice{mp([]byte("sup")) , mp([]byte("fool"))},
86 }, 86 },
87 }, 87 },
88 { 88 {
89 "time", 89 "time",
90 ds.PropertyMap{ 90 ds.PropertyMap{
91 » » » » "T": { 91 » » » » "T": ds.PropertySlice{
92 mp(now), 92 mp(now),
93 mp(now.Add(time.Second)), 93 mp(now.Add(time.Second)),
94 }, 94 },
95 }, 95 },
96 }, 96 },
97 { 97 {
98 "empty vals", 98 "empty vals",
99 ds.PropertyMap{ 99 ds.PropertyMap{
100 » » » » "T": {mp(true), mp(true)}, 100 » » » » "T": ds.PropertySlice{mp(true), mp(true)},
101 » » » » "F": {mp(false), mp(false)}, 101 » » » » "F": ds.PropertySlice{mp(false), mp(false)},
102 » » » » "N": {mp(nil), mp(nil)}, 102 » » » » "N": ds.PropertySlice{mp(nil), mp(nil)},
103 » » » » "E": {}, 103 » » » » "E": ds.PropertySlice{},
104 }, 104 },
105 }, 105 },
106 } 106 }
107 107
108 Convey("PropertyMap serialization", t, func() { 108 Convey("PropertyMap serialization", t, func() {
109 Convey("round trip", func() { 109 Convey("round trip", func() {
110 for _, tc := range tests { 110 for _, tc := range tests {
111 tc := tc 111 tc := tc
112 Convey(tc.name, func() { 112 Convey(tc.name, func() {
113 data := ToBytesWithContext(tc.props) 113 data := ToBytesWithContext(tc.props)
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 } 475 }
476 476
477 func TestPartialSerialization(t *testing.T) { 477 func TestPartialSerialization(t *testing.T) {
478 t.Parallel() 478 t.Parallel()
479 479
480 fakeKey := mkKey("dev~app", "ns", "parentKind", "sid", "knd", 10) 480 fakeKey := mkKey("dev~app", "ns", "parentKind", "sid", "knd", 10)
481 481
482 Convey("TestPartialSerialization", t, func() { 482 Convey("TestPartialSerialization", t, func() {
483 Convey("list", func() { 483 Convey("list", func() {
484 pm := ds.PropertyMap{ 484 pm := ds.PropertyMap{
485 » » » » "wat": {mpNI("thing"), mp("hat"), mp(100)}, 485 » » » » "wat": ds.PropertySlice{mpNI("thing"), mp("hat" ), mp(100)},
486 » » » » "nerd": {mp(103.7)}, 486 » » » » "nerd": mp(103.7),
487 » » » » "spaz": {mpNI(false)}, 487 » » » » "spaz": mpNI(false),
488 } 488 }
489 sip := PropertyMapPartially(fakeKey, pm) 489 sip := PropertyMapPartially(fakeKey, pm)
490 So(len(sip), ShouldEqual, 4) 490 So(len(sip), ShouldEqual, 4)
491 491
492 Convey("single collated", func() { 492 Convey("single collated", func() {
493 Convey("indexableMap", func() { 493 Convey("indexableMap", func() {
494 So(sip, ShouldResemble, SerializedPmap{ 494 So(sip, ShouldResemble, SerializedPmap{
495 "wat": { 495 "wat": {
496 ToBytes(mp("hat")), 496 ToBytes(mp("hat")),
497 ToBytes(mp(100)), 497 ToBytes(mp(100)),
498 // 'thing' is skipped, b ecause it's not NoIndex 498 // 'thing' is skipped, b ecause it's not NoIndex
499 }, 499 },
500 "nerd": { 500 "nerd": {
501 ToBytes(mp(103.7)), 501 ToBytes(mp(103.7)),
502 }, 502 },
503 "__key__": { 503 "__key__": {
504 ToBytes(mp(fakeKey)), 504 ToBytes(mp(fakeKey)),
505 }, 505 },
506 "__ancestor__": { 506 "__ancestor__": {
507 ToBytes(mp(fakeKey)), 507 ToBytes(mp(fakeKey)),
508 ToBytes(mp(fakeKey.Paren t())), 508 ToBytes(mp(fakeKey.Paren t())),
509 }, 509 },
510 }) 510 })
511 }) 511 })
512 }) 512 })
513 }) 513 })
514 }) 514 })
515 } 515 }
OLDNEW
« no previous file with comments | « service/datastore/serialize/serialize.go ('k') | service/datastore/size_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698