@@ -11,6 +11,7 @@ import (
1111 "time"
1212
1313 "github.com/hashicorp/consul/api"
14+ "github.com/ncode/tagit/pkg/consul"
1415 "github.com/stretchr/testify/assert"
1516)
1617
@@ -19,7 +20,7 @@ type MockConsulClient struct {
1920 MockAgent * MockAgent
2021}
2122
22- func (m * MockConsulClient ) Agent () ConsulAgent {
23+ func (m * MockConsulClient ) Agent () consul. ConsulAgent {
2324 return m .MockAgent
2425}
2526
@@ -596,19 +597,34 @@ func TestRun(t *testing.T) {
596597 assert .LessOrEqual (t , updateServiceTagsCalled .Load (), int32 (4 ), "Expected updateServiceTags to be called at most 4 times" )
597598}
598599
599- func TestNewConsulAPIWrapper (t * testing.T ) {
600- consulClient , err := api .NewClient (api .DefaultConfig ())
601- assert .NoError (t , err , "Failed to create Consul client" )
602-
603- wrapper := NewConsulAPIWrapper (consulClient )
604-
605- assert .NotNil (t , wrapper , "NewConsulAPIWrapper returned nil" )
606-
607- _ , isConsulClient := interface {}(wrapper ).(ConsulClient )
608- assert .True (t , isConsulClient , "NewConsulAPIWrapper does not implement ConsulClient interface" )
609-
610- _ , isConsulAgent := wrapper .Agent ().(ConsulAgent )
611- assert .True (t , isConsulAgent , "Wrapper's Agent method does not return a ConsulAgent" )
600+ func TestConsulInterfaceCompatibility (t * testing.T ) {
601+ // Test that our mocks implement the consul package interfaces correctly
602+ mockAgent := & MockAgent {
603+ ServiceFunc : func (serviceID string , q * api.QueryOptions ) (* api.AgentService , * api.QueryMeta , error ) {
604+ return & api.AgentService {ID : serviceID }, nil , nil
605+ },
606+ ServiceRegisterFunc : func (reg * api.AgentServiceRegistration ) error {
607+ return nil
608+ },
609+ }
610+
611+ mockClient := & MockConsulClient {
612+ MockAgent : mockAgent ,
613+ }
614+
615+ // Verify that MockConsulClient implements consul.ConsulClient
616+ var _ consul.ConsulClient = mockClient
617+
618+ // Verify that MockAgent implements consul.ConsulAgent
619+ var _ consul.ConsulAgent = mockAgent
620+
621+ // Test that the mock client works correctly
622+ agent := mockClient .Agent ()
623+ assert .NotNil (t , agent , "Agent() should return non-nil" )
624+
625+ service , _ , err := agent .Service ("test-service" , nil )
626+ assert .NoError (t , err )
627+ assert .Equal (t , "test-service" , service .ID )
612628}
613629
614630func TestCmdExecutor_Execute (t * testing.T ) {
0 commit comments