bytedance / mockey

a simple and easy-to-use golang mock library
Apache License 2.0
556 stars 22 forks source link

feat: support mocking struct functional filed #12

Closed Sychorius closed 1 year ago

Sychorius commented 1 year ago

support mocking struct functional filed

What type of PR is this?

feat: support mocking struct functional filed

What this PR does / why we need it (en: English/zh: Chinese):

en: support mocking struct functional field zh: 支持mock结构体内函数类的成员变量指向的函数

eg:

type Fn func()
type Foo struct {
    privateField Fn
}

func NewFoo() *Foo { return &Foo{privateField: func() { /*anonymous function, do nothing*/ }} }
var foo interface{} = NewFoo()

we can mock Foo.privateField as below:

Mock(GetMethod(foo,"privateField"))