Skip to content
This repository has been archived by the owner on Jul 21, 2021. It is now read-only.

How to mock Connect API for test? #212

Open
max-min opened this issue May 24, 2019 · 1 comment
Open

How to mock Connect API for test? #212

max-min opened this issue May 24, 2019 · 1 comment

Comments

@max-min
Copy link

max-min commented May 24, 2019

func Connect(servers []string, sessionTimeout time.Duration, options ...connOption) (*Conn, <-chan Event, error) {

connOption is not friendly ...

@khuddlefish
Copy link

We just left the connOption part out in our mock since it is optional. This is kind of what our connect looks like

type stubZkClient struct {
	ConnectStub struct {
		called         int
		servers        []string
		sessionTimeout time.Duration
		zkConn         ZkConn
		eventChan      chan zk.Event
		err            error
	}
}

func (c *stubZkClient) Connect(servers []string, sessionTimeout time.Duration) (ZkConn, <-chan zk.Event, error) {
        c.ConnectStub.called++
        c.ConnectStub.servers = servers
	c.ConnectStub.sessionTimeout = sessionTimeout
	return c.ConnectStub.zkConn, c.ConnectStub.eventChan, c.ConnectStub.err
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants