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

Unified Diff: filter/featureBreaker/featurebreaker_test.go

Issue 1253263002: Make rawdatastore API safer for writing filters. (Closed) Base URL: https://github.com/luci/gae.git@master
Patch Set: fix comments 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
« no previous file with comments | « filter/count/rds.go ('k') | filter/featureBreaker/rds.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: filter/featureBreaker/featurebreaker_test.go
diff --git a/filter/featureBreaker/featurebreaker_test.go b/filter/featureBreaker/featurebreaker_test.go
index 241e12896daa12f48bf25c247d027f7456c9ff04..491edceb47360796a2bac2e3f0d43906510a4485 100644
--- a/filter/featureBreaker/featurebreaker_test.go
+++ b/filter/featureBreaker/featurebreaker_test.go
@@ -5,15 +5,13 @@
package featureBreaker
import (
- "errors"
"testing"
- "golang.org/x/net/context"
-
"github.com/luci/gae/impl/memory"
"github.com/luci/gae/service/rawdatastore"
-
+ "github.com/luci/luci-go/common/errors"
. "github.com/smartystreets/goconvey/convey"
+ "golang.org/x/net/context"
)
func TestBrokenFeatures(t *testing.T) {
@@ -21,6 +19,14 @@ func TestBrokenFeatures(t *testing.T) {
e := errors.New("default err")
+ cbe := func(expect string) func(rawdatastore.PropertyMap, error) {
+ return func(_ rawdatastore.PropertyMap, err error) {
+ So(err.Error(), ShouldContainSubstring, expect)
+ }
+ }
+
+ cbn := func(rawdatastore.PropertyMap, error) {}
+
Convey("BrokenFeatures", t, func() {
c := memory.Use(context.Background())
@@ -28,33 +34,39 @@ func TestBrokenFeatures(t *testing.T) {
Convey("without a default", func() {
c, bf := FilterRDS(c, nil)
rds := rawdatastore.Get(c)
+ keys := []rawdatastore.Key{rds.NewKey("Wut", "", 1, nil)}
Convey("by specifying an error", func() {
- bf.BreakFeatures(e, "Get", "Put")
- So(rds.Get(nil, nil), ShouldEqual, e)
+ bf.BreakFeatures(e, "GetMulti", "PutMulti")
+ So(rds.GetMulti(keys, cbn), ShouldEqual, e)
Convey("and you can unbreak them as well", func() {
- bf.UnbreakFeatures("Get")
- So(rds.Get(nil, nil), ShouldEqual, rawdatastore.ErrInvalidKey)
+ bf.UnbreakFeatures("GetMulti")
+
+ err := rds.GetMulti(keys, cbe(rawdatastore.ErrNoSuchEntity.Error()))
+ So(err, ShouldBeNil)
Convey("no broken features at all is a shortcut", func() {
- bf.UnbreakFeatures("Put")
- So(rds.Get(nil, nil), ShouldEqual, rawdatastore.ErrInvalidKey)
+ bf.UnbreakFeatures("PutMulti")
+ err := rds.GetMulti(keys, cbe(rawdatastore.ErrNoSuchEntity.Error()))
+ So(err, ShouldBeNil)
})
})
})
Convey("Not specifying an error gets you a generic error", func() {
- bf.BreakFeatures(nil, "Get")
- So(rds.Get(nil, nil).Error(), ShouldEqual, `feature "Get" is broken`)
+ bf.BreakFeatures(nil, "GetMulti")
+ err := rds.GetMulti(keys, cbn)
+ So(err.Error(), ShouldContainSubstring, `feature "GetMulti" is broken`)
})
})
Convey("with a default", func() {
c, bf := FilterRDS(c, e)
rds := rawdatastore.Get(c)
- bf.BreakFeatures(nil, "Get")
- So(rds.Get(nil, nil), ShouldEqual, e)
+ keys := []rawdatastore.Key{rds.NewKey("Wut", "", 1, nil)}
+ bf.BreakFeatures(nil, "GetMulti")
+ So(rds.GetMulti(keys, cbn), ShouldEqual, e)
})
})
})
« no previous file with comments | « filter/count/rds.go ('k') | filter/featureBreaker/rds.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698