mirror of https://github.com/status-im/consul.git
agent: address PR feedback
This commit is contained in:
parent
22a0eb6c67
commit
4d852e62a3
|
@ -788,6 +788,7 @@ func TestCatalogConnectServiceNodes_good(t *testing.T) {
|
|||
|
||||
// Register
|
||||
args := structs.TestRegisterRequestProxy(t)
|
||||
args.Service.Address = "127.0.0.55"
|
||||
var out struct{}
|
||||
assert.Nil(a.RPC("Catalog.Register", args, &out))
|
||||
|
||||
|
@ -801,6 +802,7 @@ func TestCatalogConnectServiceNodes_good(t *testing.T) {
|
|||
nodes := obj.(structs.ServiceNodes)
|
||||
assert.Len(nodes, 1)
|
||||
assert.Equal(structs.ServiceKindConnectProxy, nodes[0].ServiceKind)
|
||||
assert.Equal(args.Service.Address, nodes[0].ServiceAddress)
|
||||
}
|
||||
|
||||
func TestCatalogNodeServices(t *testing.T) {
|
||||
|
|
|
@ -112,22 +112,14 @@ func (h *Health) ServiceNodes(args *structs.ServiceSpecificRequest, reply *struc
|
|||
}
|
||||
|
||||
// Determine the function we'll call
|
||||
var f func(memdb.WatchSet, *state.Store) (uint64, structs.CheckServiceNodes, error)
|
||||
var f func(memdb.WatchSet, *state.Store, *structs.ServiceSpecificRequest) (uint64, structs.CheckServiceNodes, error)
|
||||
switch {
|
||||
case args.Connect:
|
||||
f = func(ws memdb.WatchSet, s *state.Store) (uint64, structs.CheckServiceNodes, error) {
|
||||
return s.CheckConnectServiceNodes(ws, args.ServiceName)
|
||||
}
|
||||
|
||||
f = h.serviceNodesConnect
|
||||
case args.TagFilter:
|
||||
f = func(ws memdb.WatchSet, s *state.Store) (uint64, structs.CheckServiceNodes, error) {
|
||||
return s.CheckServiceTagNodes(ws, args.ServiceName, args.ServiceTag)
|
||||
}
|
||||
|
||||
f = h.serviceNodesTagFilter
|
||||
default:
|
||||
f = func(ws memdb.WatchSet, s *state.Store) (uint64, structs.CheckServiceNodes, error) {
|
||||
return s.CheckServiceNodes(ws, args.ServiceName)
|
||||
}
|
||||
f = h.serviceNodesDefault
|
||||
}
|
||||
|
||||
// If we're doing a connect query, we need read access to the service
|
||||
|
@ -149,7 +141,7 @@ func (h *Health) ServiceNodes(args *structs.ServiceSpecificRequest, reply *struc
|
|||
&args.QueryOptions,
|
||||
&reply.QueryMeta,
|
||||
func(ws memdb.WatchSet, state *state.Store) error {
|
||||
index, nodes, err := f(ws, state)
|
||||
index, nodes, err := f(ws, state, args)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -185,3 +177,18 @@ func (h *Health) ServiceNodes(args *structs.ServiceSpecificRequest, reply *struc
|
|||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// The serviceNodes* functions below are the various lookup methods that
|
||||
// can be used by the ServiceNodes endpoint.
|
||||
|
||||
func (h *Health) serviceNodesConnect(ws memdb.WatchSet, s *state.Store, args *structs.ServiceSpecificRequest) (uint64, structs.CheckServiceNodes, error) {
|
||||
return s.CheckConnectServiceNodes(ws, args.ServiceName)
|
||||
}
|
||||
|
||||
func (h *Health) serviceNodesTagFilter(ws memdb.WatchSet, s *state.Store, args *structs.ServiceSpecificRequest) (uint64, structs.CheckServiceNodes, error) {
|
||||
return s.CheckServiceTagNodes(ws, args.ServiceName, args.ServiceTag)
|
||||
}
|
||||
|
||||
func (h *Health) serviceNodesDefault(ws memdb.WatchSet, s *state.Store, args *structs.ServiceSpecificRequest) (uint64, structs.CheckServiceNodes, error) {
|
||||
return s.CheckServiceNodes(ws, args.ServiceName)
|
||||
}
|
||||
|
|
|
@ -1052,6 +1052,7 @@ func TestDNS_ConnectServiceLookup(t *testing.T) {
|
|||
// Register
|
||||
{
|
||||
args := structs.TestRegisterRequestProxy(t)
|
||||
args.Address = "127.0.0.55"
|
||||
args.Service.ProxyDestination = "db"
|
||||
args.Service.Address = ""
|
||||
args.Service.Port = 12345
|
||||
|
@ -1082,6 +1083,7 @@ func TestDNS_ConnectServiceLookup(t *testing.T) {
|
|||
assert.True(ok)
|
||||
assert.Equal("foo.node.dc1.consul.", cnameRec.Hdr.Name)
|
||||
assert.Equal(uint32(0), srvRec.Hdr.Ttl)
|
||||
assert.Equal("127.0.0.55", cnameRec.A.String())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -851,7 +851,7 @@ func TestHealthConnectServiceNodes_PassingFilter(t *testing.T) {
|
|||
assert.Nil(err)
|
||||
assertIndex(t, resp)
|
||||
|
||||
// Should be 0 health check for consul
|
||||
// Should be 1
|
||||
nodes := obj.(structs.CheckServiceNodes)
|
||||
assert.Len(nodes, 1)
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue