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

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

Issue 1302813003: impl/memory: Implement Queries (Closed) Base URL: https://github.com/luci/gae.git@add_multi_iterator
Patch Set: stringSet everywhere Created 5 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') | 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 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 buf := mkBuf(nil) 157 buf := mkBuf(nil)
158 cmpbin.WriteString(buf, "foo") 158 cmpbin.WriteString(buf, "foo")
159 buf.WriteByte(byte(ds.PTInt)) 159 buf.WriteByte(byte(ds.PTInt))
160 cmpbin.WriteInt(buf, 20) 160 cmpbin.WriteInt(buf, 20)
161 So(string(ToBytes(ds.KeyTok{Kind: "foo", IntID: 20})), 161 So(string(ToBytes(ds.KeyTok{Kind: "foo", IntID: 20})),
162 ShouldEqual, buf.String()) 162 ShouldEqual, buf.String())
163 }) 163 })
164 164
165 Convey("Property", func() { 165 Convey("Property", func() {
166 buf := mkBuf(nil) 166 buf := mkBuf(nil)
167 » » » buf.WriteByte(byte(ds.PTString)) 167 » » » buf.WriteByte(0x80 | byte(ds.PTString))
168 cmpbin.WriteString(buf, "nerp") 168 cmpbin.WriteString(buf, "nerp")
169 So(string(ToBytes(mp("nerp"))), 169 So(string(ToBytes(mp("nerp"))),
170 ShouldEqual, buf.String()) 170 ShouldEqual, buf.String())
171 }) 171 })
172 172
173 Convey("Time", func() { 173 Convey("Time", func() {
174 tp := mp(time.Now().UTC()) 174 tp := mp(time.Now().UTC())
175 So(string(ToBytes(tp.Value())), ShouldEqual, string(ToBy tes(tp)[1:])) 175 So(string(ToBytes(tp.Value())), ShouldEqual, string(ToBy tes(tp)[1:]))
176 }) 176 })
177 177
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 cmpbin.WriteUint(buf, 10) 409 cmpbin.WriteUint(buf, 10)
410 cmpbin.WriteString(buf, "ohai") 410 cmpbin.WriteString(buf, "ohai")
411 cmpbin.WriteUint(buf, 10) 411 cmpbin.WriteUint(buf, 10)
412 _, err := ReadPropertyMap(buf, WithContext, "", "") 412 _, err := ReadPropertyMap(buf, WithContext, "", "")
413 So(err, ShouldEqual, io.EOF) 413 So(err, ShouldEqual, io.EOF)
414 }) 414 })
415 }) 415 })
416 416
417 Convey("IndexDefinition", func() { 417 Convey("IndexDefinition", func() {
418 id := ds.IndexDefinition{Kind: "kind"} 418 id := ds.IndexDefinition{Kind: "kind"}
419 » » » data := ToBytes(id) 419 » » » data := ToBytes(*id.PrepForIdxTable())
420 » » » So(string(data), ShouldStartWith, string(ds.IndexBuiltin QueryPrefix()))
421 newID, err := ReadIndexDefinition(mkBuf(data)) 420 newID, err := ReadIndexDefinition(mkBuf(data))
422 So(err, ShouldBeNil) 421 So(err, ShouldBeNil)
423 » » » So(newID, ShouldResemble, id) 422 » » » So(newID.Flip(), ShouldResemble, id.Normalize())
424 423
425 id.SortBy = append(id.SortBy, ds.IndexColumn{Property: " prop"}) 424 id.SortBy = append(id.SortBy, ds.IndexColumn{Property: " prop"})
426 » » » data = ToBytes(id) 425 » » » data = ToBytes(*id.PrepForIdxTable())
427 » » » So(string(data), ShouldStartWith, string(ds.IndexBuiltin QueryPrefix()))
428 newID, err = ReadIndexDefinition(mkBuf(data)) 426 newID, err = ReadIndexDefinition(mkBuf(data))
429 So(err, ShouldBeNil) 427 So(err, ShouldBeNil)
430 » » » So(newID, ShouldResemble, id) 428 » » » So(newID.Flip(), ShouldResemble, id.Normalize())
431 429
432 id.SortBy = append(id.SortBy, ds.IndexColumn{Property: " other", Direction: ds.DESCENDING}) 430 id.SortBy = append(id.SortBy, ds.IndexColumn{Property: " other", Direction: ds.DESCENDING})
433 id.Ancestor = true 431 id.Ancestor = true
434 » » » data = ToBytes(id) 432 » » » data = ToBytes(*id.PrepForIdxTable())
435 » » » So(string(data), ShouldStartWith, string(ds.IndexComplex QueryPrefix()))
436 newID, err = ReadIndexDefinition(mkBuf(data)) 433 newID, err = ReadIndexDefinition(mkBuf(data))
437 So(err, ShouldBeNil) 434 So(err, ShouldBeNil)
438 » » » So(newID, ShouldResemble, id) 435 » » » So(newID.Flip(), ShouldResemble, id.Normalize())
439 436
440 // invalid 437 // invalid
441 id.SortBy = append(id.SortBy, ds.IndexColumn{Property: " ", Direction: ds.DESCENDING}) 438 id.SortBy = append(id.SortBy, ds.IndexColumn{Property: " ", Direction: ds.DESCENDING})
442 » » » data = ToBytes(id) 439 » » » data = ToBytes(*id.PrepForIdxTable())
443 » » » So(string(data), ShouldStartWith, string(ds.IndexComplex QueryPrefix()))
444 newID, err = ReadIndexDefinition(mkBuf(data)) 440 newID, err = ReadIndexDefinition(mkBuf(data))
445 So(err, ShouldBeNil) 441 So(err, ShouldBeNil)
446 » » » So(newID, ShouldResemble, id) 442 » » » So(newID.Flip(), ShouldResemble, id.Normalize())
447 443
448 Convey("too many", func() { 444 Convey("too many", func() {
449 id := ds.IndexDefinition{Kind: "wat"} 445 id := ds.IndexDefinition{Kind: "wat"}
450 for i := 0; i < MaxIndexColumns+1; i++ { 446 for i := 0; i < MaxIndexColumns+1; i++ {
451 id.SortBy = append(id.SortBy, ds.IndexCo lumn{Property: "Hi", Direction: ds.ASCENDING}) 447 id.SortBy = append(id.SortBy, ds.IndexCo lumn{Property: "Hi", Direction: ds.ASCENDING})
452 } 448 }
453 » » » » data := ToBytes(id) 449 » » » » data := ToBytes(*id.PrepForIdxTable())
454 newID, err = ReadIndexDefinition(mkBuf(data)) 450 newID, err = ReadIndexDefinition(mkBuf(data))
455 So(err, ShouldErrLike, "over 64 sort orders") 451 So(err, ShouldErrLike, "over 64 sort orders")
456 }) 452 })
457 }) 453 })
458 }) 454 })
459 } 455 }
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