From 297e4f272e1e177bcdddadd63ebc927d83f4bdfa Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 5 Jun 2018 10:56:42 -0700 Subject: [PATCH] api: support native connect --- api/agent.go | 3 ++- api/catalog_test.go | 59 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 1 deletion(-) diff --git a/api/agent.go b/api/agent.go index 7830f80f21..8cb81fc84e 100644 --- a/api/agent.go +++ b/api/agent.go @@ -69,7 +69,8 @@ type AgentService struct { // AgentServiceConnect represents the Connect configuration of a service. type AgentServiceConnect struct { - Proxy *AgentServiceConnectProxy + Native bool + Proxy *AgentServiceConnectProxy } // AgentServiceConnectProxy represents the Connect Proxy configuration of a diff --git a/api/catalog_test.go b/api/catalog_test.go index 9db640b9d4..3cc1bbccb1 100644 --- a/api/catalog_test.go +++ b/api/catalog_test.go @@ -310,6 +310,65 @@ func TestAPI_CatalogConnect(t *testing.T) { }) } +func TestAPI_CatalogConnectNative(t *testing.T) { + t.Parallel() + c, s := makeClient(t) + defer s.Stop() + + catalog := c.Catalog() + + // Register service and proxy instances to test against. + service := &AgentService{ + ID: "redis1", + Service: "redis", + Port: 8000, + Connect: &AgentServiceConnect{Native: true}, + } + check := &AgentCheck{ + Node: "foobar", + CheckID: "service:redis1", + Name: "Redis health check", + Notes: "Script based health check", + Status: HealthPassing, + ServiceID: "redis1", + } + + reg := &CatalogRegistration{ + Datacenter: "dc1", + Node: "foobar", + Address: "192.168.10.10", + Service: service, + Check: check, + } + + retry.Run(t, func(r *retry.R) { + if _, err := catalog.Register(reg, nil); err != nil { + r.Fatal(err) + } + + services, meta, err := catalog.Connect("redis", "", nil) + if err != nil { + r.Fatal(err) + } + + if meta.LastIndex == 0 { + r.Fatalf("Bad: %v", meta) + } + + if len(services) == 0 { + r.Fatalf("Bad: %v", services) + } + + if services[0].Datacenter != "dc1" { + r.Fatalf("Bad datacenter: %v", services[0]) + } + + if services[0].ServicePort != service.Port { + r.Fatalf("Returned port should be for proxy: %v", services[0]) + } + }) +} + func TestAPI_CatalogNode(t *testing.T) { t.Parallel() c, s := makeClient(t)