diff --git a/command/members.go b/command/members.go index b9ca520cf8..711195528f 100644 --- a/command/members.go +++ b/command/members.go @@ -114,7 +114,7 @@ func (c *MembersCommand) Run(args []string) int { // in a more human-friendly format func (c *MembersCommand) standardOutput(members []agent.Member) []string { result := make([]string, 0, len(members)) - header := "Node|Address|Status|Type|Build|Protocol" + header := "Node|Address|Status|Type|Build|Protocol|DC" result = append(result, header) for _, member := range members { addr := net.TCPAddr{IP: member.Addr, Port: int(member.Port)} @@ -125,18 +125,19 @@ func (c *MembersCommand) standardOutput(members []agent.Member) []string { } else if idx := strings.Index(build, ":"); idx != -1 { build = build[:idx] } + dc := member.Tags["dc"] switch member.Tags["role"] { case "node": - line := fmt.Sprintf("%s|%s|%s|client|%s|%s", - member.Name, addr.String(), member.Status, build, protocol) + line := fmt.Sprintf("%s|%s|%s|client|%s|%s|%s", + member.Name, addr.String(), member.Status, build, protocol, dc) result = append(result, line) case "consul": - line := fmt.Sprintf("%s|%s|%s|server|%s|%s", - member.Name, addr.String(), member.Status, build, protocol) + line := fmt.Sprintf("%s|%s|%s|server|%s|%s|%s", + member.Name, addr.String(), member.Status, build, protocol, dc) result = append(result, line) default: - line := fmt.Sprintf("%s|%s|%s|unknown||", + line := fmt.Sprintf("%s|%s|%s|unknown|||", member.Name, addr.String(), member.Status) result = append(result, line) } diff --git a/command/members_test.go b/command/members_test.go index b2ec7e7adb..12b1e4d176 100644 --- a/command/members_test.go +++ b/command/members_test.go @@ -24,9 +24,20 @@ func TestMembersCommandRun(t *testing.T) { t.Fatalf("bad: %d. %#v", code, ui.ErrorWriter.String()) } + // Name if !strings.Contains(ui.OutputWriter.String(), a1.config.NodeName) { t.Fatalf("bad: %#v", ui.OutputWriter.String()) } + + // Agent type + if !strings.Contains(ui.OutputWriter.String(), "server") { + t.Fatalf("bad: %#v", ui.OutputWriter.String()) + } + + // Datacenter + if !strings.Contains(ui.OutputWriter.String(), "dc1") { + t.Fatalf("bad: %#v", ui.OutputWriter.String()) + } } func TestMembersCommandRun_WAN(t *testing.T) {