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

Unified Diff: go/src/infra/gae/libs/gae/helper/serialize_test.go

Issue 1231863018: Fix DSKey encoding. (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: add test 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « go/src/infra/gae/libs/gae/helper/serialize.go ('k') | go/src/infra/gae/libs/gae/properties.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: go/src/infra/gae/libs/gae/helper/serialize_test.go
diff --git a/go/src/infra/gae/libs/gae/helper/serialize_test.go b/go/src/infra/gae/libs/gae/helper/serialize_test.go
index 17aae14bc4f095b3009f947ef87086be507ad4f6..15f06f21dbe17b0986177d267394a596bc3cb665 100644
--- a/go/src/infra/gae/libs/gae/helper/serialize_test.go
+++ b/go/src/infra/gae/libs/gae/helper/serialize_test.go
@@ -130,6 +130,19 @@ func TestSerializationReadMisc(t *testing.T) {
So(err, ShouldBeNil)
So(dk, ShouldEqualKey, mkKey("spam", "nerd", "knd", "yo", "other", 10))
})
+ Convey("IntIDs always sort before StringIDs", func() {
+ // -1 writes as almost all 1's in the first byte under cmpbin, even
+ // though it's technically not a valid key.
+ k := mkKey("aid", "ns", "knd", -1)
+ buf := &bytes.Buffer{}
+ WriteDSKey(buf, WithoutContext, k)
+
+ k = mkKey("aid", "ns", "knd", "hat")
+ buf2 := &bytes.Buffer{}
+ WriteDSKey(buf2, WithoutContext, k)
+
+ So(bytes.Compare(buf.Bytes(), buf2.Bytes()), ShouldBeLessThan, 0)
+ })
})
Convey("err cases", func() {
@@ -200,18 +213,29 @@ func TestSerializationReadMisc(t *testing.T) {
cmpbin.WriteString(buf, "ns")
cmpbin.WriteUint(buf, 2)
cmpbin.WriteString(buf, "hi")
- cmpbin.WriteString(buf, "")
+ buf.WriteByte(byte(gae.DSPTString))
_, err := ReadDSKey(buf, WithContext, "", "")
So(err, ShouldEqual, io.EOF)
})
- Convey("bad token", func() {
+ Convey("bad token (invalid type)", func() {
+ buf := &bytes.Buffer{}
+ buf.WriteByte(1) // actualCtx == 1
+ cmpbin.WriteString(buf, "aid")
+ cmpbin.WriteString(buf, "ns")
+ cmpbin.WriteUint(buf, 2)
+ cmpbin.WriteString(buf, "hi")
+ buf.WriteByte(byte(gae.DSPTBlobKey))
+ _, err := ReadDSKey(buf, WithContext, "", "")
+ So(err, ShouldErrLike, "invalid type DSPTBlobKey")
+ })
+ Convey("bad token (invalid IntID)", func() {
buf := &bytes.Buffer{}
buf.WriteByte(1) // actualCtx == 1
cmpbin.WriteString(buf, "aid")
cmpbin.WriteString(buf, "ns")
cmpbin.WriteUint(buf, 2)
cmpbin.WriteString(buf, "hi")
- cmpbin.WriteString(buf, "")
+ buf.WriteByte(byte(gae.DSPTInt))
cmpbin.WriteInt(buf, -2)
_, err := ReadDSKey(buf, WithContext, "", "")
So(err, ShouldErrLike, "zero/negative")
« no previous file with comments | « go/src/infra/gae/libs/gae/helper/serialize.go ('k') | go/src/infra/gae/libs/gae/properties.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698