github.com/agiledragon/gomonkey/v2@v2.11.1-0.20240427155748-d56c6823ec17/test/dsl_test/func_dsl_test.go (about) 1 package dsltest 2 3 import ( 4 "testing" 5 6 . "github.com/agiledragon/gomonkey/v2/test/fake" 7 8 . "github.com/agiledragon/gomonkey/v2" 9 . "github.com/agiledragon/gomonkey/v2/dsl" 10 . "github.com/smartystreets/goconvey/convey" 11 ) 12 13 func TestPbBuilderFunc(t *testing.T) { 14 Convey("TestPbBuilderFunc", t, func() { 15 16 Convey("first dsl", func() { 17 patches := NewPatches() 18 defer patches.Reset() 19 patchBuilder := NewPatchBuilder(patches) 20 21 patchBuilder. 22 Func(Belong). 23 Stubs(). 24 With(Eq("zxl"), Any()). 25 Will(Return(true)). 26 Then(Repeat(Return(false), 2)). 27 End() 28 29 flag := Belong("zxl", []string{}) 30 So(flag, ShouldBeTrue) 31 32 defer func() { 33 if p := recover(); p != nil { 34 str, ok := p.(string) 35 So(ok, ShouldBeTrue) 36 So(str, ShouldEqual, "input paras ddd is not matched") 37 } 38 }() 39 Belong("ddd", []string{"abc"}) 40 }) 41 42 }) 43 }