| Index: go/src/infra/gae/libs/gae/brokenfeatures_test.go
|
| diff --git a/go/src/infra/gae/libs/wrapper/brokenfeatures_test.go b/go/src/infra/gae/libs/gae/brokenfeatures_test.go
|
| similarity index 77%
|
| rename from go/src/infra/gae/libs/wrapper/brokenfeatures_test.go
|
| rename to go/src/infra/gae/libs/gae/brokenfeatures_test.go
|
| index b7dd41b5a6a3976d4d8c70cd95f2203f10ca32d8..1f1b1bf003fe313f4f89826d1bd1c46536adb520 100644
|
| --- a/go/src/infra/gae/libs/wrapper/brokenfeatures_test.go
|
| +++ b/go/src/infra/gae/libs/gae/brokenfeatures_test.go
|
| @@ -2,7 +2,7 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -package wrapper
|
| +package gae
|
|
|
| import (
|
| "errors"
|
| @@ -17,24 +17,25 @@ type foo struct {
|
| BrokenFeatures
|
| }
|
|
|
| -func (f *foo) halp() error { // test the ability to call IsBroken from an internal helper
|
| - return f.IsBroken()
|
| +func (f *foo) RunIfNotBroken(fn func() error) error {
|
| + // can 'override' RunIfNotBroken
|
| + return f.BrokenFeatures.RunIfNotBroken(fn)
|
| }
|
|
|
| -func (f *foo) Foo() (string, error) {
|
| - err := f.halp()
|
| - if err != nil {
|
| - return "", err
|
| - }
|
| - return "foo", nil
|
| +func (f *foo) Foo() (ret string, err error) {
|
| + err = f.RunIfNotBroken(func() error {
|
| + ret = "foo"
|
| + return nil
|
| + })
|
| + return
|
| }
|
|
|
| -func (f *foo) Bar() (string, error) {
|
| - err := f.halp()
|
| - if err != nil {
|
| - return "", err
|
| - }
|
| - return "bar", nil
|
| +func (f *foo) Bar() (ret string, err error) {
|
| + err = f.RunIfNotBroken(func() error {
|
| + ret = "bar"
|
| + return nil
|
| + })
|
| + return
|
| }
|
|
|
| type override struct {
|
| @@ -42,15 +43,15 @@ type override struct {
|
| totallyRekt bool
|
| }
|
|
|
| -func (o *override) IsBroken() error {
|
| +func (o *override) RunIfNotBroken(f func() error) error {
|
| if o.totallyRekt {
|
| return fmt.Errorf("totallyRekt")
|
| }
|
| - return o.BrokenFeatures.IsBroken()
|
| + return o.BrokenFeatures.RunIfNotBroken(f)
|
| }
|
|
|
| func (o *override) Foo() error {
|
| - return o.IsBroken()
|
| + return o.RunIfNotBroken(func() error { return nil })
|
| }
|
|
|
| func TestBrokenFeatures(t *testing.T) {
|
| @@ -118,7 +119,8 @@ func TestBrokenFeatures(t *testing.T) {
|
| // break some feature so we're forced to crawl the stack.
|
| bf.BreakFeatures(nil, "Nerds")
|
| // should break because there's no exported functions on the stack.
|
| - c.So(bf.IsBroken(), ShouldEqual, ErrBrokenFeaturesBroken)
|
| + err := bf.RunIfNotBroken(func() error { return nil })
|
| + c.So(err, ShouldEqual, ErrBrokenFeaturesBroken)
|
| }()
|
| wg.Wait()
|
| })
|
|
|