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

Unified Diff: go/src/infra/gae/libs/gae/properties_test.go

Issue 1227183003: Change RawDatastore to do less reflection. (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@move_dummy
Patch Set: rebase 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
Index: go/src/infra/gae/libs/gae/properties_test.go
diff --git a/go/src/infra/gae/libs/gae/properties_test.go b/go/src/infra/gae/libs/gae/properties_test.go
index 43aca9648111209e379dc30276cdc6154807e2e8..61a9ccd5e0bb86c5dfed4ba8a8923e4e9b50f248 100644
--- a/go/src/infra/gae/libs/gae/properties_test.go
+++ b/go/src/infra/gae/libs/gae/properties_test.go
@@ -29,8 +29,7 @@ func TestProperties(t *testing.T) {
So(pv.Type().String(), ShouldEqual, "DSPTNull")
})
Convey("set", func() {
- pv := DSProperty{}
- pv.SetValue(100, true)
+ pv := MkDSPropertyNI(100)
So(pv.Value(), ShouldHaveSameTypeAs, int64(100))
So(pv.Value(), ShouldEqual, 100)
So(pv.NoIndex(), ShouldBeTrue)
@@ -43,30 +42,26 @@ func TestProperties(t *testing.T) {
})
Convey("derived types", func() {
Convey("int", func() {
- pv := DSProperty{}
- pv.SetValue(myint(19), false)
+ pv := MkDSProperty(19)
So(pv.Value(), ShouldHaveSameTypeAs, int64(19))
So(pv.Value(), ShouldEqual, 19)
So(pv.NoIndex(), ShouldBeFalse)
So(pv.Type().String(), ShouldEqual, "DSPTInt")
})
Convey("bool (true)", func() {
- pv := DSProperty{}
- pv.SetValue(mybool(true), false)
+ pv := MkDSProperty(mybool(true))
So(pv.Value(), ShouldBeTrue)
So(pv.NoIndex(), ShouldBeFalse)
So(pv.Type().String(), ShouldEqual, "DSPTBoolTrue")
})
Convey("string", func() {
- pv := DSProperty{}
- pv.SetValue(mystring("sup"), false)
+ pv := MkDSProperty(mystring("sup"))
So(pv.Value(), ShouldEqual, "sup")
So(pv.NoIndex(), ShouldBeFalse)
So(pv.Type().String(), ShouldEqual, "DSPTString")
})
Convey("BSKey is distinquished", func() {
- pv := DSProperty{}
- pv.SetValue(BSKey("sup"), false)
+ pv := MkDSProperty(BSKey("sup"))
So(pv.Value(), ShouldEqual, BSKey("sup"))
So(pv.NoIndex(), ShouldBeFalse)
So(pv.Type().String(), ShouldEqual, "DSPTBlobKey")
@@ -139,27 +134,64 @@ func TestDSPropertyMapImpl(t *testing.T) {
Convey("DSPropertyMap load/save err conditions", t, func() {
Convey("nil", func() {
- pm := (*DSPropertyMap)(nil)
- _, err := pm.Load(nil)
+ pm := DSPropertyMap(nil)
+ err := pm.Load(nil)
+ So(err.Error(), ShouldContainSubstring, "nil DSPropertyMap")
+
+ _, err = pm.Save(false)
+ So(err.Error(), ShouldContainSubstring, "nil DSPropertyMap")
+
+ _, err = pm.GetMeta("foo")
So(err.Error(), ShouldContainSubstring, "nil DSPropertyMap")
- _, err = pm.Save()
+ err = pm.SetMeta("foo", "bar")
+ So(err.Error(), ShouldContainSubstring, "nil DSPropertyMap")
+
+ err = pm.Problem()
So(err.Error(), ShouldContainSubstring, "nil DSPropertyMap")
})
Convey("empty", func() {
pm := DSPropertyMap{}
- _, err := pm.Load(DSPropertyMap{"hello": {DSProperty{}}})
- So(err, ShouldBeNil)
- So(pm, ShouldResemble, DSPropertyMap{"hello": {DSProperty{}}})
-
- // it can also self-initialize
- pm = DSPropertyMap(nil)
- _, err = pm.Load(DSPropertyMap{"hello": {DSProperty{}}})
+ err := pm.Load(DSPropertyMap{"hello": {DSProperty{}}})
So(err, ShouldBeNil)
So(pm, ShouldResemble, DSPropertyMap{"hello": {DSProperty{}}})
- npm, _ := pm.Save()
+ npm, _ := pm.Save(false)
So(npm, ShouldResemble, pm)
})
+ Convey("meta", func() {
+ Convey("working", func() {
+ pm := DSPropertyMap{}
+ _, err := pm.GetMeta("foo")
+ So(err, ShouldEqual, ErrDSMetaFieldUnset)
+
+ err = pm.SetMeta("foo", 100)
+ So(err, ShouldBeNil)
+
+ v, err := pm.GetMeta("foo")
+ So(err, ShouldBeNil)
+ So(v, ShouldEqual, 100)
+
+ npm, err := pm.Save(false)
+ So(err, ShouldBeNil)
+ So(len(npm), ShouldEqual, 0)
+ })
+
+ Convey("errors", func() {
+ Convey("too many values", func() {
+ pm := DSPropertyMap{
+ "$bad": {MkDSProperty(100), MkDSProperty(200)},
+ }
+ _, err := pm.GetMeta("bad")
+ So(err.Error(), ShouldContainSubstring, "too many values")
+ })
+
+ Convey("weird value", func() {
+ pm := DSPropertyMap{}
+ err := pm.SetMeta("sup", complex(100, 20))
+ So(err.Error(), ShouldContainSubstring, "bad type")
+ })
+ })
+ })
})
}

Powered by Google App Engine
This is Rietveld 408576698