OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 package wrapper |
| 6 |
| 7 import ( |
| 8 "fmt" |
| 9 "testing" |
| 10 |
| 11 . "github.com/smartystreets/goconvey/convey" |
| 12 ) |
| 13 |
| 14 type foo struct { |
| 15 *BrokenFeatures |
| 16 } |
| 17 |
| 18 func (f *foo) Foo() (string, error) { |
| 19 err := f.IsBroken() |
| 20 if err != nil { |
| 21 return "", err |
| 22 } |
| 23 return "foo", nil |
| 24 } |
| 25 |
| 26 func (f *foo) Bar() (string, error) { |
| 27 err := f.IsBroken() |
| 28 if err != nil { |
| 29 return "", err |
| 30 } |
| 31 return "bar", nil |
| 32 } |
| 33 |
| 34 type override struct { |
| 35 *BrokenFeatures |
| 36 totallyRekt bool |
| 37 } |
| 38 |
| 39 func (o *override) IsBroken() error { |
| 40 if o.totallyRekt { |
| 41 return fmt.Errorf("totallyRekt") |
| 42 } |
| 43 return o.BrokenFeatures.IsBroken() |
| 44 } |
| 45 |
| 46 func (o *override) Foo() error { |
| 47 return o.IsBroken() |
| 48 } |
| 49 |
| 50 func TestTestable(t *testing.T) { |
| 51 e := fmt.Errorf("sup") |
| 52 f := foo{NewBrokenFeatures(e)} |
| 53 |
| 54 Convey("Testable", t, func() { |
| 55 Convey("can break functions", func() { |
| 56 s, err := f.Foo() |
| 57 So(s, ShouldEqual, "foo") |
| 58 So(err, ShouldBeNil) |
| 59 |
| 60 f.SetBrokenFeatures("Foo") |
| 61 _, err = f.Foo() |
| 62 So(err, ShouldEqual, e) |
| 63 |
| 64 Convey("and unbreak them", func() { |
| 65 f.UnsetBrokenFeatures("Foo") |
| 66 s, err = f.Foo() |
| 67 So(s, ShouldEqual, "foo") |
| 68 So(err, ShouldBeNil) |
| 69 }) |
| 70 |
| 71 Convey("and breaking features doesn't break unrelated on
es", func() { |
| 72 s, err := f.Bar() |
| 73 So(s, ShouldEqual, "bar") |
| 74 So(err, ShouldBeNil) |
| 75 }) |
| 76 }) |
| 77 |
| 78 Convey("Can override IsBroken too", func() { |
| 79 o := &override{NewBrokenFeatures(e), false} |
| 80 Convey("Can break functions as normal", func() { |
| 81 o.SetBrokenFeatures("Foo") |
| 82 So(o.Foo(), ShouldEqual, e) |
| 83 |
| 84 Convey("but can also break them in a user define
d way", func() { |
| 85 o.totallyRekt = true |
| 86 So(o.Foo().Error(), ShouldContainSubstri
ng, "totallyRekt") |
| 87 }) |
| 88 }) |
| 89 }) |
| 90 }) |
| 91 } |
OLD | NEW |