github.com/mailgun/holster/v4@v4.20.0/discovery/srv_test.go (about) 1 package discovery_test 2 3 import ( 4 "testing" 5 6 "github.com/hashicorp/consul/api" 7 "github.com/mailgun/holster/v4/discovery" 8 "github.com/stretchr/testify/assert" 9 "github.com/stretchr/testify/require" 10 ) 11 12 func TestGetSRVAddressesDirect(t *testing.T) { 13 client, err := api.NewClient(api.DefaultConfig()) 14 require.NoError(t, err) 15 16 // Register ourselves in consul as a member of the cluster 17 const id = "1234123" 18 err = client.Agent().ServiceRegisterOpts(&api.AgentServiceRegistration{ 19 Name: "scout", 20 ID: id, 21 Tags: []string{"ml"}, 22 Address: "127.0.0.1", 23 Port: 2319, 24 }, api.ServiceRegisterOpts{ReplaceExistingChecks: true}) 25 require.NoError(t, err) 26 defer func() { 27 err := client.Agent().ServiceDeregister(id) 28 require.NoError(t, err) 29 }() 30 31 addresses, err := discovery.GetSRVAddresses("ml.scout.service.consul", "127.0.0.1:8600") 32 require.NoError(t, err) 33 34 assert.Equal(t, []string{"127.0.0.1:2319"}, addresses) 35 } 36 37 func TestGetSRVAddresses(t *testing.T) { 38 t.Skip("TODO: fix https://github.com/mailgun/holster/issues/152") 39 40 client, err := api.NewClient(api.DefaultConfig()) 41 require.NoError(t, err) 42 43 // Register ourselves in consul as a member of the cluster 44 err = client.Agent().ServiceRegisterOpts(&api.AgentServiceRegistration{ 45 Name: "scout", 46 ID: "123-2319", 47 Tags: []string{"mll"}, 48 Address: "127.0.0.1", 49 Port: 2319, 50 }, api.ServiceRegisterOpts{ReplaceExistingChecks: true}) 51 require.NoError(t, err) 52 defer func() { 53 err := client.Agent().ServiceDeregister("123-2319") 54 require.NoError(t, err) 55 }() 56 57 addresses, err := discovery.GetSRVAddresses("mll.scout.service.consul", "") 58 require.NoError(t, err) 59 60 assert.Equal(t, []string{"127.0.0.1:2319"}, addresses) 61 }