Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
samanhappy committed May 7, 2024
1 parent 6eb21be commit 67d8a47
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion monkey.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
4 changes: 2 additions & 2 deletions monkey_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ func (f *f) No() bool { return false }
func TestOnInstanceMethod(t *testing.T) {
i := &f{}
assert(t, !i.No())
monkey.PatchInstanceMethod(reflect.TypeOf(i), "No", func(_ *f) bool { return true })
pg := monkey.PatchInstanceMethod(reflect.TypeOf(i), "No", func(_ *f) bool { return true })
assert(t, i.No())
assert(t, monkey.UnpatchInstanceMethod(reflect.TypeOf(i), "No"))
pg.Unpatch()
assert(t, !i.No())
}

Expand Down

0 comments on commit 67d8a47

Please sign in to comment.