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

Side by Side Diff: service/datastore/serialize/serialize_test.go

Issue 1550903002: impl/memory: Fix time serialization encoding. (Closed) Base URL: https://github.com/luci/gae@master
Patch Set: Comments, tune-up. Created 4 years, 11 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') | no next file » | 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 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 serialize 5 package serialize
6 6
7 import ( 7 import (
8 "bytes" 8 "bytes"
9 "fmt" 9 "fmt"
10 "io" 10 "io"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 } 45 }
46 if actual.(*ds.Key).Equal(expected[0].(*ds.Key)) { 46 if actual.(*ds.Key).Equal(expected[0].(*ds.Key)) {
47 return "" 47 return ""
48 } 48 }
49 return fmt.Sprintf("Expected: %q\nActual: %q", actual, expected[0]) 49 return fmt.Sprintf("Expected: %q\nActual: %q", actual, expected[0])
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 tests := []dspmapTC{ 56 tests := []dspmapTC{
56 { 57 {
57 "basic", 58 "basic",
58 ds.PropertyMap{ 59 ds.PropertyMap{
59 "R": {mp(false), mp(2.1), mpNI(3)}, 60 "R": {mp(false), mp(2.1), mpNI(3)},
60 "S": {mp("hello"), mp("world")}, 61 "S": {mp("hello"), mp("world")},
61 }, 62 },
62 }, 63 },
63 { 64 {
64 "keys", 65 "keys",
(...skipping 12 matching lines...) Expand all
77 "data", 78 "data",
78 ds.PropertyMap{ 79 ds.PropertyMap{
79 "S": {mp("sup"), mp("fool"), mp("nerd") }, 80 "S": {mp("sup"), mp("fool"), mp("nerd") },
80 "D.Foo.Nerd": {mp([]byte("sup")), mp([]byte("foo l"))}, 81 "D.Foo.Nerd": {mp([]byte("sup")), mp([]byte("foo l"))},
81 }, 82 },
82 }, 83 },
83 { 84 {
84 "time", 85 "time",
85 ds.PropertyMap{ 86 ds.PropertyMap{
86 "T": { 87 "T": {
87 » » » » » mp(time.Now().UTC()), 88 » » » » » mp(now),
88 » » » » » mp(time.Now().Add(time.Second).UTC())}, 89 » » » » » mp(now.Add(time.Second)),
90 » » » » },
89 }, 91 },
90 }, 92 },
91 { 93 {
92 "empty vals", 94 "empty vals",
93 ds.PropertyMap{ 95 ds.PropertyMap{
94 "T": {mp(true), mp(true)}, 96 "T": {mp(true), mp(true)},
95 "F": {mp(false), mp(false)}, 97 "F": {mp(false), mp(false)},
96 "N": {mp(nil), mp(nil)}, 98 "N": {mp(nil), mp(nil)},
97 "E": {}, 99 "E": {},
98 }, 100 },
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 Convey("Time", func() { 185 Convey("Time", func() {
184 tp := mp(time.Now().UTC()) 186 tp := mp(time.Now().UTC())
185 So(string(ToBytes(tp.Value())), ShouldEqual, string(ToBy tes(tp)[1:])) 187 So(string(ToBytes(tp.Value())), ShouldEqual, string(ToBy tes(tp)[1:]))
186 }) 188 })
187 189
188 Convey("Zero time", func() { 190 Convey("Zero time", func() {
189 buf := mkBuf(nil) 191 buf := mkBuf(nil)
190 So(WriteTime(buf, time.Time{}), ShouldBeNil) 192 So(WriteTime(buf, time.Time{}), ShouldBeNil)
191 t, err := ReadTime(mkBuf(buf.Bytes())) 193 t, err := ReadTime(mkBuf(buf.Bytes()))
192 So(err, ShouldBeNil) 194 So(err, ShouldBeNil)
193 » » » So(t, ShouldResemble, time.Time{}) 195 » » » So(t.Equal(time.Time{}), ShouldBeTrue)
194 » » })
195
196 » » Convey("Bad ToBytes", func() {
197 » » » So(func() { ToBytes(100.7) }, ShouldPanic)
198 » » » So(func() { ToBytesWithContext(100.7) }, ShouldPanic)
199 }) 196 })
200 197
201 Convey("ReadKey", func() { 198 Convey("ReadKey", func() {
202 Convey("good cases", func() { 199 Convey("good cases", func() {
203 Convey("w/ ctx decodes normally w/ ctx", func() { 200 Convey("w/ ctx decodes normally w/ ctx", func() {
204 k := mkKey("aid", "ns", "knd", "yo", "ot her", 10) 201 k := mkKey("aid", "ns", "knd", "yo", "ot her", 10)
205 data := ToBytesWithContext(k) 202 data := ToBytesWithContext(k)
206 dk, err := ReadKey(mkBuf(data), WithCont ext, "", "") 203 dk, err := ReadKey(mkBuf(data), WithCont ext, "", "")
207 So(err, ShouldBeNil) 204 So(err, ShouldBeNil)
208 So(dk, ShouldEqualKey, k) 205 So(dk, ShouldEqualKey, k)
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
505 "__ancestor__": { 502 "__ancestor__": {
506 ToBytes(mp(fakeKey)), 503 ToBytes(mp(fakeKey)),
507 ToBytes(mp(fakeKey.Paren t())), 504 ToBytes(mp(fakeKey.Paren t())),
508 }, 505 },
509 }) 506 })
510 }) 507 })
511 }) 508 })
512 }) 509 })
513 }) 510 })
514 } 511 }
OLDNEW
« no previous file with comments | « service/datastore/serialize/serialize.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698