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

Side by Side Diff: service/rawdatastore/serialize_test.go

Issue 1243323002: Refactor a bit. (Closed) Base URL: https://github.com/luci/gae.git@master
Patch Set: fix golint Created 5 years, 5 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/rawdatastore/serialize.go ('k') | service/rawdatastore/types.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 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 helper 5 package rawdatastore
6 6
7 import ( 7 import (
8 "bytes" 8 "bytes"
9 "io" 9 "io"
10 "testing" 10 "testing"
11 "time" 11 "time"
12 12
13 » "github.com/luci/gae" 13 » "github.com/luci/gae/service/blobstore"
14 "github.com/luci/luci-go/common/cmpbin" 14 "github.com/luci/luci-go/common/cmpbin"
15 . "github.com/smartystreets/goconvey/convey" 15 . "github.com/smartystreets/goconvey/convey"
16 ) 16 )
17 17
18 func init() { 18 func init() {
19 » WriteDSPropertyMapDeterministic = true 19 » WritePropertyMapDeterministic = true
20 } 20 }
21 21
22 type dspmapTC struct { 22 type dspmapTC struct {
23 name string 23 name string
24 » props gae.DSPropertyMap 24 » props PropertyMap
25 } 25 }
26 26
27 func TestDSPropertyMapSerialization(t *testing.T) { 27 func TestPropertyMapSerialization(t *testing.T) {
28 t.Parallel() 28 t.Parallel()
29 29
30 tests := []dspmapTC{ 30 tests := []dspmapTC{
31 { 31 {
32 "basic", 32 "basic",
33 » » » gae.DSPropertyMap{ 33 » » » PropertyMap{
34 "R": {mp(false), mp(2.1), mpNI(3)}, 34 "R": {mp(false), mp(2.1), mpNI(3)},
35 "S": {mp("hello"), mp("world")}, 35 "S": {mp("hello"), mp("world")},
36 }, 36 },
37 }, 37 },
38 { 38 {
39 "keys", 39 "keys",
40 » » » gae.DSPropertyMap{ 40 » » » PropertyMap{
41 » » » » "DS": {mp(mkKey("appy", "ns", "Foo", 7)), mp(mkK ey("other", "", "Yot", "wheeep"))}, 41 » » » » "DS": {mp(mkKey("appy", "ns", "Foo", 7)), mp(mkKey("other", "", "Yot", "wheeep"))},
42 » » » » "BS": {mp(gae.BSKey("sup")), mp(gae.BSKey("nerds "))}, 42 » » » » "blobstore": {mp(blobstore.Key("sup")), mp(blobs tore.Key("nerds"))},
43 }, 43 },
44 }, 44 },
45 { 45 {
46 "geo", 46 "geo",
47 » » » gae.DSPropertyMap{ 47 » » » PropertyMap{
48 » » » » "G": {mp(gae.DSGeoPoint{Lat: 1, Lng: 2})}, 48 » » » » "G": {mp(GeoPoint{Lat: 1, Lng: 2})},
49 }, 49 },
50 }, 50 },
51 { 51 {
52 "data", 52 "data",
53 » » » gae.DSPropertyMap{ 53 » » » PropertyMap{
54 "S": {mp("sup"), mp("fool"), mp("nerd") }, 54 "S": {mp("sup"), mp("fool"), mp("nerd") },
55 "D.Foo.Nerd": {mp([]byte("sup")), mp([]byte("foo l"))}, 55 "D.Foo.Nerd": {mp([]byte("sup")), mp([]byte("foo l"))},
56 » » » » "B": {mp(gae.DSByteString("sup")), mp(g ae.DSByteString("fool"))}, 56 » » » » "B": {mp(ByteString("sup")), mp(ByteStr ing("fool"))},
57 }, 57 },
58 }, 58 },
59 { 59 {
60 "time", 60 "time",
61 » » » gae.DSPropertyMap{ 61 » » » PropertyMap{
62 "T": { 62 "T": {
63 mp(time.Now().UTC()), 63 mp(time.Now().UTC()),
64 mp(time.Now().Add(time.Second).UTC())}, 64 mp(time.Now().Add(time.Second).UTC())},
65 }, 65 },
66 }, 66 },
67 { 67 {
68 "empty vals", 68 "empty vals",
69 » » » gae.DSPropertyMap{ 69 » » » PropertyMap{
70 "T": {mp(true), mp(true)}, 70 "T": {mp(true), mp(true)},
71 "F": {mp(false), mp(false)}, 71 "F": {mp(false), mp(false)},
72 "N": {mp(nil), mp(nil)}, 72 "N": {mp(nil), mp(nil)},
73 "E": {}, 73 "E": {},
74 }, 74 },
75 }, 75 },
76 } 76 }
77 77
78 » Convey("DSPropertyMap serialization", t, func() { 78 » Convey("PropertyMap serialization", t, func() {
79 Convey("round trip", func() { 79 Convey("round trip", func() {
80 for _, tc := range tests { 80 for _, tc := range tests {
81 tc := tc 81 tc := tc
82 Convey(tc.name, func() { 82 Convey(tc.name, func() {
83 buf := &bytes.Buffer{} 83 buf := &bytes.Buffer{}
84 » » » » » WriteDSPropertyMap(buf, tc.props, WithCo ntext) 84 » » » » » WritePropertyMap(buf, tc.props, WithCont ext)
85 » » » » » dec, err := ReadDSPropertyMap(buf, WithC ontext, "", "") 85 » » » » » dec, err := ReadPropertyMap(buf, WithCon text, "", "")
86 So(err, ShouldBeNil) 86 So(err, ShouldBeNil)
87 So(dec, ShouldResemble, tc.props) 87 So(dec, ShouldResemble, tc.props)
88 }) 88 })
89 } 89 }
90 }) 90 })
91 }) 91 })
92 } 92 }
93 93
94 func TestSerializationReadMisc(t *testing.T) { 94 func TestSerializationReadMisc(t *testing.T) {
95 t.Parallel() 95 t.Parallel()
96 96
97 Convey("Misc Serialization tests", t, func() { 97 Convey("Misc Serialization tests", t, func() {
98 » » Convey("ReadDSKey", func() { 98 » » buf := &bytes.Buffer{}
99 » » Convey("ReadKey", func() {
99 Convey("good cases", func() { 100 Convey("good cases", func() {
100 Convey("w/ ctx decodes normally w/ ctx", func() { 101 Convey("w/ ctx decodes normally w/ ctx", func() {
101 k := mkKey("aid", "ns", "knd", "yo", "ot her", 10) 102 k := mkKey("aid", "ns", "knd", "yo", "ot her", 10)
102 » » » » » buf := &bytes.Buffer{} 103 » » » » » WriteKey(buf, WithContext, k)
103 » » » » » WriteDSKey(buf, WithContext, k) 104 » » » » » dk, err := ReadKey(buf, WithContext, "", "")
104 » » » » » dk, err := ReadDSKey(buf, WithContext, " ", "")
105 So(err, ShouldBeNil) 105 So(err, ShouldBeNil)
106 So(dk, ShouldEqualKey, k) 106 So(dk, ShouldEqualKey, k)
107 }) 107 })
108 Convey("w/ ctx decodes normally w/o ctx", func() { 108 Convey("w/ ctx decodes normally w/o ctx", func() {
109 k := mkKey("aid", "ns", "knd", "yo", "ot her", 10) 109 k := mkKey("aid", "ns", "knd", "yo", "ot her", 10)
110 » » » » » buf := &bytes.Buffer{} 110 » » » » » WriteKey(buf, WithContext, k)
111 » » » » » WriteDSKey(buf, WithContext, k) 111 » » » » » dk, err := ReadKey(buf, WithoutContext, "spam", "nerd")
112 » » » » » dk, err := ReadDSKey(buf, WithoutContext , "spam", "nerd")
113 So(err, ShouldBeNil) 112 So(err, ShouldBeNil)
114 So(dk, ShouldEqualKey, mkKey("spam", "ne rd", "knd", "yo", "other", 10)) 113 So(dk, ShouldEqualKey, mkKey("spam", "ne rd", "knd", "yo", "other", 10))
115 }) 114 })
116 Convey("w/o ctx decodes normally w/ ctx", func() { 115 Convey("w/o ctx decodes normally w/ ctx", func() {
117 k := mkKey("aid", "ns", "knd", "yo", "ot her", 10) 116 k := mkKey("aid", "ns", "knd", "yo", "ot her", 10)
118 » » » » » buf := &bytes.Buffer{} 117 » » » » » WriteKey(buf, WithoutContext, k)
119 » » » » » WriteDSKey(buf, WithoutContext, k) 118 » » » » » dk, err := ReadKey(buf, WithContext, "sp am", "nerd")
120 » » » » » dk, err := ReadDSKey(buf, WithContext, " spam", "nerd")
121 So(err, ShouldBeNil) 119 So(err, ShouldBeNil)
122 So(dk, ShouldEqualKey, mkKey("", "", "kn d", "yo", "other", 10)) 120 So(dk, ShouldEqualKey, mkKey("", "", "kn d", "yo", "other", 10))
123 }) 121 })
124 Convey("w/o ctx decodes normally w/o ctx", func( ) { 122 Convey("w/o ctx decodes normally w/o ctx", func( ) {
125 k := mkKey("aid", "ns", "knd", "yo", "ot her", 10) 123 k := mkKey("aid", "ns", "knd", "yo", "ot her", 10)
126 » » » » » buf := &bytes.Buffer{} 124 » » » » » WriteKey(buf, WithoutContext, k)
127 » » » » » WriteDSKey(buf, WithoutContext, k) 125 » » » » » dk, err := ReadKey(buf, WithoutContext, "spam", "nerd")
128 » » » » » dk, err := ReadDSKey(buf, WithoutContext , "spam", "nerd")
129 So(err, ShouldBeNil) 126 So(err, ShouldBeNil)
130 So(dk, ShouldEqualKey, mkKey("spam", "ne rd", "knd", "yo", "other", 10)) 127 So(dk, ShouldEqualKey, mkKey("spam", "ne rd", "knd", "yo", "other", 10))
131 }) 128 })
132 Convey("IntIDs always sort before StringIDs", fu nc() { 129 Convey("IntIDs always sort before StringIDs", fu nc() {
133 // -1 writes as almost all 1's in the fi rst byte under cmpbin, even 130 // -1 writes as almost all 1's in the fi rst byte under cmpbin, even
134 // though it's technically not a valid k ey. 131 // though it's technically not a valid k ey.
135 k := mkKey("aid", "ns", "knd", -1) 132 k := mkKey("aid", "ns", "knd", -1)
136 » » » » » buf := &bytes.Buffer{} 133 » » » » » WriteKey(buf, WithoutContext, k)
137 » » » » » WriteDSKey(buf, WithoutContext, k)
138 134
139 k = mkKey("aid", "ns", "knd", "hat") 135 k = mkKey("aid", "ns", "knd", "hat")
140 buf2 := &bytes.Buffer{} 136 buf2 := &bytes.Buffer{}
141 » » » » » WriteDSKey(buf2, WithoutContext, k) 137 » » » » » WriteKey(buf2, WithoutContext, k)
142 138
143 So(bytes.Compare(buf.Bytes(), buf2.Bytes ()), ShouldBeLessThan, 0) 139 So(bytes.Compare(buf.Bytes(), buf2.Bytes ()), ShouldBeLessThan, 0)
144 }) 140 })
145 }) 141 })
146 142
147 Convey("err cases", func() { 143 Convey("err cases", func() {
148 Convey("nil", func() { 144 Convey("nil", func() {
149 » » » » » buf := &bytes.Buffer{} 145 » » » » » _, err := ReadKey(buf, WithContext, "", "")
150 » » » » » _, err := ReadDSKey(buf, WithContext, "" , "")
151 So(err, ShouldEqual, io.EOF) 146 So(err, ShouldEqual, io.EOF)
152 }) 147 })
153 Convey("str", func() { 148 Convey("str", func() {
154 buf := &bytes.Buffer{}
155 buf.WriteString("sup") 149 buf.WriteString("sup")
156 » » » » » _, err := ReadDSKey(buf, WithContext, "" , "") 150 » » » » » _, err := ReadKey(buf, WithContext, "", "")
157 So(err, ShouldErrLike, "expected actualC tx") 151 So(err, ShouldErrLike, "expected actualC tx")
158 }) 152 })
159 Convey("truncated 1", func() { 153 Convey("truncated 1", func() {
160 buf := &bytes.Buffer{}
161 buf.WriteByte(1) // actualCtx == 1 154 buf.WriteByte(1) // actualCtx == 1
162 » » » » » _, err := ReadDSKey(buf, WithContext, "" , "") 155 » » » » » _, err := ReadKey(buf, WithContext, "", "")
163 So(err, ShouldEqual, io.EOF) 156 So(err, ShouldEqual, io.EOF)
164 }) 157 })
165 Convey("truncated 2", func() { 158 Convey("truncated 2", func() {
166 buf := &bytes.Buffer{}
167 buf.WriteByte(1) // actualCtx == 1 159 buf.WriteByte(1) // actualCtx == 1
168 cmpbin.WriteString(buf, "aid") 160 cmpbin.WriteString(buf, "aid")
169 » » » » » _, err := ReadDSKey(buf, WithContext, "" , "") 161 » » » » » _, err := ReadKey(buf, WithContext, "", "")
170 So(err, ShouldEqual, io.EOF) 162 So(err, ShouldEqual, io.EOF)
171 }) 163 })
172 Convey("truncated 3", func() { 164 Convey("truncated 3", func() {
173 buf := &bytes.Buffer{}
174 buf.WriteByte(1) // actualCtx == 1 165 buf.WriteByte(1) // actualCtx == 1
175 cmpbin.WriteString(buf, "aid") 166 cmpbin.WriteString(buf, "aid")
176 cmpbin.WriteString(buf, "ns") 167 cmpbin.WriteString(buf, "ns")
177 » » » » » _, err := ReadDSKey(buf, WithContext, "" , "") 168 » » » » » _, err := ReadKey(buf, WithContext, "", "")
178 So(err, ShouldEqual, io.EOF) 169 So(err, ShouldEqual, io.EOF)
179 }) 170 })
180 Convey("huge key", func() { 171 Convey("huge key", func() {
181 buf := &bytes.Buffer{}
182 buf.WriteByte(1) // actualCtx == 1 172 buf.WriteByte(1) // actualCtx == 1
183 cmpbin.WriteString(buf, "aid") 173 cmpbin.WriteString(buf, "aid")
184 cmpbin.WriteString(buf, "ns") 174 cmpbin.WriteString(buf, "ns")
185 cmpbin.WriteUint(buf, 1000) 175 cmpbin.WriteUint(buf, 1000)
186 » » » » » _, err := ReadDSKey(buf, WithContext, "" , "") 176 » » » » » _, err := ReadKey(buf, WithContext, "", "")
187 So(err, ShouldErrLike, "huge key") 177 So(err, ShouldErrLike, "huge key")
188 }) 178 })
189 Convey("insufficient tokens", func() { 179 Convey("insufficient tokens", func() {
190 buf := &bytes.Buffer{}
191 buf.WriteByte(1) // actualCtx == 1 180 buf.WriteByte(1) // actualCtx == 1
192 cmpbin.WriteString(buf, "aid") 181 cmpbin.WriteString(buf, "aid")
193 cmpbin.WriteString(buf, "ns") 182 cmpbin.WriteString(buf, "ns")
194 cmpbin.WriteUint(buf, 2) 183 cmpbin.WriteUint(buf, 2)
195 » » » » » _, err := ReadDSKey(buf, WithContext, "" , "") 184 » » » » » _, err := ReadKey(buf, WithContext, "", "")
196 So(err, ShouldEqual, io.EOF) 185 So(err, ShouldEqual, io.EOF)
197 }) 186 })
198 Convey("partial token 1", func() { 187 Convey("partial token 1", func() {
199 buf := &bytes.Buffer{}
200 buf.WriteByte(1) // actualCtx == 1 188 buf.WriteByte(1) // actualCtx == 1
201 cmpbin.WriteString(buf, "aid") 189 cmpbin.WriteString(buf, "aid")
202 cmpbin.WriteString(buf, "ns") 190 cmpbin.WriteString(buf, "ns")
203 cmpbin.WriteUint(buf, 2) 191 cmpbin.WriteUint(buf, 2)
204 cmpbin.WriteString(buf, "hi") 192 cmpbin.WriteString(buf, "hi")
205 » » » » » _, err := ReadDSKey(buf, WithContext, "" , "") 193 » » » » » _, err := ReadKey(buf, WithContext, "", "")
206 So(err, ShouldEqual, io.EOF) 194 So(err, ShouldEqual, io.EOF)
207 }) 195 })
208 Convey("partial token 2", func() { 196 Convey("partial token 2", func() {
209 buf := &bytes.Buffer{}
210 buf.WriteByte(1) // actualCtx == 1 197 buf.WriteByte(1) // actualCtx == 1
211 cmpbin.WriteString(buf, "aid") 198 cmpbin.WriteString(buf, "aid")
212 cmpbin.WriteString(buf, "ns") 199 cmpbin.WriteString(buf, "ns")
213 cmpbin.WriteUint(buf, 2) 200 cmpbin.WriteUint(buf, 2)
214 cmpbin.WriteString(buf, "hi") 201 cmpbin.WriteString(buf, "hi")
215 » » » » » buf.WriteByte(byte(gae.DSPTString)) 202 » » » » » buf.WriteByte(byte(PTString))
216 » » » » » _, err := ReadDSKey(buf, WithContext, "" , "") 203 » » » » » _, err := ReadKey(buf, WithContext, "", "")
217 So(err, ShouldEqual, io.EOF) 204 So(err, ShouldEqual, io.EOF)
218 }) 205 })
219 Convey("bad token (invalid type)", func() { 206 Convey("bad token (invalid type)", func() {
220 buf := &bytes.Buffer{}
221 buf.WriteByte(1) // actualCtx == 1 207 buf.WriteByte(1) // actualCtx == 1
222 cmpbin.WriteString(buf, "aid") 208 cmpbin.WriteString(buf, "aid")
223 cmpbin.WriteString(buf, "ns") 209 cmpbin.WriteString(buf, "ns")
224 cmpbin.WriteUint(buf, 2) 210 cmpbin.WriteUint(buf, 2)
225 cmpbin.WriteString(buf, "hi") 211 cmpbin.WriteString(buf, "hi")
226 » » » » » buf.WriteByte(byte(gae.DSPTBlobKey)) 212 » » » » » buf.WriteByte(byte(PTBlobKey))
227 » » » » » _, err := ReadDSKey(buf, WithContext, "" , "") 213 » » » » » _, err := ReadKey(buf, WithContext, "", "")
228 » » » » » So(err, ShouldErrLike, "invalid type DSP TBlobKey") 214 » » » » » So(err, ShouldErrLike, "invalid type PTB lobKey")
229 }) 215 })
230 Convey("bad token (invalid IntID)", func() { 216 Convey("bad token (invalid IntID)", func() {
231 buf := &bytes.Buffer{}
232 buf.WriteByte(1) // actualCtx == 1 217 buf.WriteByte(1) // actualCtx == 1
233 cmpbin.WriteString(buf, "aid") 218 cmpbin.WriteString(buf, "aid")
234 cmpbin.WriteString(buf, "ns") 219 cmpbin.WriteString(buf, "ns")
235 cmpbin.WriteUint(buf, 2) 220 cmpbin.WriteUint(buf, 2)
236 cmpbin.WriteString(buf, "hi") 221 cmpbin.WriteString(buf, "hi")
237 » » » » » buf.WriteByte(byte(gae.DSPTInt)) 222 » » » » » buf.WriteByte(byte(PTInt))
238 cmpbin.WriteInt(buf, -2) 223 cmpbin.WriteInt(buf, -2)
239 » » » » » _, err := ReadDSKey(buf, WithContext, "" , "") 224 » » » » » _, err := ReadKey(buf, WithContext, "", "")
240 So(err, ShouldErrLike, "zero/negative") 225 So(err, ShouldErrLike, "zero/negative")
241 }) 226 })
242 }) 227 })
243 }) 228 })
244 229
245 » » Convey("ReadDSGeoPoint", func() { 230 » » Convey("ReadGeoPoint", func() {
246 Convey("trunc 1", func() { 231 Convey("trunc 1", func() {
247 » » » » buf := &bytes.Buffer{} 232 » » » » _, err := ReadGeoPoint(buf)
248 » » » » _, err := ReadDSGeoPoint(buf)
249 So(err, ShouldEqual, io.EOF) 233 So(err, ShouldEqual, io.EOF)
250 }) 234 })
251 Convey("trunc 2", func() { 235 Convey("trunc 2", func() {
252 buf := &bytes.Buffer{}
253 cmpbin.WriteFloat64(buf, 100) 236 cmpbin.WriteFloat64(buf, 100)
254 » » » » _, err := ReadDSGeoPoint(buf) 237 » » » » _, err := ReadGeoPoint(buf)
255 So(err, ShouldEqual, io.EOF) 238 So(err, ShouldEqual, io.EOF)
256 }) 239 })
257 Convey("invalid", func() { 240 Convey("invalid", func() {
258 buf := &bytes.Buffer{}
259 cmpbin.WriteFloat64(buf, 100) 241 cmpbin.WriteFloat64(buf, 100)
260 cmpbin.WriteFloat64(buf, 1000) 242 cmpbin.WriteFloat64(buf, 1000)
261 » » » » _, err := ReadDSGeoPoint(buf) 243 » » » » _, err := ReadGeoPoint(buf)
262 » » » » So(err, ShouldErrLike, "invalid DSGeoPoint") 244 » » » » So(err, ShouldErrLike, "invalid GeoPoint")
263 }) 245 })
264 }) 246 })
265 247
266 Convey("WriteTime", func() { 248 Convey("WriteTime", func() {
267 Convey("in non-UTC!", func() { 249 Convey("in non-UTC!", func() {
268 buf := &bytes.Buffer{}
269 pst, err := time.LoadLocation("America/Los_Angel es") 250 pst, err := time.LoadLocation("America/Los_Angel es")
270 So(err, ShouldBeNil) 251 So(err, ShouldBeNil)
271 So(func() { 252 So(func() {
272 WriteTime(buf, time.Now().In(pst)) 253 WriteTime(buf, time.Now().In(pst))
273 }, ShouldPanic) 254 }, ShouldPanic)
274 }) 255 })
275 }) 256 })
276 257
277 Convey("ReadTime", func() { 258 Convey("ReadTime", func() {
278 Convey("trunc 1", func() { 259 Convey("trunc 1", func() {
279 buf := &bytes.Buffer{}
280 _, err := ReadTime(buf) 260 _, err := ReadTime(buf)
281 So(err, ShouldEqual, io.EOF) 261 So(err, ShouldEqual, io.EOF)
282 }) 262 })
283 }) 263 })
284 264
285 » » Convey("ReadDSProperty", func() { 265 » » Convey("ReadProperty", func() {
286 Convey("trunc 1", func() { 266 Convey("trunc 1", func() {
287 » » » » buf := &bytes.Buffer{} 267 » » » » _, err := ReadProperty(buf, WithContext, "", "")
288 » » » » _, err := ReadDSProperty(buf, WithContext, "", " ")
289 So(err, ShouldEqual, io.EOF) 268 So(err, ShouldEqual, io.EOF)
290 }) 269 })
291 » » » Convey("trunc (DSPTBytes)", func() { 270 » » » Convey("trunc (PTBytes)", func() {
292 » » » » buf := &bytes.Buffer{} 271 » » » » buf.WriteByte(byte(PTBytes))
293 » » » » buf.WriteByte(byte(gae.DSPTBytes)) 272 » » » » _, err := ReadProperty(buf, WithContext, "", "")
294 » » » » _, err := ReadDSProperty(buf, WithContext, "", " ")
295 So(err, ShouldEqual, io.EOF) 273 So(err, ShouldEqual, io.EOF)
296 }) 274 })
297 » » » Convey("trunc (DSPTBlobKey)", func() { 275 » » » Convey("trunc (PTBlobKey)", func() {
298 » » » » buf := &bytes.Buffer{} 276 » » » » buf.WriteByte(byte(PTBlobKey))
299 » » » » buf.WriteByte(byte(gae.DSPTBlobKey)) 277 » » » » _, err := ReadProperty(buf, WithContext, "", "")
300 » » » » _, err := ReadDSProperty(buf, WithContext, "", " ")
301 So(err, ShouldEqual, io.EOF) 278 So(err, ShouldEqual, io.EOF)
302 }) 279 })
303 Convey("invalid type", func() { 280 Convey("invalid type", func() {
304 » » » » buf := &bytes.Buffer{} 281 » » » » buf.WriteByte(byte(PTUnknown + 1))
305 » » » » buf.WriteByte(byte(gae.DSPTUnknown + 1)) 282 » » » » _, err := ReadProperty(buf, WithContext, "", "")
306 » » » » _, err := ReadDSProperty(buf, WithContext, "", " ")
307 So(err, ShouldErrLike, "unknown type!") 283 So(err, ShouldErrLike, "unknown type!")
308 }) 284 })
309 }) 285 })
310 286
311 » » Convey("ReadDSPropertyMap", func() { 287 » » Convey("ReadPropertyMap", func() {
312 Convey("trunc 1", func() { 288 Convey("trunc 1", func() {
313 » » » » buf := &bytes.Buffer{} 289 » » » » _, err := ReadPropertyMap(buf, WithContext, "", "")
314 » » » » _, err := ReadDSPropertyMap(buf, WithContext, "" , "")
315 So(err, ShouldEqual, io.EOF) 290 So(err, ShouldEqual, io.EOF)
316 }) 291 })
317 Convey("too many rows", func() { 292 Convey("too many rows", func() {
318 buf := &bytes.Buffer{}
319 cmpbin.WriteUint(buf, 1000000) 293 cmpbin.WriteUint(buf, 1000000)
320 » » » » _, err := ReadDSPropertyMap(buf, WithContext, "" , "") 294 » » » » _, err := ReadPropertyMap(buf, WithContext, "", "")
321 So(err, ShouldErrLike, "huge number of rows") 295 So(err, ShouldErrLike, "huge number of rows")
322 }) 296 })
323 Convey("trunc 2", func() { 297 Convey("trunc 2", func() {
324 buf := &bytes.Buffer{}
325 cmpbin.WriteUint(buf, 10) 298 cmpbin.WriteUint(buf, 10)
326 » » » » _, err := ReadDSPropertyMap(buf, WithContext, "" , "") 299 » » » » _, err := ReadPropertyMap(buf, WithContext, "", "")
327 So(err, ShouldEqual, io.EOF) 300 So(err, ShouldEqual, io.EOF)
328 }) 301 })
329 Convey("trunc 3", func() { 302 Convey("trunc 3", func() {
330 buf := &bytes.Buffer{}
331 cmpbin.WriteUint(buf, 10) 303 cmpbin.WriteUint(buf, 10)
332 cmpbin.WriteString(buf, "ohai") 304 cmpbin.WriteString(buf, "ohai")
333 » » » » _, err := ReadDSPropertyMap(buf, WithContext, "" , "") 305 » » » » _, err := ReadPropertyMap(buf, WithContext, "", "")
334 So(err, ShouldEqual, io.EOF) 306 So(err, ShouldEqual, io.EOF)
335 }) 307 })
336 Convey("too many values", func() { 308 Convey("too many values", func() {
337 buf := &bytes.Buffer{}
338 cmpbin.WriteUint(buf, 10) 309 cmpbin.WriteUint(buf, 10)
339 cmpbin.WriteString(buf, "ohai") 310 cmpbin.WriteString(buf, "ohai")
340 cmpbin.WriteUint(buf, 100000) 311 cmpbin.WriteUint(buf, 100000)
341 » » » » _, err := ReadDSPropertyMap(buf, WithContext, "" , "") 312 » » » » _, err := ReadPropertyMap(buf, WithContext, "", "")
342 So(err, ShouldErrLike, "huge number of propertie s") 313 So(err, ShouldErrLike, "huge number of propertie s")
343 }) 314 })
344 Convey("trunc 4", func() { 315 Convey("trunc 4", func() {
345 buf := &bytes.Buffer{}
346 cmpbin.WriteUint(buf, 10) 316 cmpbin.WriteUint(buf, 10)
347 cmpbin.WriteString(buf, "ohai") 317 cmpbin.WriteString(buf, "ohai")
348 cmpbin.WriteUint(buf, 10) 318 cmpbin.WriteUint(buf, 10)
349 » » » » _, err := ReadDSPropertyMap(buf, WithContext, "" , "") 319 » » » » _, err := ReadPropertyMap(buf, WithContext, "", "")
350 So(err, ShouldEqual, io.EOF) 320 So(err, ShouldEqual, io.EOF)
351 }) 321 })
352 }) 322 })
353 }) 323 })
354 } 324 }
OLDNEW
« no previous file with comments | « service/rawdatastore/serialize.go ('k') | service/rawdatastore/types.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698