github.com/agiledragon/gomonkey/v2@v2.11.1-0.20240427155748-d56c6823ec17/test/apply_global_var_test.go (about) 1 package test 2 3 import ( 4 "testing" 5 6 . "github.com/agiledragon/gomonkey/v2" 7 . "github.com/smartystreets/goconvey/convey" 8 ) 9 10 var num = 10 11 12 func TestApplyGlobalVar(t *testing.T) { 13 Convey("TestApplyGlobalVar", t, func() { 14 15 Convey("change", func() { 16 patches := ApplyGlobalVar(&num, 150) 17 defer patches.Reset() 18 So(num, ShouldEqual, 150) 19 }) 20 21 Convey("recover", func() { 22 So(num, ShouldEqual, 10) 23 }) 24 }) 25 }