-
Notifications
You must be signed in to change notification settings - Fork 4
/
apply_interface_reused_test.go
53 lines (48 loc) · 1.32 KB
/
apply_interface_reused_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package test
import (
. "github.com/agiledragon/gomonkey"
"github.com/agiledragon/gomonkey/test/fake"
. "github.com/smartystreets/goconvey/convey"
"reflect"
"testing"
)
func TestApplyInterfaceReused(t *testing.T) {
e := &fake.Etcd{}
Convey("TestApplyInterfaceReused", t, func() {
patches := ApplyFunc(fake.NewDb, func(_ string) fake.Db {
return e
})
defer patches.Reset()
db := fake.NewDb("mysql")
Convey("TestApplyInterface", func() {
info := "hello interface"
patches.ApplyMethod(reflect.TypeOf(e), "Retrieve",
func(_ *fake.Etcd, _ string) (string, error) {
return info, nil
})
output, err := db.Retrieve("")
So(err, ShouldEqual, nil)
So(output, ShouldEqual, info)
})
Convey("TestApplyInterfaceSeq", func() {
info1 := "hello cpp"
info2 := "hello golang"
info3 := "hello gomonkey"
outputs := []OutputCell{
{Values: Params{info1, nil}},
{Values: Params{info2, nil}},
{Values: Params{info3, nil}},
}
patches.ApplyMethodSeq(reflect.TypeOf(e), "Retrieve", outputs)
output, err := db.Retrieve("")
So(err, ShouldEqual, nil)
So(output, ShouldEqual, info1)
output, err = db.Retrieve("")
So(err, ShouldEqual, nil)
So(output, ShouldEqual, info2)
output, err = db.Retrieve("")
So(err, ShouldEqual, nil)
So(output, ShouldEqual, info3)
})
})
}