I want to use etcd to test my program, and I need a mock etcd (used it in my unit test). However, I'm confused that which API I should use. After I read the document of the etcd, I found that there may be two options for me.
Can anyone give me some advice? Thanks.
use testify library to create mock of KV, TXN,WATCHER ....etc
etcdFn: func() *clientv3.Client {
resp := &clientv3.GetResponse{}
kv := &mocks.KV{}
kv.On("Get", mock.Anything, "/leader").Return(resp, nil)
return &clientv3.Client{KV: kv}
}
like this to mock etcd client @wjhuang2016
Hi, @dongzerun.
Thank you for your reply, however, it's not convenient to use the testify library. I want to do many operations like put, get, and watch. It's tough to mock every response. What I need is an etcd cluster that behaves like real etcd cluster and providing some functionality and good performance.
unit test shouldn't rely on thirdpart services, testify is enough for your case
This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 21 days if no further activity occurs. Thank you for your contributions.
Most helpful comment
use testify library to create mock of KV, TXN,WATCHER ....etc
like this to mock etcd client @wjhuang2016