diff --git a/monkey.go b/monkey.go index 02dd2db..fb34153 100644 --- a/monkey.go +++ b/monkey.go @@ -64,7 +64,7 @@ func PatchInstanceMethod(target reflect.Type, methodName string, replacement int panic(fmt.Sprintf("unknown method %s", methodName)) } - o := &opt{} + o := &opt{global: true} r := reflect.ValueOf(replacement) patchValue(m.Func, r, o) return &PatchGuard{m.Func, r, o} diff --git a/monkey_test.go b/monkey_test.go index dbb28dc..10bc8b5 100644 --- a/monkey_test.go +++ b/monkey_test.go @@ -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")) assert(t, !i.No())