Index: service/datastore/pls_test.go |
diff --git a/service/datastore/pls_test.go b/service/datastore/pls_test.go |
index 92ebffcf0b4521a9b5bc4f3912a24e840aa59157..af1a595e795730f2498dc1afa96c7858e0dccd50 100644 |
--- a/service/datastore/pls_test.go |
+++ b/service/datastore/pls_test.go |
@@ -586,10 +586,6 @@ func (i *IDParser) GetMeta(key string) (interface{}, error) { |
return GetPLS(i).GetMeta(key) |
} |
-func (i *IDParser) GetMetaDefault(key string, dflt interface{}) interface{} { |
- return GetMetaDefaultImpl(i.GetMeta, key, dflt) |
-} |
- |
func (i *IDParser) SetMeta(key string, value interface{}) (err error) { |
if key == "id" { |
// let the panics flooowwww |
@@ -624,10 +620,6 @@ func (i *KindOverride) GetMeta(key string) (interface{}, error) { |
return GetPLS(i).GetMeta(key) |
} |
-func (i *KindOverride) GetMetaDefault(key string, dflt interface{}) interface{} { |
- return GetMetaDefaultImpl(i.GetMeta, key, dflt) |
-} |
- |
func (i *KindOverride) SetMeta(key string, value interface{}) error { |
if key == "kind" { |
kind := value.(string) |
@@ -1626,7 +1618,10 @@ func TestRoundTrip(t *testing.T) { |
for _, tc := range testCases { |
tc := tc |
Convey(tc.desc, func() { |
- pls, ok := tc.src.(PropertyLoadSaver) |
+ pls, ok := tc.src.(interface { |
+ PropertyLoadSaver |
+ Problem() error |
+ }) |
iannucci
2015/12/12 03:52:22
This silliness is because of the way the tests are
|
if !ok { |
pls = GetPLS(tc.src) |
} |
@@ -1647,7 +1642,10 @@ func TestRoundTrip(t *testing.T) { |
got = pls |
} else { |
got = reflect.New(reflect.TypeOf(tc.want).Elem()).Interface() |
- if pls, ok = got.(PropertyLoadSaver); !ok { |
+ if pls, ok = got.(interface { |
+ PropertyLoadSaver |
+ Problem() error |
+ }); !ok { |
pls = GetPLS(got) |
} |
} |
@@ -1692,9 +1690,17 @@ func TestMeta(t *testing.T) { |
So(err, ShouldBeNil) |
So(val, ShouldEqual, "whatnow") |
- So(mgs.GetMetaDefault("kind", "zappo"), ShouldEqual, "whatnow") |
- So(mgs.GetMetaDefault("id", "stringID"), ShouldEqual, "stringID") |
- So(mgs.GetMetaDefault("id", 6), ShouldEqual, 100) |
+ v, err := GetMetaDefault(mgs, "kind", "zappo") |
+ So(err, ShouldBeNil) |
+ So(v, ShouldEqual, "whatnow") |
+ |
+ v, err = GetMetaDefault(mgs, "id", "stringID") |
+ So(err, ShouldBeNil) |
+ So(v, ShouldEqual, "stringID") |
+ |
+ v, err = GetMetaDefault(mgs, "id", 6) |
+ So(err, ShouldBeNil) |
+ So(v, ShouldEqual, 100) |
}) |
Convey("Getting something not there is an error", func() { |
@@ -1707,7 +1713,9 @@ func TestMeta(t *testing.T) { |
Convey("Default works for missing fields", func() { |
o := &N0{ID: 100} |
mgs := getMGS(o) |
- So(mgs.GetMetaDefault("whozit", 10), ShouldEqual, 10) |
+ v, err := GetMetaDefault(mgs, "whozit", 10) |
+ So(err, ShouldBeNil) |
+ So(v, ShouldEqual, 10) |
}) |
Convey("getting/setting from a bad struct is an error", func() { |
@@ -1720,10 +1728,11 @@ func TestMeta(t *testing.T) { |
So(err, ShouldNotBeNil) |
}) |
- Convey("Default works for bad structs", func() { |
+ Convey("Default fails for bad structs", func() { |
o := &Recursive{} |
mgs := getMGS(o) |
- So(mgs.GetMetaDefault("whozit", 10), ShouldEqual, 10) |
+ _, err := GetMetaDefault(mgs, "whozit", 10) |
+ So(err, ShouldErrLike, `field "R" is recursively defined`) |
}) |
Convey("can assign values to exported meta fields", func() { |
@@ -1739,7 +1748,7 @@ func TestMeta(t *testing.T) { |
o := &N0{ID: 100} |
mgs := getMGS(o) |
err := mgs.SetMeta("kind", "hi") |
- So(err.Error(), ShouldContainSubstring, "unexported field") |
+ So(err, ShouldErrLike, "unexported field") |
err = mgs.SetMeta("noob", "hi") |
So(err, ShouldEqual, ErrMetaFieldUnset) |
@@ -1830,7 +1839,7 @@ func TestMeta(t *testing.T) { |
Bad Toggle `gae:"$wut"` |
} |
pls := GetPLS(&BadToggle{}) |
- So(pls.Problem().Error(), ShouldContainSubstring, "bad/missing default") |
+ So(pls.Problem(), ShouldErrLike, "bad/missing default") |
}) |
}) |
@@ -1914,14 +1923,19 @@ func TestMeta(t *testing.T) { |
Val time.Time `gae:"$meta,tomorrow"` |
} |
pls := GetPLS(&BadDefault{}) |
- So(pls.Problem().Error(), ShouldContainSubstring, "bad type") |
+ So(pls.Problem(), ShouldErrLike, "bad type") |
}) |
Convey("MetaGetterSetter implementation (IDParser)", func() { |
idp := &IDParser{parent: "moo", id: 100} |
mgs := getMGS(idp) |
- So(mgs.GetMetaDefault("id", ""), ShouldEqual, "moo|100") |
- So(mgs.GetMetaDefault("kind", ""), ShouldEqual, "CoolKind") |
+ v, err := GetMetaDefault(mgs, "id", "") |
+ So(err, ShouldBeNil) |
+ So(v, ShouldEqual, "moo|100") |
+ |
+ v, err = GetMetaDefault(mgs, "kind", "") |
+ So(err, ShouldBeNil) |
+ So(v, ShouldEqual, "CoolKind") |
So(mgs.SetMeta("kind", "Something"), ShouldErrLike, "unexported field") |
So(mgs.SetMeta("id", "happy|27"), ShouldBeNil) |
@@ -1938,10 +1952,14 @@ func TestMeta(t *testing.T) { |
Convey("MetaGetterSetter implementation (KindOverride)", func() { |
ko := &KindOverride{ID: 20} |
mgs := getMGS(ko) |
- So(mgs.GetMetaDefault("kind", ""), ShouldEqual, "KindOverride") |
+ v, err := GetMetaDefault(mgs, "kind", "") |
+ So(err, ShouldBeNil) |
+ So(v, ShouldEqual, "KindOverride") |
ko.customKind = "something" |
- So(mgs.GetMetaDefault("kind", ""), ShouldEqual, "something") |
+ v, err = GetMetaDefault(mgs, "kind", "") |
+ So(err, ShouldBeNil) |
+ So(v, ShouldEqual, "something") |
So(mgs.SetMeta("kind", "Nerp"), ShouldBeNil) |
So(ko.customKind, ShouldEqual, "Nerp") |