Closed studyzy closed 1 year ago
First of all, I recommend using the released version as much as possible. Secondly, we are implementing the private method in the main branch, and some of the problems we have encountered have not yet been resolved. Now that the test case has been skipped, let the test take effect after the feature is fully supported.
gomonkey has supported this feature in v2.3.1
gomonkey has supported this feature in v2.3.1
newest master branch code run:
go test -gcflags=all=-l apply_private_method_test.go -v
not work, still show error:
=== RUN TestApplyPrivateMethod
TestApplyPrivateMethod
patch private pointer method in the different package 🔥
patch private value method in the different package 🔥
Errors:
* /Users/devinzeng/go/src/github.com/agiledragon/gomonkey/test/apply_private_method_test.go
Line 17: - retrieve method by name failed
goroutine 4 [running]:
/Users/devinzeng/go/pkg/mod/github.com/smartystreets/goconvey@v1.6.4/convey/reporting/reports.go:148 +0x5c
/Users/devinzeng/go/pkg/mod/github.com/smartystreets/goconvey@v1.6.4/convey/reporting/reports.go:121 +0x70
/Users/devinzeng/go/pkg/mod/github.com/smartystreets/goconvey@v1.6.4/convey/context.go:235 +0x104
panic({0x1025fcb80, 0x102627dc0})
/usr/local/go/src/runtime/panic.go:1038 +0x224
github.com/agiledragon/gomonkey/v2.(*Patches).ApplyPrivateMethod(0x1400000c150, {0x10262da88, 0x10260c7a0}, {0x1025d3e07, 0x2}, {0x1025fefa0, 0x1026272d0})
/Users/devinzeng/go/src/github.com/agiledragon/gomonkey/patch.go:81 +0xa8
github.com/agiledragon/gomonkey/v2.ApplyPrivateMethod({0x10262da88, 0x10260c7a0}, {0x1025d3e07, 0x2}, {0x1025fefa0, 0x1026272d0})
/Users/devinzeng/go/src/github.com/agiledragon/gomonkey/patch.go:32 +0x54
command-line-arguments.TestApplyPrivateMethod.func1.1()
/Users/devinzeng/go/src/github.com/agiledragon/gomonkey/test/apply_private_method_test.go:17 +0x7c
What is your go version?
What is your go version?
go version go1.17 darwin/arm64
What is your go version?
go version go1.17 darwin/arm64
It turned out to be go1.17, which is exactly the same as I guessed. Please read the release notes carefully: https://github.com/agiledragon/gomonkey/releases At the same time, I also wrote an article before: https://www.jianshu.com/p/7546e788613b
go1.17 has not supported this feature temporarily, will be considered later.
Reference in
my go version is 1.16 linux/amd64,and i have installed the gomonkey 2.7.0. In the release notes, it say support the: go1.14 ok go1.15 ok go1.16 ok go1.17 ok go1.18 ok
but I also get the error panic: retrieve method by name failed [recovered]
different is: I use it for a public methods of private variables like this:
patch := gomonkey.ApplyMethod(reflect.TypeOf(opt.Para.customer), "Query", func()....)
.customer is the private variables
Reference in
my go version is 1.16 linux/amd64,and i have installed the gomonkey 2.7.0. In the release notes, it say support the: go1.14 ok go1.15 ok go1.16 ok go1.17 ok go1.18 ok
but I also get the error
panic: retrieve method by name failed [recovered]
different is: I use it for a public methods of private variables like this:
patch := gomonkey.ApplyMethod(reflect.TypeOf(opt.Para.customer), "Query", func()....)
.customer is the private variables
sorry, I just use it in a wrong way. it's ok now
官方例子:TestApplyPrivate,运行结果,报错:
环境是Mac M1, go version go1.17 darwin/arm64