github.com/agiledragon/gomonkey/v2@v2.11.1-0.20240427155748-d56c6823ec17/test/apply_method_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_method_seq_test.go
    13  */
    14  
    15  func TestApplyMethodReturn(t *testing.T) {
    16  	e := &fake.Etcd{}
    17  	Convey("TestApplyMethodReturn", t, func() {
    18  		Convey("declares the values to be returned", func() {
    19  			info1 := "hello cpp"
    20  			patches := ApplyMethodReturn(e, "Retrieve", info1, nil)
    21  			defer patches.Reset()
    22  			for i := 0; i < 10; i++ {
    23  				output1, err1 := e.Retrieve("")
    24  				So(err1, ShouldEqual, nil)
    25  				So(output1, ShouldEqual, info1)
    26  			}
    27  
    28  			patches.Reset() // if not reset will occur:patch has been existed
    29  			info2 := "hello golang"
    30  			patches.ApplyMethodReturn(e, "Retrieve", info2, nil)
    31  			for i := 0; i < 10; i++ {
    32  				output2, err2 := e.Retrieve("")
    33  				So(err2, ShouldEqual, nil)
    34  				So(output2, ShouldEqual, info2)
    35  			}
    36  		})
    37  	})
    38  }