-
Notifications
You must be signed in to change notification settings - Fork 4
/
apply_func_var_seq_test.go
72 lines (65 loc) · 2.02 KB
/
apply_func_var_seq_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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package test
import (
. "github.com/agiledragon/gomonkey"
. "github.com/smartystreets/goconvey/convey"
"testing"
"github.com/agiledragon/gomonkey/test/fake"
)
func TestApplyFuncVarSeq(t *testing.T) {
Convey("TestApplyFuncVarSeq", t, func() {
Convey("default times is 1", func() {
info1 := "hello cpp"
info2 := "hello golang"
info3 := "hello gomonkey"
outputs := []OutputCell{
{Values: Params{[]byte(info1), nil}},
{Values: Params{[]byte(info2), nil}},
{Values: Params{[]byte(info3), nil}},
}
patches := ApplyFuncVarSeq(&fake.Marshal, outputs)
defer patches.Reset()
bytes, err := fake.Marshal("")
So(err, ShouldEqual, nil)
So(string(bytes), ShouldEqual, info1)
bytes, err = fake.Marshal("")
So(err, ShouldEqual, nil)
So(string(bytes), ShouldEqual, info2)
bytes, err = fake.Marshal("")
So(err, ShouldEqual, nil)
So(string(bytes), ShouldEqual, info3)
})
Convey("retry succ util the third times", func() {
info1 := "hello cpp"
outputs := []OutputCell{
{Values: Params{[]byte(""), fake.ErrActual}, Times: 2},
{Values: Params{[]byte(info1), nil}},
}
patches := ApplyFuncVarSeq(&fake.Marshal, outputs)
defer patches.Reset()
bytes, err := fake.Marshal("")
So(err, ShouldEqual, fake.ErrActual)
bytes, err = fake.Marshal("")
So(err, ShouldEqual, fake.ErrActual)
bytes, err = fake.Marshal("")
So(err, ShouldEqual, nil)
So(string(bytes), ShouldEqual, info1)
})
Convey("batch operations failed on the third time", func() {
info1 := "hello gomonkey"
outputs := []OutputCell{
{Values: Params{[]byte(info1), nil}, Times: 2},
{Values: Params{[]byte(""), fake.ErrActual}},
}
patches := ApplyFuncVarSeq(&fake.Marshal, outputs)
defer patches.Reset()
bytes, err := fake.Marshal("")
So(err, ShouldEqual, nil)
So(string(bytes), ShouldEqual, info1)
bytes, err = fake.Marshal("")
So(err, ShouldEqual, nil)
So(string(bytes), ShouldEqual, info1)
bytes, err = fake.Marshal("")
So(err, ShouldEqual, fake.ErrActual)
})
})
}