File tree Expand file tree Collapse file tree 2 files changed +26
-7
lines changed
Expand file tree Collapse file tree 2 files changed +26
-7
lines changed Original file line number Diff line number Diff line change @@ -25,7 +25,13 @@ type TagIt struct {
2525
2626// ConsulClient is an interface for the Consul client.
2727type ConsulClient interface {
28- Agent () * api.Agent
28+ Agent () ConsulAgent
29+ }
30+
31+ // ConsulClientAgent is an interface for the Consul agent.
32+ type ConsulAgent interface {
33+ Services () (map [string ]* api.AgentService , error )
34+ ServiceRegister (* api.AgentServiceRegistration ) error
2935}
3036
3137// CommandExecutor is an interface for running commands.
Original file line number Diff line number Diff line change @@ -290,13 +290,26 @@ func TestRunScript(t *testing.T) {
290290 }
291291}
292292
293- // MockConsulClient is a mock implementation of the ConsulClient interface
294- type MockConsulClient struct {}
293+ // MockConsulClient implements the ConsulClient interface for testing.
294+ type MockConsulClient struct {
295+ MockAgent * MockAgent
296+ }
297+
298+ func (m * MockConsulClient ) Agent () ConsulAgent {
299+ return m .MockAgent
300+ }
301+
302+ // MockAgent simulates the Agent part of the Consul client.
303+ type MockAgent struct {
304+ ServicesFunc func () (map [string ]* api.AgentService , error )
305+ }
306+
307+ func (m * MockAgent ) Services () (map [string ]* api.AgentService , error ) {
308+ return m .ServicesFunc ()
309+ }
295310
296- // TODO: Implement the Agent method properly so that we can test the rest of the methods
297- func (m * MockConsulClient ) Agent () * api.Agent {
298- // Return a mock *api.Agent if needed
299- return & api.Agent {}
311+ func (m * MockAgent ) ServiceRegister (reg * api.AgentServiceRegistration ) error {
312+ return nil
300313}
301314
302315func TestNew (t * testing.T ) {
You can’t perform that action at this time.
0 commit comments