agiledragon / gomonkey

gomonkey is a library to make monkey patching in unit tests easy
MIT License
2k stars 179 forks source link

ApplyMethod invalid one case #117

Open YouSec995 opened 1 year ago

YouSec995 commented 1 year ago

i find a question :

type Outside struct {
  *Inner
}
type Inner struct {
}

func (gthis *Outside)MethodOut(){
  //...
  gthis.MethodInner()
}

func (gthis *Inner)MethodInner(){

}

if you

var p *Outside
p1 := gomonkey.ApplyMethod(reflect.TypeOf(p), "MethodInner",    func()  {
    fmt.Printf("applymethod succ")
    return 
}). // it will be invalid

but

var p *Inner
p1 := gomonkey.ApplyMethod(reflect.TypeOf(p), "MethodInner", func()  {
    fmt.Printf("applymethod succ")
    return 
}). // it will be valid