Skip to content

Commit

Permalink
Adds missing TaggedAddress structures to API client.
Browse files Browse the repository at this point in the history
  • Loading branch information
slackpad committed Aug 16, 2016
1 parent 315b9d4 commit 1d5eb36
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 7 deletions.
17 changes: 10 additions & 7 deletions api/catalog.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package api

type Node struct {
Node string
Address string
Node string
Address string
TaggedAddresses map[string]string
}

type CatalogService struct {
Node string
Address string
TaggedAddresses map[string]string
ServiceID string
ServiceName string
ServiceAddress string
Expand All @@ -22,11 +24,12 @@ type CatalogNode struct {
}

type CatalogRegistration struct {
Node string
Address string
Datacenter string
Service *AgentService
Check *AgentCheck
Node string
Address string
TaggedAddresses map[string]string
Datacenter string
Service *AgentService
Check *AgentCheck
}

type CatalogDeregistration struct {
Expand Down
9 changes: 9 additions & 0 deletions api/catalog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ func TestCatalog_Nodes(t *testing.T) {
return false, fmt.Errorf("Bad: %v", nodes)
}

if _, ok := nodes[0].TaggedAddresses["wan"]; !ok {
return false, fmt.Errorf("Bad: %v", nodes)
}

return true, nil
}, func(err error) {
t.Fatalf("err: %s", err)
Expand Down Expand Up @@ -128,10 +132,15 @@ func TestCatalog_Node(t *testing.T) {
if meta.LastIndex == 0 {
return false, fmt.Errorf("Bad: %v", meta)
}

if len(info.Services) == 0 {
return false, fmt.Errorf("Bad: %v", info)
}

if _, ok := info.Node.TaggedAddresses["wan"]; !ok {
return false, fmt.Errorf("Bad: %v", info)
}

return true, nil
}, func(err error) {
t.Fatalf("err: %s", err)
Expand Down
3 changes: 3 additions & 0 deletions api/health_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ func TestHealth_Service(t *testing.T) {
if len(checks) == 0 {
return false, fmt.Errorf("Bad: %v", checks)
}
if _, ok := checks[0].Node.TaggedAddresses["wan"]; !ok {
return false, fmt.Errorf("Bad: %v", checks)
}
return true, nil
}, func(err error) {
t.Fatalf("err: %s", err)
Expand Down
9 changes: 9 additions & 0 deletions api/prepared_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ func TestPreparedQuery(t *testing.T) {
Datacenter: "dc1",
Node: "foobar",
Address: "192.168.10.10",
TaggedAddresses: map[string]string{
"wan": "127.0.0.1",
},
Service: &AgentService{
ID: "redis1",
Service: "redis",
Expand Down Expand Up @@ -96,6 +99,9 @@ func TestPreparedQuery(t *testing.T) {
if len(results.Nodes) != 1 || results.Nodes[0].Node.Node != "foobar" {
t.Fatalf("bad: %v", results)
}
if wan, ok := results.Nodes[0].Node.TaggedAddresses["wan"]; !ok || wan != "127.0.0.1" {
t.Fatalf("bad: %v", results)
}

// Execute by name.
results, _, err = query.Execute("my-query", nil)
Expand All @@ -105,6 +111,9 @@ func TestPreparedQuery(t *testing.T) {
if len(results.Nodes) != 1 || results.Nodes[0].Node.Node != "foobar" {
t.Fatalf("bad: %v", results)
}
if wan, ok := results.Nodes[0].Node.TaggedAddresses["wan"]; !ok || wan != "127.0.0.1" {
t.Fatalf("bad: %v", results)
}

// Delete it.
_, err = query.Delete(def.ID, nil)
Expand Down

0 comments on commit 1d5eb36

Please sign in to comment.