Merge pull request #1726 from hashicorp/f-tag-override-api

Adds support for EnableTagOverride to the API client.
This commit is contained in:
James Phillips 2016-02-17 19:25:40 -08:00
commit aed82bf7d7
4 changed files with 156 additions and 19 deletions

View File

@ -23,6 +23,7 @@ type AgentService struct {
Tags []string
Port int
Address string
EnableTagOverride bool
}
// AgentMember represents a cluster member known to the agent
@ -47,6 +48,7 @@ type AgentServiceRegistration struct {
Tags []string `json:",omitempty"`
Port int `json:",omitempty"`
Address string `json:",omitempty"`
EnableTagOverride bool `json:",omitempty"`
Check *AgentServiceCheck
Checks AgentServiceChecks
}

View File

@ -196,6 +196,49 @@ func TestAgent_ServiceAddress(t *testing.T) {
}
}
func TestAgent_EnableTagOverride(t *testing.T) {
t.Parallel()
c, s := makeClient(t)
defer s.Stop()
agent := c.Agent()
reg1 := &AgentServiceRegistration{
Name: "foo1",
Port: 8000,
Address: "192.168.0.42",
EnableTagOverride: true,
}
reg2 := &AgentServiceRegistration{
Name: "foo2",
Port: 8000,
}
if err := agent.ServiceRegister(reg1); err != nil {
t.Fatalf("err: %v", err)
}
if err := agent.ServiceRegister(reg2); err != nil {
t.Fatalf("err: %v", err)
}
services, err := agent.Services()
if err != nil {
t.Fatalf("err: %v", err)
}
if _, ok := services["foo1"]; !ok {
t.Fatalf("missing service: %v", services)
}
if services["foo1"].EnableTagOverride != true {
t.Fatalf("tag override not set on service foo1: %v", services)
}
if _, ok := services["foo2"]; !ok {
t.Fatalf("missing service: %v", services)
}
if services["foo2"].EnableTagOverride != false {
t.Fatalf("tag override set on service foo2: %v", services)
}
}
func TestAgent_Services_MultipleChecks(t *testing.T) {
t.Parallel()
c, s := makeClient(t)

View File

@ -13,6 +13,7 @@ type CatalogService struct {
ServiceAddress string
ServiceTags []string
ServicePort int
ServiceEnableTagOverride bool
}
type CatalogNode struct {

View File

@ -277,3 +277,94 @@ func TestCatalog_Registration(t *testing.T) {
t.Fatalf("err: %s", err)
})
}
func TestCatalog_EnableTagOverride(t *testing.T) {
t.Parallel()
c, s := makeClient(t)
defer s.Stop()
catalog := c.Catalog()
service := &AgentService{
ID: "redis1",
Service: "redis",
Tags: []string{"master", "v1"},
Port: 8000,
}
reg := &CatalogRegistration{
Datacenter: "dc1",
Node: "foobar",
Address: "192.168.10.10",
Service: service,
}
testutil.WaitForResult(func() (bool, error) {
if _, err := catalog.Register(reg, nil); err != nil {
return false, err
}
node, _, err := catalog.Node("foobar", nil)
if err != nil {
return false, err
}
if _, ok := node.Services["redis1"]; !ok {
return false, fmt.Errorf("missing service: redis1")
}
if node.Services["redis1"].EnableTagOverride != false {
return false, fmt.Errorf("tag override set")
}
services, _, err := catalog.Service("redis", "", nil)
if err != nil {
return false, err
}
if len(services) < 1 || services[0].ServiceName != "redis" {
return false, fmt.Errorf("missing service: redis")
}
if services[0].ServiceEnableTagOverride != false {
return false, fmt.Errorf("tag override set")
}
return true, nil
}, func(err error) {
t.Fatalf("err: %s", err)
})
service.EnableTagOverride = true
testutil.WaitForResult(func() (bool, error) {
if _, err := catalog.Register(reg, nil); err != nil {
return false, err
}
node, _, err := catalog.Node("foobar", nil)
if err != nil {
return false, err
}
if _, ok := node.Services["redis1"]; !ok {
return false, fmt.Errorf("missing service: redis1")
}
if node.Services["redis1"].EnableTagOverride != true {
return false, fmt.Errorf("tag override not set")
}
services, _, err := catalog.Service("redis", "", nil)
if err != nil {
return false, err
}
if len(services) < 1 || services[0].ServiceName != "redis" {
return false, fmt.Errorf("missing service: redis")
}
if services[0].ServiceEnableTagOverride != true {
return false, fmt.Errorf("tag override not set")
}
return true, nil
}, func(err error) {
t.Fatalf("err: %s", err)
})
}