bytedance / mockey

a simple and easy-to-use golang mock library
Apache License 2.0
556 stars 22 forks source link

feat: support get private member method #36

Closed smallchimney closed 8 months ago

smallchimney commented 9 months ago

What type of PR is this?

feat: A new feature

What this PR does / why we need it (en: English/zh: Chinese):

en: 1. We need to mock some method even if it's not exported, like (*sha256.digest).checksum or other method; 2. We need some helper function to migrate gomonkey.ApplyPrivateMethod. zh: 1. 某些场景下我们需要Mock私有方法,比如(*sha256.digest).checksum;2. 我们需要一个辅助函数去实现从gomonkey.ApplyPrivateMethod的代码实现迁移。

smallchimney commented 9 months ago

Is there any possible to upgrade GetPrivateMethod to generic function in place?

smallchimney commented 9 months ago

I've tryed to resolve function type from reflect information, but saddly the type info of private methods have not been written for reflect package

smallchimney commented 9 months ago

btw, the branch develop described in CONTRIBUTION.md is not exist yet.

smallchimney commented 9 months ago

add the missing license decriptions

ycydsxy commented 9 months ago

Good job. But some tests failed ...

Sychorius commented 9 months ago

Try put generics-required code into another .go file with compile option like this:

//go:build go1.18
// +build go1.18
smallchimney commented 9 months ago

The CI testing is failed with Go1.13, which reflect.Pointer has not been declared, I changed to use reflect.Ptr for the compatibility

ycydsxy commented 8 months ago

some tests still failed

smallchimney commented 8 months ago

fixed, I've tried go1.13, 1.16, 1.17, 1.18, 1.19 and 1.20 on my dev env.