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

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

Issue 1286093007: Fix key encoding to be null terminated (Closed) Base URL: https://github.com/luci/gae.git@add_iterator
Patch Set: Set limit to > instead of >= Created 5 years, 4 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 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 buf.WriteByte(1) // actualCtx == 1 249 buf.WriteByte(1) // actualCtx == 1
250 cmpbin.WriteString(buf, "aid") 250 cmpbin.WriteString(buf, "aid")
251 cmpbin.WriteString(buf, "ns") 251 cmpbin.WriteString(buf, "ns")
252 _, err := ReadKey(buf, WithContext, "", "") 252 _, err := ReadKey(buf, WithContext, "", "")
253 So(err, ShouldEqual, io.EOF) 253 So(err, ShouldEqual, io.EOF)
254 }) 254 })
255 Convey("huge key", func() { 255 Convey("huge key", func() {
256 buf.WriteByte(1) // actualCtx == 1 256 buf.WriteByte(1) // actualCtx == 1
257 cmpbin.WriteString(buf, "aid") 257 cmpbin.WriteString(buf, "aid")
258 cmpbin.WriteString(buf, "ns") 258 cmpbin.WriteString(buf, "ns")
259 » » » » » cmpbin.WriteUint(buf, 1000) 259 » » » » » for i := 1; i < 60; i++ {
260 » » » » » » buf.WriteByte(1)
261 » » » » » » WriteKeyTok(buf, ds.KeyTok{Kind: "sup", IntID: int64(i)})
262 » » » » » }
263 » » » » » buf.WriteByte(0)
260 _, err := ReadKey(buf, WithContext, "", "") 264 _, err := ReadKey(buf, WithContext, "", "")
261 So(err, ShouldErrLike, "huge key") 265 So(err, ShouldErrLike, "huge key")
262 }) 266 })
263 Convey("insufficient tokens", func() { 267 Convey("insufficient tokens", func() {
264 buf.WriteByte(1) // actualCtx == 1 268 buf.WriteByte(1) // actualCtx == 1
265 cmpbin.WriteString(buf, "aid") 269 cmpbin.WriteString(buf, "aid")
266 cmpbin.WriteString(buf, "ns") 270 cmpbin.WriteString(buf, "ns")
267 cmpbin.WriteUint(buf, 2) 271 cmpbin.WriteUint(buf, 2)
268 _, err := ReadKey(buf, WithContext, "", "") 272 _, err := ReadKey(buf, WithContext, "", "")
269 So(err, ShouldEqual, io.EOF) 273 So(err, ShouldEqual, io.EOF)
270 }) 274 })
271 Convey("partial token 1", func() { 275 Convey("partial token 1", func() {
272 buf.WriteByte(1) // actualCtx == 1 276 buf.WriteByte(1) // actualCtx == 1
273 cmpbin.WriteString(buf, "aid") 277 cmpbin.WriteString(buf, "aid")
274 cmpbin.WriteString(buf, "ns") 278 cmpbin.WriteString(buf, "ns")
275 » » » » » cmpbin.WriteUint(buf, 2) 279 » » » » » buf.WriteByte(1)
276 cmpbin.WriteString(buf, "hi") 280 cmpbin.WriteString(buf, "hi")
277 _, err := ReadKey(buf, WithContext, "", "") 281 _, err := ReadKey(buf, WithContext, "", "")
278 So(err, ShouldEqual, io.EOF) 282 So(err, ShouldEqual, io.EOF)
279 }) 283 })
280 Convey("partial token 2", func() { 284 Convey("partial token 2", func() {
281 buf.WriteByte(1) // actualCtx == 1 285 buf.WriteByte(1) // actualCtx == 1
282 cmpbin.WriteString(buf, "aid") 286 cmpbin.WriteString(buf, "aid")
283 cmpbin.WriteString(buf, "ns") 287 cmpbin.WriteString(buf, "ns")
284 » » » » » cmpbin.WriteUint(buf, 2) 288 » » » » » buf.WriteByte(1)
285 cmpbin.WriteString(buf, "hi") 289 cmpbin.WriteString(buf, "hi")
286 buf.WriteByte(byte(ds.PTString)) 290 buf.WriteByte(byte(ds.PTString))
287 _, err := ReadKey(buf, WithContext, "", "") 291 _, err := ReadKey(buf, WithContext, "", "")
288 So(err, ShouldEqual, io.EOF) 292 So(err, ShouldEqual, io.EOF)
289 }) 293 })
290 Convey("bad token (invalid type)", func() { 294 Convey("bad token (invalid type)", func() {
291 buf.WriteByte(1) // actualCtx == 1 295 buf.WriteByte(1) // actualCtx == 1
292 cmpbin.WriteString(buf, "aid") 296 cmpbin.WriteString(buf, "aid")
293 cmpbin.WriteString(buf, "ns") 297 cmpbin.WriteString(buf, "ns")
294 » » » » » cmpbin.WriteUint(buf, 2) 298 » » » » » buf.WriteByte(1)
295 cmpbin.WriteString(buf, "hi") 299 cmpbin.WriteString(buf, "hi")
296 buf.WriteByte(byte(ds.PTBlobKey)) 300 buf.WriteByte(byte(ds.PTBlobKey))
297 _, err := ReadKey(buf, WithContext, "", "") 301 _, err := ReadKey(buf, WithContext, "", "")
298 So(err, ShouldErrLike, "invalid type PTB lobKey") 302 So(err, ShouldErrLike, "invalid type PTB lobKey")
299 }) 303 })
300 Convey("bad token (invalid IntID)", func() { 304 Convey("bad token (invalid IntID)", func() {
301 buf.WriteByte(1) // actualCtx == 1 305 buf.WriteByte(1) // actualCtx == 1
302 cmpbin.WriteString(buf, "aid") 306 cmpbin.WriteString(buf, "aid")
303 cmpbin.WriteString(buf, "ns") 307 cmpbin.WriteString(buf, "ns")
304 » » » » » cmpbin.WriteUint(buf, 2) 308 » » » » » buf.WriteByte(1)
305 cmpbin.WriteString(buf, "hi") 309 cmpbin.WriteString(buf, "hi")
306 buf.WriteByte(byte(ds.PTInt)) 310 buf.WriteByte(byte(ds.PTInt))
307 cmpbin.WriteInt(buf, -2) 311 cmpbin.WriteInt(buf, -2)
308 _, err := ReadKey(buf, WithContext, "", "") 312 _, err := ReadKey(buf, WithContext, "", "")
309 So(err, ShouldErrLike, "zero/negative") 313 So(err, ShouldErrLike, "zero/negative")
310 }) 314 })
311 }) 315 })
312 }) 316 })
313 317
314 Convey("ReadGeoPoint", func() { 318 Convey("ReadGeoPoint", func() {
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 for i := 0; i < MaxIndexColumns+1; i++ { 450 for i := 0; i < MaxIndexColumns+1; i++ {
447 id.SortBy = append(id.SortBy, ds.IndexCo lumn{Property: "Hi", Direction: ds.ASCENDING}) 451 id.SortBy = append(id.SortBy, ds.IndexCo lumn{Property: "Hi", Direction: ds.ASCENDING})
448 } 452 }
449 data := ToBytes(id) 453 data := ToBytes(id)
450 newID, err = ReadIndexDefinition(mkBuf(data)) 454 newID, err = ReadIndexDefinition(mkBuf(data))
451 So(err, ShouldErrLike, "over 64 sort orders") 455 So(err, ShouldErrLike, "over 64 sort orders")
452 }) 456 })
453 }) 457 })
454 }) 458 })
455 } 459 }
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