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

Unified Diff: go/src/infra/gae/libs/wrapper/brokenfeatures_test.go

Issue 1151473003: Better attempt at an appengine wrapper. (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: fix coverage numbers Created 5 years, 7 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 | « go/src/infra/gae/libs/wrapper/brokenfeatures.go ('k') | go/src/infra/gae/libs/wrapper/context.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: go/src/infra/gae/libs/wrapper/brokenfeatures_test.go
diff --git a/go/src/infra/gae/libs/wrapper/brokenfeatures_test.go b/go/src/infra/gae/libs/wrapper/brokenfeatures_test.go
new file mode 100644
index 0000000000000000000000000000000000000000..b7dd41b5a6a3976d4d8c70cd95f2203f10ca32d8
--- /dev/null
+++ b/go/src/infra/gae/libs/wrapper/brokenfeatures_test.go
@@ -0,0 +1,126 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package wrapper
+
+import (
+ "errors"
+ "fmt"
+ "sync"
+ "testing"
+
+ . "github.com/smartystreets/goconvey/convey"
+)
+
+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) Foo() (string, error) {
+ err := f.halp()
+ if err != nil {
+ return "", err
+ }
+ return "foo", nil
+}
+
+func (f *foo) Bar() (string, error) {
+ err := f.halp()
+ if err != nil {
+ return "", err
+ }
+ return "bar", nil
+}
+
+type override struct {
+ BrokenFeatures
+ totallyRekt bool
+}
+
+func (o *override) IsBroken() error {
+ if o.totallyRekt {
+ return fmt.Errorf("totallyRekt")
+ }
+ return o.BrokenFeatures.IsBroken()
+}
+
+func (o *override) Foo() error {
+ return o.IsBroken()
+}
+
+func TestBrokenFeatures(t *testing.T) {
+ e := errors.New("sup")
+ eCustom := fmt.Errorf("bad stuff happened")
+ f := foo{BrokenFeatures{DefaultError: e}}
+
+ Convey("BrokenFeatures", t, func() {
+ Convey("can break functions", func() {
+ s, err := f.Foo()
+ So(s, ShouldEqual, "foo")
+ So(err, ShouldBeNil)
+
+ f.BreakFeatures(nil, "Foo")
+ _, err = f.Foo()
+ So(err, ShouldEqual, e)
+
+ Convey("and unbreak them", func() {
+ f.UnbreakFeatures("Foo")
+ s, err = f.Foo()
+ So(s, ShouldEqual, "foo")
+ So(err, ShouldBeNil)
+ })
+
+ Convey("and breaking features doesn't break unrelated ones", func() {
+ s, err := f.Bar()
+ So(s, ShouldEqual, "bar")
+ So(err, ShouldBeNil)
+ })
+ })
+
+ Convey("Can override IsBroken too", func() {
+ o := &override{BrokenFeatures{DefaultError: e}, false}
+ Convey("Can break functions as normal", func() {
+ o.BreakFeatures(nil, "Foo")
+ So(o.Foo(), ShouldEqual, e)
+
+ Convey("but can also break them in a user defined way", func() {
+ o.totallyRekt = true
+ So(o.Foo().Error(), ShouldContainSubstring, "totallyRekt")
+ })
+ })
+ })
+
+ Convey("Not specifying a default gets you a generic error", func() {
+ f.BrokenFeatures.DefaultError = nil
+ f.BreakFeatures(nil, "Foo")
+ _, err := f.Foo()
+ So(err.Error(), ShouldContainSubstring, `"Foo"`)
+ })
+
+ Convey("Can override the error returned", func() {
+ f.BreakFeatures(eCustom, "Foo")
+ v, err := f.Foo()
+ So(v, ShouldEqual, "")
+ So(err, ShouldEqual, eCustom)
+ })
+
+ Convey("Can be broken if not embedded", func(c C) {
+ var wg sync.WaitGroup
+ wg.Add(1)
+ go func() {
+ defer wg.Done()
+ bf := BrokenFeatures{DefaultError: e}
+ // 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)
+ }()
+ wg.Wait()
+ })
+ })
+}
« no previous file with comments | « go/src/infra/gae/libs/wrapper/brokenfeatures.go ('k') | go/src/infra/gae/libs/wrapper/context.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698