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

Unified Diff: service/datastore/properties_test.go

Issue 1516173002: Fix error message from KeyForObj when passing an invalid struct. (Closed) Base URL: https://github.com/luci/gae.git@master
Patch Set: remove accidental extra test Created 5 years 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: service/datastore/properties_test.go
diff --git a/service/datastore/properties_test.go b/service/datastore/properties_test.go
index f814d435f39119ae4d989e5532cfc85ff41aa23b..2dc8851fd3f3e8156feeb4b34a18d3b2e10e881c 100644
--- a/service/datastore/properties_test.go
+++ b/service/datastore/properties_test.go
@@ -143,36 +143,38 @@ func TestDSPropertyMapImpl(t *testing.T) {
Convey("meta", func() {
Convey("working", func() {
pm := PropertyMap{"": {MkProperty("trap!")}}
- _, err := pm.GetMeta("foo")
- So(err, ShouldEqual, ErrMetaFieldUnset)
+ _, ok := pm.GetMeta("foo")
+ So(ok, ShouldBeFalse)
- err = pm.SetMeta("foo", 100)
- So(err, ShouldBeNil)
+ So(pm.SetMeta("foo", 100), ShouldBeTrue)
- v, err := pm.GetMeta("foo")
- So(err, ShouldBeNil)
+ v, ok := pm.GetMeta("foo")
+ So(ok, ShouldBeTrue)
So(v, ShouldEqual, 100)
- So(pm.GetMetaDefault("foo", 100), ShouldEqual, 100)
- So(pm.GetMetaDefault("bar", 100), ShouldEqual, 100)
+
+ So(GetMetaDefault(pm, "foo", 100), ShouldEqual, 100)
+
+ So(GetMetaDefault(pm, "bar", 100), ShouldEqual, 100)
npm, err := pm.Save(false)
So(err, ShouldBeNil)
So(len(npm), ShouldEqual, 0)
})
+ Convey("too many values picks the first one", func() {
+ pm := PropertyMap{
+ "$thing": {MkProperty(100), MkProperty(200)},
+ }
+ v, ok := pm.GetMeta("thing")
+ So(ok, ShouldBeTrue)
+ So(v, ShouldEqual, 100)
+ })
+
Convey("errors", func() {
- Convey("too many values", func() {
- pm := PropertyMap{
- "$bad": {MkProperty(100), MkProperty(200)},
- }
- _, err := pm.GetMeta("bad")
- So(err.Error(), ShouldContainSubstring, "too many values")
- })
Convey("weird value", func() {
pm := PropertyMap{}
- err := pm.SetMeta("sup", complex(100, 20))
- So(err.Error(), ShouldContainSubstring, "bad type")
+ So(pm.SetMeta("sup", complex(100, 20)), ShouldBeFalse)
})
})
})

Powered by Google App Engine
This is Rietveld 408576698