github.com/agiledragon/gomonkey/v2@v2.11.1-0.20240427155748-d56c6823ec17/test/apply_func_return_test.go (about) 1 package test 2 3 import ( 4 "testing" 5 6 . "github.com/agiledragon/gomonkey/v2" 7 "github.com/agiledragon/gomonkey/v2/test/fake" 8 . "github.com/smartystreets/goconvey/convey" 9 ) 10 11 /* 12 compare with apply_func_seq_test.go 13 */ 14 func TestApplyFuncReturn(t *testing.T) { 15 Convey("TestApplyFuncReturn", t, func() { 16 17 Convey("declares the values to be returned", func() { 18 info1 := "hello cpp" 19 20 patches := ApplyFuncReturn(fake.ReadLeaf, info1, nil) 21 defer patches.Reset() 22 23 for i := 0; i < 10; i++ { 24 output, err := fake.ReadLeaf("") 25 So(err, ShouldEqual, nil) 26 So(output, ShouldEqual, info1) 27 } 28 29 patches.Reset() // if not reset will occur:patch has been existed 30 info2 := "hello golang" 31 patches.ApplyFuncReturn(fake.ReadLeaf, info2, nil) 32 for i := 0; i < 10; i++ { 33 output, err := fake.ReadLeaf("") 34 So(err, ShouldEqual, nil) 35 So(output, ShouldEqual, info2) 36 } 37 }) 38 }) 39 }