agiledragon / gomonkey

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

go1.18 support #84

Closed zhongyuanjia closed 2 years ago

zhongyuanjia commented 2 years ago

hello, has any plan for 1.18 support?

agiledragon commented 2 years ago

private method? Other features are independent of go version.

zhongyuanjia commented 2 years ago

yep, I currently use the following method instead of the ApplyPrivateMethod

type Patch struct {}

func (*Patch) method() int { return 1 }
func (Patch) method2() int { return 1 }

patches = gomonkey.NewPatches()
defer patches.Reset()
patches.ApplyFunc((*Patch).method, func() { return 2 })
patches.ApplyFunc(Patch.method2, func() { return 3 })

It works fine on go1.18, but it can only be used inside packages

agiledragon commented 2 years ago

I think it will be supported next month!

zhongyuanjia commented 2 years ago

I look forward to it. thanks a lot

agiledragon commented 2 years ago

fully support private method in the v2.7.0 @metauro

zhongyuanjia commented 2 years ago

nice, thanks a lot again