Index: service/rawdatastore/serialize_test.go |
diff --git a/helper/serialize_test.go b/service/rawdatastore/serialize_test.go |
similarity index 62% |
rename from helper/serialize_test.go |
rename to service/rawdatastore/serialize_test.go |
index ea941df6b3ae5f948802f25a84446de20345c496..0d97419b19874f1a110c50fa8e57408ccaaa94df 100644 |
--- a/helper/serialize_test.go |
+++ b/service/rawdatastore/serialize_test.go |
@@ -2,7 +2,7 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-package helper |
+package rawdatastore |
import ( |
"bytes" |
@@ -10,55 +10,55 @@ import ( |
"testing" |
"time" |
- "github.com/luci/gae" |
+ "github.com/luci/gae/service/blobstore" |
"github.com/luci/luci-go/common/cmpbin" |
. "github.com/smartystreets/goconvey/convey" |
) |
func init() { |
- WriteDSPropertyMapDeterministic = true |
+ WritePropertyMapDeterministic = true |
} |
type dspmapTC struct { |
name string |
- props gae.DSPropertyMap |
+ props PropertyMap |
} |
-func TestDSPropertyMapSerialization(t *testing.T) { |
+func TestPropertyMapSerialization(t *testing.T) { |
t.Parallel() |
tests := []dspmapTC{ |
{ |
"basic", |
- gae.DSPropertyMap{ |
+ PropertyMap{ |
"R": {mp(false), mp(2.1), mpNI(3)}, |
"S": {mp("hello"), mp("world")}, |
}, |
}, |
{ |
"keys", |
- gae.DSPropertyMap{ |
- "DS": {mp(mkKey("appy", "ns", "Foo", 7)), mp(mkKey("other", "", "Yot", "wheeep"))}, |
- "BS": {mp(gae.BSKey("sup")), mp(gae.BSKey("nerds"))}, |
+ PropertyMap{ |
+ "DS": {mp(mkKey("appy", "ns", "Foo", 7)), mp(mkKey("other", "", "Yot", "wheeep"))}, |
+ "blobstore": {mp(blobstore.Key("sup")), mp(blobstore.Key("nerds"))}, |
}, |
}, |
{ |
"geo", |
- gae.DSPropertyMap{ |
- "G": {mp(gae.DSGeoPoint{Lat: 1, Lng: 2})}, |
+ PropertyMap{ |
+ "G": {mp(GeoPoint{Lat: 1, Lng: 2})}, |
}, |
}, |
{ |
"data", |
- gae.DSPropertyMap{ |
+ PropertyMap{ |
"S": {mp("sup"), mp("fool"), mp("nerd")}, |
"D.Foo.Nerd": {mp([]byte("sup")), mp([]byte("fool"))}, |
- "B": {mp(gae.DSByteString("sup")), mp(gae.DSByteString("fool"))}, |
+ "B": {mp(ByteString("sup")), mp(ByteString("fool"))}, |
}, |
}, |
{ |
"time", |
- gae.DSPropertyMap{ |
+ PropertyMap{ |
"T": { |
mp(time.Now().UTC()), |
mp(time.Now().Add(time.Second).UTC())}, |
@@ -66,7 +66,7 @@ func TestDSPropertyMapSerialization(t *testing.T) { |
}, |
{ |
"empty vals", |
- gae.DSPropertyMap{ |
+ PropertyMap{ |
"T": {mp(true), mp(true)}, |
"F": {mp(false), mp(false)}, |
"N": {mp(nil), mp(nil)}, |
@@ -75,14 +75,14 @@ func TestDSPropertyMapSerialization(t *testing.T) { |
}, |
} |
- Convey("DSPropertyMap serialization", t, func() { |
+ Convey("PropertyMap serialization", t, func() { |
Convey("round trip", func() { |
for _, tc := range tests { |
tc := tc |
Convey(tc.name, func() { |
buf := &bytes.Buffer{} |
- WriteDSPropertyMap(buf, tc.props, WithContext) |
- dec, err := ReadDSPropertyMap(buf, WithContext, "", "") |
+ WritePropertyMap(buf, tc.props, WithContext) |
+ dec, err := ReadPropertyMap(buf, WithContext, "", "") |
So(err, ShouldBeNil) |
So(dec, ShouldResemble, tc.props) |
}) |
@@ -95,37 +95,34 @@ func TestSerializationReadMisc(t *testing.T) { |
t.Parallel() |
Convey("Misc Serialization tests", t, func() { |
- Convey("ReadDSKey", func() { |
+ buf := &bytes.Buffer{} |
+ Convey("ReadKey", func() { |
Convey("good cases", func() { |
Convey("w/ ctx decodes normally w/ ctx", func() { |
k := mkKey("aid", "ns", "knd", "yo", "other", 10) |
- buf := &bytes.Buffer{} |
- WriteDSKey(buf, WithContext, k) |
- dk, err := ReadDSKey(buf, WithContext, "", "") |
+ WriteKey(buf, WithContext, k) |
+ dk, err := ReadKey(buf, WithContext, "", "") |
So(err, ShouldBeNil) |
So(dk, ShouldEqualKey, k) |
}) |
Convey("w/ ctx decodes normally w/o ctx", func() { |
k := mkKey("aid", "ns", "knd", "yo", "other", 10) |
- buf := &bytes.Buffer{} |
- WriteDSKey(buf, WithContext, k) |
- dk, err := ReadDSKey(buf, WithoutContext, "spam", "nerd") |
+ WriteKey(buf, WithContext, k) |
+ dk, err := ReadKey(buf, WithoutContext, "spam", "nerd") |
So(err, ShouldBeNil) |
So(dk, ShouldEqualKey, mkKey("spam", "nerd", "knd", "yo", "other", 10)) |
}) |
Convey("w/o ctx decodes normally w/ ctx", func() { |
k := mkKey("aid", "ns", "knd", "yo", "other", 10) |
- buf := &bytes.Buffer{} |
- WriteDSKey(buf, WithoutContext, k) |
- dk, err := ReadDSKey(buf, WithContext, "spam", "nerd") |
+ WriteKey(buf, WithoutContext, k) |
+ dk, err := ReadKey(buf, WithContext, "spam", "nerd") |
So(err, ShouldBeNil) |
So(dk, ShouldEqualKey, mkKey("", "", "knd", "yo", "other", 10)) |
}) |
Convey("w/o ctx decodes normally w/o ctx", func() { |
k := mkKey("aid", "ns", "knd", "yo", "other", 10) |
- buf := &bytes.Buffer{} |
- WriteDSKey(buf, WithoutContext, k) |
- dk, err := ReadDSKey(buf, WithoutContext, "spam", "nerd") |
+ WriteKey(buf, WithoutContext, k) |
+ dk, err := ReadKey(buf, WithoutContext, "spam", "nerd") |
So(err, ShouldBeNil) |
So(dk, ShouldEqualKey, mkKey("spam", "nerd", "knd", "yo", "other", 10)) |
}) |
@@ -133,12 +130,11 @@ func TestSerializationReadMisc(t *testing.T) { |
// -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) |
+ WriteKey(buf, WithoutContext, k) |
k = mkKey("aid", "ns", "knd", "hat") |
buf2 := &bytes.Buffer{} |
- WriteDSKey(buf2, WithoutContext, k) |
+ WriteKey(buf2, WithoutContext, k) |
So(bytes.Compare(buf.Bytes(), buf2.Bytes()), ShouldBeLessThan, 0) |
}) |
@@ -146,126 +142,111 @@ func TestSerializationReadMisc(t *testing.T) { |
Convey("err cases", func() { |
Convey("nil", func() { |
- buf := &bytes.Buffer{} |
- _, err := ReadDSKey(buf, WithContext, "", "") |
+ _, err := ReadKey(buf, WithContext, "", "") |
So(err, ShouldEqual, io.EOF) |
}) |
Convey("str", func() { |
- buf := &bytes.Buffer{} |
buf.WriteString("sup") |
- _, err := ReadDSKey(buf, WithContext, "", "") |
+ _, err := ReadKey(buf, WithContext, "", "") |
So(err, ShouldErrLike, "expected actualCtx") |
}) |
Convey("truncated 1", func() { |
- buf := &bytes.Buffer{} |
buf.WriteByte(1) // actualCtx == 1 |
- _, err := ReadDSKey(buf, WithContext, "", "") |
+ _, err := ReadKey(buf, WithContext, "", "") |
So(err, ShouldEqual, io.EOF) |
}) |
Convey("truncated 2", func() { |
- buf := &bytes.Buffer{} |
buf.WriteByte(1) // actualCtx == 1 |
cmpbin.WriteString(buf, "aid") |
- _, err := ReadDSKey(buf, WithContext, "", "") |
+ _, err := ReadKey(buf, WithContext, "", "") |
So(err, ShouldEqual, io.EOF) |
}) |
Convey("truncated 3", func() { |
- buf := &bytes.Buffer{} |
buf.WriteByte(1) // actualCtx == 1 |
cmpbin.WriteString(buf, "aid") |
cmpbin.WriteString(buf, "ns") |
- _, err := ReadDSKey(buf, WithContext, "", "") |
+ _, err := ReadKey(buf, WithContext, "", "") |
So(err, ShouldEqual, io.EOF) |
}) |
Convey("huge key", func() { |
- buf := &bytes.Buffer{} |
buf.WriteByte(1) // actualCtx == 1 |
cmpbin.WriteString(buf, "aid") |
cmpbin.WriteString(buf, "ns") |
cmpbin.WriteUint(buf, 1000) |
- _, err := ReadDSKey(buf, WithContext, "", "") |
+ _, err := ReadKey(buf, WithContext, "", "") |
So(err, ShouldErrLike, "huge key") |
}) |
Convey("insufficient tokens", func() { |
- buf := &bytes.Buffer{} |
buf.WriteByte(1) // actualCtx == 1 |
cmpbin.WriteString(buf, "aid") |
cmpbin.WriteString(buf, "ns") |
cmpbin.WriteUint(buf, 2) |
- _, err := ReadDSKey(buf, WithContext, "", "") |
+ _, err := ReadKey(buf, WithContext, "", "") |
So(err, ShouldEqual, io.EOF) |
}) |
Convey("partial token 1", 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") |
- _, err := ReadDSKey(buf, WithContext, "", "") |
+ _, err := ReadKey(buf, WithContext, "", "") |
So(err, ShouldEqual, io.EOF) |
}) |
Convey("partial token 2", 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.DSPTString)) |
- _, err := ReadDSKey(buf, WithContext, "", "") |
+ buf.WriteByte(byte(PTString)) |
+ _, err := ReadKey(buf, WithContext, "", "") |
So(err, ShouldEqual, io.EOF) |
}) |
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") |
+ buf.WriteByte(byte(PTBlobKey)) |
+ _, err := ReadKey(buf, WithContext, "", "") |
+ So(err, ShouldErrLike, "invalid type PTBlobKey") |
}) |
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") |
- buf.WriteByte(byte(gae.DSPTInt)) |
+ buf.WriteByte(byte(PTInt)) |
cmpbin.WriteInt(buf, -2) |
- _, err := ReadDSKey(buf, WithContext, "", "") |
+ _, err := ReadKey(buf, WithContext, "", "") |
So(err, ShouldErrLike, "zero/negative") |
}) |
}) |
}) |
- Convey("ReadDSGeoPoint", func() { |
+ Convey("ReadGeoPoint", func() { |
Convey("trunc 1", func() { |
- buf := &bytes.Buffer{} |
- _, err := ReadDSGeoPoint(buf) |
+ _, err := ReadGeoPoint(buf) |
So(err, ShouldEqual, io.EOF) |
}) |
Convey("trunc 2", func() { |
- buf := &bytes.Buffer{} |
cmpbin.WriteFloat64(buf, 100) |
- _, err := ReadDSGeoPoint(buf) |
+ _, err := ReadGeoPoint(buf) |
So(err, ShouldEqual, io.EOF) |
}) |
Convey("invalid", func() { |
- buf := &bytes.Buffer{} |
cmpbin.WriteFloat64(buf, 100) |
cmpbin.WriteFloat64(buf, 1000) |
- _, err := ReadDSGeoPoint(buf) |
- So(err, ShouldErrLike, "invalid DSGeoPoint") |
+ _, err := ReadGeoPoint(buf) |
+ So(err, ShouldErrLike, "invalid GeoPoint") |
}) |
}) |
Convey("WriteTime", func() { |
Convey("in non-UTC!", func() { |
- buf := &bytes.Buffer{} |
pst, err := time.LoadLocation("America/Los_Angeles") |
So(err, ShouldBeNil) |
So(func() { |
@@ -276,77 +257,66 @@ func TestSerializationReadMisc(t *testing.T) { |
Convey("ReadTime", func() { |
Convey("trunc 1", func() { |
- buf := &bytes.Buffer{} |
_, err := ReadTime(buf) |
So(err, ShouldEqual, io.EOF) |
}) |
}) |
- Convey("ReadDSProperty", func() { |
+ Convey("ReadProperty", func() { |
Convey("trunc 1", func() { |
- buf := &bytes.Buffer{} |
- _, err := ReadDSProperty(buf, WithContext, "", "") |
+ _, err := ReadProperty(buf, WithContext, "", "") |
So(err, ShouldEqual, io.EOF) |
}) |
- Convey("trunc (DSPTBytes)", func() { |
- buf := &bytes.Buffer{} |
- buf.WriteByte(byte(gae.DSPTBytes)) |
- _, err := ReadDSProperty(buf, WithContext, "", "") |
+ Convey("trunc (PTBytes)", func() { |
+ buf.WriteByte(byte(PTBytes)) |
+ _, err := ReadProperty(buf, WithContext, "", "") |
So(err, ShouldEqual, io.EOF) |
}) |
- Convey("trunc (DSPTBlobKey)", func() { |
- buf := &bytes.Buffer{} |
- buf.WriteByte(byte(gae.DSPTBlobKey)) |
- _, err := ReadDSProperty(buf, WithContext, "", "") |
+ Convey("trunc (PTBlobKey)", func() { |
+ buf.WriteByte(byte(PTBlobKey)) |
+ _, err := ReadProperty(buf, WithContext, "", "") |
So(err, ShouldEqual, io.EOF) |
}) |
Convey("invalid type", func() { |
- buf := &bytes.Buffer{} |
- buf.WriteByte(byte(gae.DSPTUnknown + 1)) |
- _, err := ReadDSProperty(buf, WithContext, "", "") |
+ buf.WriteByte(byte(PTUnknown + 1)) |
+ _, err := ReadProperty(buf, WithContext, "", "") |
So(err, ShouldErrLike, "unknown type!") |
}) |
}) |
- Convey("ReadDSPropertyMap", func() { |
+ Convey("ReadPropertyMap", func() { |
Convey("trunc 1", func() { |
- buf := &bytes.Buffer{} |
- _, err := ReadDSPropertyMap(buf, WithContext, "", "") |
+ _, err := ReadPropertyMap(buf, WithContext, "", "") |
So(err, ShouldEqual, io.EOF) |
}) |
Convey("too many rows", func() { |
- buf := &bytes.Buffer{} |
cmpbin.WriteUint(buf, 1000000) |
- _, err := ReadDSPropertyMap(buf, WithContext, "", "") |
+ _, err := ReadPropertyMap(buf, WithContext, "", "") |
So(err, ShouldErrLike, "huge number of rows") |
}) |
Convey("trunc 2", func() { |
- buf := &bytes.Buffer{} |
cmpbin.WriteUint(buf, 10) |
- _, err := ReadDSPropertyMap(buf, WithContext, "", "") |
+ _, err := ReadPropertyMap(buf, WithContext, "", "") |
So(err, ShouldEqual, io.EOF) |
}) |
Convey("trunc 3", func() { |
- buf := &bytes.Buffer{} |
cmpbin.WriteUint(buf, 10) |
cmpbin.WriteString(buf, "ohai") |
- _, err := ReadDSPropertyMap(buf, WithContext, "", "") |
+ _, err := ReadPropertyMap(buf, WithContext, "", "") |
So(err, ShouldEqual, io.EOF) |
}) |
Convey("too many values", func() { |
- buf := &bytes.Buffer{} |
cmpbin.WriteUint(buf, 10) |
cmpbin.WriteString(buf, "ohai") |
cmpbin.WriteUint(buf, 100000) |
- _, err := ReadDSPropertyMap(buf, WithContext, "", "") |
+ _, err := ReadPropertyMap(buf, WithContext, "", "") |
So(err, ShouldErrLike, "huge number of properties") |
}) |
Convey("trunc 4", func() { |
- buf := &bytes.Buffer{} |
cmpbin.WriteUint(buf, 10) |
cmpbin.WriteString(buf, "ohai") |
cmpbin.WriteUint(buf, 10) |
- _, err := ReadDSPropertyMap(buf, WithContext, "", "") |
+ _, err := ReadPropertyMap(buf, WithContext, "", "") |
So(err, ShouldEqual, io.EOF) |
}) |
}) |