agiledragon / gomonkey

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

为elastic.NewClient打桩失败 #16

Closed chengdanhao closed 4 years ago

chengdanhao commented 4 years ago

有个函数需要调用 oliver 库创建 elasticsearch client,使用下面方法

patches := gomonkey.ApplyFunc(elastic.NewClient,
    func(options ...elastic.ClientOptionFunc) (*elastic.Client, error) {
        t.Log("client MOCK >>>>>>>>>>>>>")
        return nil, fmt.Errorf("someerr")
    })
defer patches.Reset()

执行时,发现打印并没有出现。

chengdanhao commented 4 years ago

-gcflags=-l 取消内联即可