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

Unified Diff: service/rawdatastore/properties_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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « service/rawdatastore/properties.go ('k') | service/rawdatastore/reflect.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: service/rawdatastore/properties_test.go
diff --git a/properties_test.go b/service/rawdatastore/properties_test.go
similarity index 67%
rename from properties_test.go
rename to service/rawdatastore/properties_test.go
index 5d9d5568b84c8517efbad7b16b99b923489a6050..c6b5f149706752cbc90d1289328bab5983a42b14 100644
--- a/properties_test.go
+++ b/service/rawdatastore/properties_test.go
@@ -2,13 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-package gae
+package rawdatastore
import (
"math"
"testing"
"time"
+ "github.com/luci/gae/service/blobstore"
. "github.com/smartystreets/goconvey/convey"
)
@@ -20,79 +21,79 @@ type myfloat float32
func TestProperties(t *testing.T) {
t.Parallel()
- Convey("Test DSProperty", t, func() {
+ Convey("Test Property", t, func() {
Convey("Construction", func() {
Convey("empty", func() {
- pv := DSProperty{}
+ pv := Property{}
So(pv.Value(), ShouldBeNil)
So(pv.IndexSetting(), ShouldEqual, ShouldIndex)
- So(pv.Type().String(), ShouldEqual, "DSPTNull")
+ So(pv.Type().String(), ShouldEqual, "PTNull")
})
Convey("set", func() {
- pv := MkDSPropertyNI(100)
+ pv := MkPropertyNI(100)
So(pv.Value(), ShouldHaveSameTypeAs, int64(100))
So(pv.Value(), ShouldEqual, 100)
So(pv.IndexSetting(), ShouldEqual, NoIndex)
- So(pv.Type().String(), ShouldEqual, "DSPTInt")
+ So(pv.Type().String(), ShouldEqual, "PTInt")
pv.SetValue(nil, ShouldIndex)
So(pv.Value(), ShouldBeNil)
So(pv.IndexSetting(), ShouldEqual, ShouldIndex)
- So(pv.Type().String(), ShouldEqual, "DSPTNull")
+ So(pv.Type().String(), ShouldEqual, "PTNull")
})
Convey("derived types", func() {
Convey("int", func() {
- pv := MkDSProperty(19)
+ pv := MkProperty(19)
So(pv.Value(), ShouldHaveSameTypeAs, int64(19))
So(pv.Value(), ShouldEqual, 19)
So(pv.IndexSetting(), ShouldEqual, ShouldIndex)
- So(pv.Type().String(), ShouldEqual, "DSPTInt")
+ So(pv.Type().String(), ShouldEqual, "PTInt")
})
Convey("bool (true)", func() {
- pv := MkDSProperty(mybool(true))
+ pv := MkProperty(mybool(true))
So(pv.Value(), ShouldBeTrue)
So(pv.IndexSetting(), ShouldEqual, ShouldIndex)
- So(pv.Type().String(), ShouldEqual, "DSPTBoolTrue")
+ So(pv.Type().String(), ShouldEqual, "PTBoolTrue")
})
Convey("string", func() {
- pv := MkDSProperty(mystring("sup"))
+ pv := MkProperty(mystring("sup"))
So(pv.Value(), ShouldEqual, "sup")
So(pv.IndexSetting(), ShouldEqual, ShouldIndex)
- So(pv.Type().String(), ShouldEqual, "DSPTString")
+ So(pv.Type().String(), ShouldEqual, "PTString")
})
- Convey("BSKey is distinquished", func() {
- pv := MkDSProperty(BSKey("sup"))
- So(pv.Value(), ShouldEqual, BSKey("sup"))
+ Convey("blobstore.Key is distinquished", func() {
+ pv := MkProperty(blobstore.Key("sup"))
+ So(pv.Value(), ShouldEqual, blobstore.Key("sup"))
So(pv.IndexSetting(), ShouldEqual, ShouldIndex)
- So(pv.Type().String(), ShouldEqual, "DSPTBlobKey")
+ So(pv.Type().String(), ShouldEqual, "PTBlobKey")
})
Convey("float", func() {
- pv := DSProperty{}
+ pv := Property{}
pv.SetValue(myfloat(19.7), ShouldIndex)
So(pv.Value(), ShouldHaveSameTypeAs, float64(19.7))
So(pv.Value(), ShouldEqual, float32(19.7))
So(pv.IndexSetting(), ShouldEqual, ShouldIndex)
- So(pv.Type().String(), ShouldEqual, "DSPTFloat")
+ So(pv.Type().String(), ShouldEqual, "PTFloat")
})
})
Convey("bad type", func() {
- pv := DSProperty{}
+ pv := Property{}
err := pv.SetValue(complex(100, 29), ShouldIndex)
So(err.Error(), ShouldContainSubstring, "has bad type complex")
So(pv.Value(), ShouldBeNil)
So(pv.IndexSetting(), ShouldEqual, ShouldIndex)
- So(pv.Type().String(), ShouldEqual, "DSPTNull")
+ So(pv.Type().String(), ShouldEqual, "PTNull")
})
Convey("invalid GeoPoint", func() {
- pv := DSProperty{}
- err := pv.SetValue(DSGeoPoint{-1000, 0}, ShouldIndex)
+ pv := Property{}
+ err := pv.SetValue(GeoPoint{-1000, 0}, ShouldIndex)
So(err.Error(), ShouldContainSubstring, "invalid GeoPoint value")
So(pv.Value(), ShouldBeNil)
So(pv.IndexSetting(), ShouldEqual, ShouldIndex)
- So(pv.Type().String(), ShouldEqual, "DSPTNull")
+ So(pv.Type().String(), ShouldEqual, "PTNull")
})
Convey("invalid time", func() {
- pv := DSProperty{}
+ pv := Property{}
err := pv.SetValue(time.Now(), ShouldIndex)
So(err.Error(), ShouldContainSubstring, "time value has wrong Location")
@@ -100,30 +101,30 @@ func TestProperties(t *testing.T) {
So(err.Error(), ShouldContainSubstring, "time value out of range")
So(pv.Value(), ShouldBeNil)
So(pv.IndexSetting(), ShouldEqual, ShouldIndex)
- So(pv.Type().String(), ShouldEqual, "DSPTNull")
+ So(pv.Type().String(), ShouldEqual, "PTNull")
})
Convey("time gets rounded", func() {
- pv := DSProperty{}
+ pv := Property{}
now := time.Now().In(time.UTC)
now = now.Round(time.Microsecond).Add(time.Nanosecond * 313)
pv.SetValue(now, ShouldIndex)
So(pv.Value(), ShouldHappenBefore, now)
So(pv.IndexSetting(), ShouldEqual, ShouldIndex)
- So(pv.Type().String(), ShouldEqual, "DSPTTime")
+ So(pv.Type().String(), ShouldEqual, "PTTime")
})
Convey("[]byte coerces IndexSetting", func() {
- pv := DSProperty{}
+ pv := Property{}
pv.SetValue([]byte("hello"), ShouldIndex)
So(pv.Value(), ShouldResemble, []byte("hello"))
So(pv.IndexSetting(), ShouldEqual, NoIndex)
- So(pv.Type().String(), ShouldEqual, "DSPTBytes")
+ So(pv.Type().String(), ShouldEqual, "PTBytes")
})
Convey("ByteString allows !IndexSetting", func() {
- pv := DSProperty{}
- pv.SetValue(DSByteString("hello"), ShouldIndex)
- So(pv.Value(), ShouldResemble, DSByteString("hello"))
+ pv := Property{}
+ pv.SetValue(ByteString("hello"), ShouldIndex)
+ So(pv.Value(), ShouldResemble, ByteString("hello"))
So(pv.IndexSetting(), ShouldEqual, ShouldIndex)
- So(pv.Type().String(), ShouldEqual, "DSPTBytes")
+ So(pv.Type().String(), ShouldEqual, "PTBytes")
})
})
})
@@ -132,21 +133,21 @@ func TestProperties(t *testing.T) {
func TestDSPropertyMapImpl(t *testing.T) {
t.Parallel()
- Convey("DSPropertyMap load/save err conditions", t, func() {
+ Convey("PropertyMap load/save err conditions", t, func() {
Convey("empty", func() {
- pm := DSPropertyMap{}
- err := pm.Load(DSPropertyMap{"hello": {DSProperty{}}})
+ pm := PropertyMap{}
+ err := pm.Load(PropertyMap{"hello": {Property{}}})
So(err, ShouldBeNil)
- So(pm, ShouldResemble, DSPropertyMap{"hello": {DSProperty{}}})
+ So(pm, ShouldResemble, PropertyMap{"hello": {Property{}}})
npm, _ := pm.Save(false)
So(npm, ShouldResemble, pm)
})
Convey("meta", func() {
Convey("working", func() {
- pm := DSPropertyMap{"": {MkDSProperty("trap!")}}
+ pm := PropertyMap{"": {MkProperty("trap!")}}
_, err := pm.GetMeta("foo")
- So(err, ShouldEqual, ErrDSMetaFieldUnset)
+ So(err, ShouldEqual, ErrMetaFieldUnset)
err = pm.SetMeta("foo", 100)
So(err, ShouldBeNil)
@@ -162,15 +163,15 @@ func TestDSPropertyMapImpl(t *testing.T) {
Convey("errors", func() {
Convey("too many values", func() {
- pm := DSPropertyMap{
- "$bad": {MkDSProperty(100), MkDSProperty(200)},
+ pm := PropertyMap{
+ "$bad": {MkProperty(100), MkProperty(200)},
}
_, err := pm.GetMeta("bad")
So(err.Error(), ShouldContainSubstring, "too many values")
})
Convey("weird value", func() {
- pm := DSPropertyMap{}
+ pm := PropertyMap{}
err := pm.SetMeta("sup", complex(100, 20))
So(err.Error(), ShouldContainSubstring, "bad type")
})
« no previous file with comments | « service/rawdatastore/properties.go ('k') | service/rawdatastore/reflect.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698