agiledragon / gomonkey

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

Not reset after call `Reset` | 调用 Reset 没有重置 #62

Closed youthlin closed 3 years ago

youthlin commented 3 years ago
func MyFun() int {
    return 1
}

func TestMock(t *testing.T) {
    Convey("mock", t, func() {
        p := gomonkey.ApplyFunc(MyFun, func() int { return 11 })
        i := MyFun()
        So(i, ShouldEqual, 11) // ok
        p.Reset()
        i = MyFun()
        So(i, ShouldEqual, 1)// fails, got 11
    })
}

调用 Reset 方法后,还是走了打桩逻辑,而没有调用原来的函数? Reset 不是还原的含义吗,那需要怎么还原呢? (may be similar to https://github.com/agiledragon/gomonkey/issues/21)

youthlin commented 3 years ago

我的锅,没问题