Skip to content
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

Merged
merged 4 commits into from
May 8, 2024
Merged

feat: restore PatchInstanceMethod #20

merged 4 commits into from
May 8, 2024

Conversation

samanhappy
Copy link
Contributor

Resolve #19

@taoso
Copy link
Member

taoso commented May 7, 2024

功能没问题,麻烦补一个测试用例

monkey.go Outdated
panic(fmt.Sprintf("unknown method %s", methodName))
}

o := &opt{}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

此处可能有问题。monkey 默认开启协程隔离,原来的 PatchInstanceMethod 函数是全局 patch 吧?需要指定 global 参数。

Copy link
Contributor Author

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"))
Copy link
Member

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。

@samanhappy
Copy link
Contributor Author

看起来 macos-latest runner 开始使用 arm64 架构的版本了,但是代码还不支持,所以测试失败了

@taoso
Copy link
Member

taoso commented May 7, 2024

修好了 #21 rebase master 分支试试

@taoso taoso merged commit d037952 into go-kiss:master May 8, 2024
15 checks passed
@samanhappy samanhappy deleted the patch branch May 15, 2024 11:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

能否恢复 PatchInstanceMethod 函数
2 participants