diff --git a/consul/catalog_endpoint_test.go b/consul/catalog_endpoint_test.go index 85fa6a141..423ed106a 100644 --- a/consul/catalog_endpoint_test.go +++ b/consul/catalog_endpoint_test.go @@ -213,13 +213,18 @@ func TestCatalogListNodes(t *testing.T) { t.Fatalf("err: %v", err) } - if len(out) != 1 { + if len(out) != 2 { t.Fatalf("bad: %v", out) } - if out[0].Node != "foo" { + + // Server node is auto added from Serf + if out[0].Node != s1.config.NodeName { t.Fatalf("bad: %v", out) } - if out[0].Address != "127.0.0.1" { + if out[1].Node != "foo" { + t.Fatalf("bad: %v", out) + } + if out[1].Address != "127.0.0.1" { t.Fatalf("bad: %v", out) } } diff --git a/consul/health_endpoint_test.go b/consul/health_endpoint_test.go index 8dc2287f4..536573a99 100644 --- a/consul/health_endpoint_test.go +++ b/consul/health_endpoint_test.go @@ -40,11 +40,16 @@ func TestHealth_ChecksInState(t *testing.T) { t.Fatalf("err: %v", err) } - if len(checks) != 1 { + if len(checks) != 2 { t.Fatalf("Bad: %v", checks) } - if checks[0].Name != "memory utilization" { - t.Fatalf("Bad: %v", checks) + + // First check is automatically added for the server node + if checks[0].CheckID != serfCheckID { + t.Fatalf("Bad: %v", checks[0]) + } + if checks[1].Name != "memory utilization" { + t.Fatalf("Bad: %v", checks[1]) } } diff --git a/consul/util_test.go b/consul/util_test.go index 7a04c57bf..7d24d458a 100644 --- a/consul/util_test.go +++ b/consul/util_test.go @@ -1,6 +1,7 @@ package consul import ( + "github.com/hashicorp/serf/serf" "testing" ) @@ -31,3 +32,31 @@ func TestIsPrivateIP(t *testing.T) { t.Fatalf("bad") } } + +func TestIsConsulServer(t *testing.T) { + m := serf.Member{ + Role: "consul:east-aws:10000", + } + valid, dc, port := isConsulServer(m) + if !valid || dc != "east-aws" || port != 10000 { + t.Fatalf("bad: %v %v %v", valid, dc, port) + } +} + +func TestIsConsulNode(t *testing.T) { + m := serf.Member{ + Role: "node:east-aws", + } + valid, dc := isConsulNode(m) + if !valid || dc != "east-aws" { + t.Fatalf("bad: %v %v %v", valid, dc) + } +} + +func TestByteConversion(t *testing.T) { + var val uint64 = 2 << 50 + raw := uint64ToBytes(val) + if bytesToUint64(raw) != val { + t.Fatalf("no match") + } +}