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

Unified Diff: service/datastore/datastore_test.go

Issue 1525873002: Panic when non-runtime-handleable type errors occur (Closed) Base URL: https://github.com/luci/gae.git@master
Patch Set: add 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
« no previous file with comments | « service/datastore/datastore.go ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: service/datastore/datastore_test.go
diff --git a/service/datastore/datastore_test.go b/service/datastore/datastore_test.go
index 1974ac5aacf607e7eade3cfc0d1cbdad9d01742c..3dcf68f4759f78a4a9d7b1ed6b55d3bc46a63e94 100644
--- a/service/datastore/datastore_test.go
+++ b/service/datastore/datastore_test.go
@@ -407,11 +407,13 @@ func TestPut(t *testing.T) {
Convey("put with non-modifyable type is an error", func() {
cs := CommonStruct{}
- So(ds.Put(cs), ShouldErrLike, "invalid Put input type")
+ So(func() { ds.Put(cs) }, ShouldPanicLike,
+ "invalid Put input type (datastore.CommonStruct): not a pointer")
})
Convey("get with *Key is an error", func() {
- So(ds.Get(&Key{}), ShouldErrLike, "invalid Get input type: *datastore.Key")
+ So(func() { ds.Get(&Key{}) }, ShouldPanicLike,
+ "invalid Get input type (*datastore.Key): not user datatype")
})
Convey("struct with no $kind is an error", func() {
@@ -652,7 +654,19 @@ func TestGet(t *testing.T) {
Convey("get with non-modifiable type is an error", func() {
cs := CommonStruct{}
- So(ds.Get(cs), ShouldErrLike, "invalid Get input type")
+ So(func() { ds.Get(cs) }, ShouldPanicLike,
+ "invalid Get input type (datastore.CommonStruct): not a pointer")
+ })
+
+ Convey("get with nil is an error", func() {
+ So(func() { ds.Get(nil) }, ShouldPanicLike,
+ "invalid Get input type (<nil>): no type information")
+ })
+
+ Convey("get with ptr-to-nonstruct is an error", func() {
+ val := 100
+ So(func() { ds.Get(&val) }, ShouldPanicLike,
+ "invalid Get input type (*int): does not point to a struct")
})
Convey("failure to save metadata is no problem though", func() {
@@ -701,7 +715,8 @@ func TestGetAll(t *testing.T) {
Convey("bad", func() {
Convey("nil target", func() {
- So(ds.GetAll(q, (*[]PropertyMap)(nil)), ShouldErrLike, "dst: <nil>")
+ So(func() { ds.GetAll(q, (*[]PropertyMap)(nil)) }, ShouldPanicLike,
+ "invalid GetAll dst: <nil>")
})
Convey("bad type", func() {
@@ -711,12 +726,14 @@ func TestGetAll(t *testing.T) {
})
Convey("bad type (non pointer)", func() {
- So(ds.GetAll(q, "moo"), ShouldErrLike, "must have a ptr-to-slice")
+ So(func() { ds.GetAll(q, "moo") }, ShouldPanicLike,
+ "invalid GetAll dst: must have a ptr-to-slice")
})
Convey("bad type (underspecified)", func() {
output := []PropertyLoadSaver(nil)
- So(ds.GetAll(q, &output), ShouldErrLike, "invalid GetAll input type")
+ So(func() { ds.GetAll(q, &output) }, ShouldPanicLike,
+ "invalid GetAll dst (non-concrete element type): *[]datastore.PropertyLoadSaver")
})
})
« no previous file with comments | « service/datastore/datastore.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698