-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: restore PatchInstanceMethod #20
Conversation
功能没问题,麻烦补一个测试用例 |
monkey.go
Outdated
panic(fmt.Sprintf("unknown method %s", methodName)) | ||
} | ||
|
||
o := &opt{} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
此处可能有问题。monkey 默认开启协程隔离,原来的 PatchInstanceMethod 函数是全局 patch 吧?需要指定 global 参数。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
使用 global: true 测试会失败,我不太熟悉之前的代码,这个地方是不是不需要设置?
monkey_test.go
Outdated
@@ -90,7 +90,7 @@ func (f *f) No() bool { return false } | |||
func TestOnInstanceMethod(t *testing.T) { | |||
i := &f{} | |||
assert(t, !i.No()) | |||
monkey.Patch((*f).No, func(_ *f) bool { return true }) | |||
monkey.PatchInstanceMethod(reflect.TypeOf(i), "No", func(_ *f) bool { return true }) | |||
assert(t, i.No()) | |||
assert(t, monkey.UnpatchInstanceMethod(reflect.TypeOf(i), "No")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个 UnpatchInstanceMethod
有问题。PatchInstanceMethod
函数返回 guard 对象,调用其 Unpatch
函数来取消 mock。
看起来 macos-latest runner 开始使用 arm64 架构的版本了,但是代码还不支持,所以测试失败了 |
修好了 #21 rebase master 分支试试 |
Resolve #19