agiledragon / gomonkey

gomonkey is a library to make monkey patching in unit tests easy
MIT License
1.92k stars 178 forks source link

ApplyFuncVar和ApplyFunc有什么区别? #135

Open kaifeng666 opened 1 year ago

kaifeng666 commented 1 year ago

Convey("for succ", func() { str := "hello" patches := ApplyFuncVar(&fake.Marshal, func (_ interface{}) ([]byte, error) { return []byte(str), nil }) defer patches.Reset() bytes, err := fake.Marshal(nil) So(err, ShouldEqual, nil) So(string(bytes), ShouldEqual, str) })

ApplyFuncVar替换为ApplyFunc不也是同样的效果?

xhd2015 commented 3 months ago

Seems confusing, why not try xgo instead? https://github.com/xhd2015/xgo