agent: address PR feedback

This commit is contained in:
Mitchell Hashimoto 2018-03-21 16:54:44 -10:00
parent 22a0eb6c67
commit 4d852e62a3
No known key found for this signature in database
GPG Key ID: 744E147AA52F5B0A
4 changed files with 25 additions and 14 deletions

View File

@ -788,6 +788,7 @@ func TestCatalogConnectServiceNodes_good(t *testing.T) {
// Register // Register
args := structs.TestRegisterRequestProxy(t) args := structs.TestRegisterRequestProxy(t)
args.Service.Address = "127.0.0.55"
var out struct{} var out struct{}
assert.Nil(a.RPC("Catalog.Register", args, &out)) assert.Nil(a.RPC("Catalog.Register", args, &out))
@ -801,6 +802,7 @@ func TestCatalogConnectServiceNodes_good(t *testing.T) {
nodes := obj.(structs.ServiceNodes) nodes := obj.(structs.ServiceNodes)
assert.Len(nodes, 1) assert.Len(nodes, 1)
assert.Equal(structs.ServiceKindConnectProxy, nodes[0].ServiceKind) assert.Equal(structs.ServiceKindConnectProxy, nodes[0].ServiceKind)
assert.Equal(args.Service.Address, nodes[0].ServiceAddress)
} }
func TestCatalogNodeServices(t *testing.T) { func TestCatalogNodeServices(t *testing.T) {

View File

@ -112,22 +112,14 @@ func (h *Health) ServiceNodes(args *structs.ServiceSpecificRequest, reply *struc
} }
// Determine the function we'll call // 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 { switch {
case args.Connect: case args.Connect:
f = func(ws memdb.WatchSet, s *state.Store) (uint64, structs.CheckServiceNodes, error) { f = h.serviceNodesConnect
return s.CheckConnectServiceNodes(ws, args.ServiceName)
}
case args.TagFilter: case args.TagFilter:
f = func(ws memdb.WatchSet, s *state.Store) (uint64, structs.CheckServiceNodes, error) { f = h.serviceNodesTagFilter
return s.CheckServiceTagNodes(ws, args.ServiceName, args.ServiceTag)
}
default: default:
f = func(ws memdb.WatchSet, s *state.Store) (uint64, structs.CheckServiceNodes, error) { f = h.serviceNodesDefault
return s.CheckServiceNodes(ws, args.ServiceName)
}
} }
// If we're doing a connect query, we need read access to the service // 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, &args.QueryOptions,
&reply.QueryMeta, &reply.QueryMeta,
func(ws memdb.WatchSet, state *state.Store) error { func(ws memdb.WatchSet, state *state.Store) error {
index, nodes, err := f(ws, state) index, nodes, err := f(ws, state, args)
if err != nil { if err != nil {
return err return err
} }
@ -185,3 +177,18 @@ func (h *Health) ServiceNodes(args *structs.ServiceSpecificRequest, reply *struc
} }
return err 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)
}

View File

@ -1052,6 +1052,7 @@ func TestDNS_ConnectServiceLookup(t *testing.T) {
// Register // Register
{ {
args := structs.TestRegisterRequestProxy(t) args := structs.TestRegisterRequestProxy(t)
args.Address = "127.0.0.55"
args.Service.ProxyDestination = "db" args.Service.ProxyDestination = "db"
args.Service.Address = "" args.Service.Address = ""
args.Service.Port = 12345 args.Service.Port = 12345
@ -1082,6 +1083,7 @@ func TestDNS_ConnectServiceLookup(t *testing.T) {
assert.True(ok) assert.True(ok)
assert.Equal("foo.node.dc1.consul.", cnameRec.Hdr.Name) assert.Equal("foo.node.dc1.consul.", cnameRec.Hdr.Name)
assert.Equal(uint32(0), srvRec.Hdr.Ttl) assert.Equal(uint32(0), srvRec.Hdr.Ttl)
assert.Equal("127.0.0.55", cnameRec.A.String())
} }
} }

View File

@ -851,7 +851,7 @@ func TestHealthConnectServiceNodes_PassingFilter(t *testing.T) {
assert.Nil(err) assert.Nil(err)
assertIndex(t, resp) assertIndex(t, resp)
// Should be 0 health check for consul // Should be 1
nodes := obj.(structs.CheckServiceNodes) nodes := obj.(structs.CheckServiceNodes)
assert.Len(nodes, 1) assert.Len(nodes, 1)
}) })