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

Unified Diff: service/datastore/pls_test.go

Issue 1270113002: Re-add metadata passthrough on Get operations (Closed) Base URL: https://github.com/luci/gae.git@fix_other_interfaces
Patch Set: cleanup Created 5 years, 4 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/datastore/pls_impl.go ('k') | service/datastore/properties.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: service/datastore/pls_test.go
diff --git a/service/datastore/pls_test.go b/service/datastore/pls_test.go
index a39571a51759994216cb6f5a598caece1d5f5a84..959226af5ae02cadc8717f4aad79d4d6edc03e8b 100644
--- a/service/datastore/pls_test.go
+++ b/service/datastore/pls_test.go
@@ -337,7 +337,7 @@ type MismatchTypes struct {
IS []int
}
-type BadSpecial struct {
+type BadMeta struct {
ID int64 `gae:"$id"`
id string `gae:"$id"`
}
@@ -375,9 +375,10 @@ func (d *Doubler) Save(withMeta bool) (PropertyMap, error) {
return propMap, nil
}
-func (d *Doubler) GetMeta(string) (interface{}, error) { return nil, ErrMetaFieldUnset }
-func (d *Doubler) SetMeta(string, interface{}) error { return ErrMetaFieldUnset }
-func (d *Doubler) Problem() error { return nil }
+func (d *Doubler) GetMeta(string) (interface{}, error) { return nil, ErrMetaFieldUnset }
+func (d *Doubler) GetMetaDefault(_ string, dflt interface{}) interface{} { return dflt }
+func (d *Doubler) SetMeta(string, interface{}) error { return ErrMetaFieldUnset }
+func (d *Doubler) Problem() error { return nil }
var _ PropertyLoadSaver = (*Doubler)(nil)
@@ -402,9 +403,10 @@ func (d *Deriver) Save(withMeta bool) (PropertyMap, error) {
}, nil
}
-func (d *Deriver) GetMeta(string) (interface{}, error) { return nil, ErrMetaFieldUnset }
-func (d *Deriver) SetMeta(string, interface{}) error { return ErrMetaFieldUnset }
-func (d *Deriver) Problem() error { return nil }
+func (d *Deriver) GetMeta(string) (interface{}, error) { return nil, ErrMetaFieldUnset }
+func (d *Deriver) GetMetaDefault(_ string, dflt interface{}) interface{} { return dflt }
+func (d *Deriver) SetMeta(string, interface{}) error { return ErrMetaFieldUnset }
+func (d *Deriver) Problem() error { return nil }
var _ PropertyLoadSaver = (*Deriver)(nil)
@@ -1564,10 +1566,10 @@ func TestRoundTrip(t *testing.T) {
})
}
-func TestSpecial(t *testing.T) {
+func TestMeta(t *testing.T) {
t.Parallel()
- Convey("Test special fields", t, func() {
+ Convey("Test meta fields", t, func() {
Convey("Can retrieve from struct", func() {
o := &N0{ID: 100}
pls := GetPLS(o)
@@ -1578,6 +1580,10 @@ func TestSpecial(t *testing.T) {
val, err = pls.GetMeta("kind")
So(err, ShouldBeNil)
So(val, ShouldEqual, "whatnow")
+
+ So(pls.GetMetaDefault("kind", "zappo"), ShouldEqual, "whatnow")
+ So(pls.GetMetaDefault("id", "stringID"), ShouldEqual, "stringID")
+ So(pls.GetMetaDefault("id", 6), ShouldEqual, 100)
})
Convey("Getting something not there is an error", func() {
@@ -1587,6 +1593,12 @@ func TestSpecial(t *testing.T) {
So(err, ShouldEqual, ErrMetaFieldUnset)
})
+ Convey("Default works for missing fields", func() {
+ o := &N0{ID: 100}
+ pls := GetPLS(o)
+ So(pls.GetMetaDefault("whozit", 10), ShouldEqual, 10)
+ })
+
Convey("getting/setting from a bad struct is an error", func() {
o := &Recursive{}
pls := GetPLS(o)
@@ -1597,7 +1609,13 @@ func TestSpecial(t *testing.T) {
So(err, ShouldNotBeNil)
})
- Convey("can assign values to exported special fields", func() {
+ Convey("Default works for bad structs", func() {
+ o := &Recursive{}
+ pls := GetPLS(o)
+ So(pls.GetMetaDefault("whozit", 10), ShouldEqual, 10)
+ })
+
+ Convey("can assign values to exported meta fields", func() {
o := &N0{ID: 100}
pls := GetPLS(o)
err := pls.SetMeta("id", int64(200))
@@ -1619,7 +1637,7 @@ func TestSpecial(t *testing.T) {
Convey("StructPLS Miscellaneous", t, func() {
Convey("multiple overlapping fields is an error", func() {
- o := &BadSpecial{}
+ o := &BadMeta{}
pls := GetPLS(o)
err := pls.Load(nil)
So(err, ShouldErrLike, "multiple times")
« no previous file with comments | « service/datastore/pls_impl.go ('k') | service/datastore/properties.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698