From 742fcf7a24659801c0b21a4ccfe821a077d97fc2 Mon Sep 17 00:00:00 2001 From: James Phillips Date: Tue, 16 Aug 2016 10:30:30 -0700 Subject: [PATCH] Adds missing TaggedAddress structures to API client. --- api/catalog.go | 17 ++++++++++------- api/catalog_test.go | 9 +++++++++ api/health_test.go | 3 +++ api/prepared_query_test.go | 9 +++++++++ 4 files changed, 31 insertions(+), 7 deletions(-) diff --git a/api/catalog.go b/api/catalog.go index 52a00b304..337772ec0 100644 --- a/api/catalog.go +++ b/api/catalog.go @@ -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 @@ -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 { diff --git a/api/catalog_test.go b/api/catalog_test.go index 3a3395ae6..9ca832304 100644 --- a/api/catalog_test.go +++ b/api/catalog_test.go @@ -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) @@ -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) diff --git a/api/health_test.go b/api/health_test.go index d80a4693a..b6f463d56 100644 --- a/api/health_test.go +++ b/api/health_test.go @@ -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) diff --git a/api/prepared_query_test.go b/api/prepared_query_test.go index 011bfb195..d16f007c9 100644 --- a/api/prepared_query_test.go +++ b/api/prepared_query_test.go @@ -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", @@ -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) @@ -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)