agent: /v1/catalog/service/:service works with proxies
This commit is contained in:
parent
58bff8dd05
commit
761b561946
|
@ -10,6 +10,7 @@ import (
|
|||
"github.com/hashicorp/consul/agent/structs"
|
||||
"github.com/hashicorp/consul/testutil/retry"
|
||||
"github.com/hashicorp/serf/coordinate"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestCatalogRegister_Service_InvalidAddress(t *testing.T) {
|
||||
|
@ -750,6 +751,30 @@ func TestCatalogServiceNodes_DistanceSort(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestCatalogServiceNodes_ConnectProxy(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
assert := assert.New(t)
|
||||
a := NewTestAgent(t.Name(), "")
|
||||
defer a.Shutdown()
|
||||
|
||||
// Register
|
||||
args := structs.TestRegisterRequestProxy(t)
|
||||
var out struct{}
|
||||
assert.Nil(a.RPC("Catalog.Register", args, &out))
|
||||
|
||||
req, _ := http.NewRequest("GET", fmt.Sprintf(
|
||||
"/v1/catalog/service/%s", args.Service.Service), nil)
|
||||
resp := httptest.NewRecorder()
|
||||
obj, err := a.srv.CatalogServiceNodes(resp, req)
|
||||
assert.Nil(err)
|
||||
assertIndex(t, resp)
|
||||
|
||||
nodes := obj.(structs.ServiceNodes)
|
||||
assert.Len(nodes, 1)
|
||||
assert.Equal(structs.ServiceKindConnectProxy, nodes[0].ServiceKind)
|
||||
}
|
||||
|
||||
func TestCatalogNodeServices(t *testing.T) {
|
||||
t.Parallel()
|
||||
a := NewTestAgent(t.Name(), "")
|
||||
|
|
|
@ -16,6 +16,7 @@ import (
|
|||
"github.com/hashicorp/consul/testutil/retry"
|
||||
"github.com/hashicorp/consul/types"
|
||||
"github.com/hashicorp/net-rpc-msgpackrpc"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestCatalog_Register(t *testing.T) {
|
||||
|
@ -1599,6 +1600,37 @@ func TestCatalog_ListServiceNodes_DistanceSort(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestCatalog_ListServiceNodes_ConnectProxy(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
assert := assert.New(t)
|
||||
dir1, s1 := testServer(t)
|
||||
defer os.RemoveAll(dir1)
|
||||
defer s1.Shutdown()
|
||||
codec := rpcClient(t, s1)
|
||||
defer codec.Close()
|
||||
|
||||
testrpc.WaitForLeader(t, s1.RPC, "dc1")
|
||||
|
||||
// Register the service
|
||||
args := structs.TestRegisterRequestProxy(t)
|
||||
var out struct{}
|
||||
assert.Nil(msgpackrpc.CallWithCodec(codec, "Catalog.Register", args, &out))
|
||||
|
||||
// List
|
||||
req := structs.ServiceSpecificRequest{
|
||||
Datacenter: "dc1",
|
||||
ServiceName: args.Service.Service,
|
||||
TagFilter: false,
|
||||
}
|
||||
var resp structs.IndexedServiceNodes
|
||||
assert.Nil(msgpackrpc.CallWithCodec(codec, "Catalog.ServiceNodes", &req, &resp))
|
||||
assert.Len(resp.ServiceNodes, 1)
|
||||
v := resp.ServiceNodes[0]
|
||||
assert.Equal(structs.ServiceKindConnectProxy, v.ServiceKind)
|
||||
assert.Equal(args.Service.ProxyDestination, v.ServiceProxyDestination)
|
||||
}
|
||||
|
||||
func TestCatalog_NodeServices(t *testing.T) {
|
||||
t.Parallel()
|
||||
dir1, s1 := testServer(t)
|
||||
|
|
|
@ -13,9 +13,12 @@ const (
|
|||
SerfCheckFailedOutput = "Agent not live or unreachable"
|
||||
)
|
||||
|
||||
// These are used to manage the "consul" service that's attached to every Consul
|
||||
// server node in the catalog.
|
||||
const (
|
||||
// These are used to manage the "consul" service that's attached to every
|
||||
// Consul server node in the catalog.
|
||||
ConsulServiceID = "consul"
|
||||
ConsulServiceName = "consul"
|
||||
|
||||
// ConnectProxyServiceName is the name of the proxy services.
|
||||
ConnectProxyServiceName = "connect-proxy"
|
||||
)
|
||||
|
|
|
@ -416,6 +416,7 @@ func (s *ServiceNode) PartialClone() *ServiceNode {
|
|||
Node: s.Node,
|
||||
// Skip Address, see above.
|
||||
// Skip TaggedAddresses, see above.
|
||||
ServiceKind: s.ServiceKind,
|
||||
ServiceID: s.ServiceID,
|
||||
ServiceName: s.ServiceName,
|
||||
ServiceTags: tags,
|
||||
|
@ -423,6 +424,7 @@ func (s *ServiceNode) PartialClone() *ServiceNode {
|
|||
ServicePort: s.ServicePort,
|
||||
ServiceMeta: nsmeta,
|
||||
ServiceEnableTagOverride: s.ServiceEnableTagOverride,
|
||||
ServiceProxyDestination: s.ServiceProxyDestination,
|
||||
RaftIndex: RaftIndex{
|
||||
CreateIndex: s.CreateIndex,
|
||||
ModifyIndex: s.ModifyIndex,
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
package structs
|
||||
|
||||
import (
|
||||
"github.com/mitchellh/go-testing-interface"
|
||||
)
|
||||
|
||||
// TestRegisterRequestProxy returns a RegisterRequest for registering a
|
||||
// Connect proxy.
|
||||
func TestRegisterRequestProxy(t testing.T) *RegisterRequest {
|
||||
return &RegisterRequest{
|
||||
Datacenter: "dc1",
|
||||
Node: "foo",
|
||||
Address: "127.0.0.1",
|
||||
Service: &NodeService{
|
||||
Kind: ServiceKindConnectProxy,
|
||||
Service: ConnectProxyServiceName,
|
||||
Address: "127.0.0.2",
|
||||
Port: 2222,
|
||||
ProxyDestination: "web",
|
||||
},
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue