From 6a3271980e334588aab7cab5f40faf70f0f55ea5 Mon Sep 17 00:00:00 2001 From: Ryan Uber Date: Mon, 29 Sep 2014 15:49:47 -0700 Subject: [PATCH] command/keyring: refactor, adjust tests --- command/keyring.go | 17 ++++------------- command/keyring_test.go | 8 ++++---- 2 files changed, 8 insertions(+), 17 deletions(-) diff --git a/command/keyring.go b/command/keyring.go index cc6d211a83..cde37f3e6c 100644 --- a/command/keyring.go +++ b/command/keyring.go @@ -11,7 +11,6 @@ import ( "github.com/hashicorp/consul/command/agent" "github.com/mitchellh/cli" - "github.com/ryanuber/columnize" ) const ( @@ -97,7 +96,7 @@ func (c *KeyringCommand) Run(args []string) int { defer client.Close() if listKeys { - c.Ui.Info("Asking all members for installed keys...") + c.Ui.Info("Gathering installed encryption keys...") r, err := client.ListKeys() if err != nil { c.Ui.Error(fmt.Sprintf("error: %s", err)) @@ -161,17 +160,12 @@ func (c *KeyringCommand) handleResponse( c.Ui.Error("") c.Ui.Error(fmt.Sprintf("%s error: %s", pool, i.Error)) - var errors []string for _, msg := range messages { if msg.Datacenter != i.Datacenter || msg.Pool != i.Pool { continue } - errors = append(errors, fmt.Sprintf( - "failed: %s | %s", - msg.Node, - msg.Message)) + c.Ui.Error(fmt.Sprintf(" %s: %s", msg.Node, msg.Message)) } - c.Ui.Error(columnize.SimpleFormat(errors)) rval = 1 } } @@ -208,16 +202,13 @@ func (c *KeyringCommand) handleList( installed[pool][key.Key] = []int{key.Count, nodes} } } + for pool, keys := range installed { c.Ui.Output("") c.Ui.Output(pool + ":") - var out []string for key, num := range keys { - out = append(out, fmt.Sprintf( - "%s | [%d/%d]", - key, num[0], num[1])) + c.Ui.Output(fmt.Sprintf(" %s [%d/%d]", key, num[0], num[1])) } - c.Ui.Output(columnize.SimpleFormat(out)) } } diff --git a/command/keyring_test.go b/command/keyring_test.go index 98f8ba3dd1..7e975b6ccc 100644 --- a/command/keyring_test.go +++ b/command/keyring_test.go @@ -26,10 +26,10 @@ func TestKeyringCommandRun(t *testing.T) { // The LAN and WAN keyrings were initialized with key1 out := listKeys(t, a1.addr) - if !strings.Contains(out, "dc1 (LAN):\n"+key1) { + if !strings.Contains(out, "dc1 (LAN):\n "+key1) { t.Fatalf("bad: %#v", out) } - if !strings.Contains(out, "WAN:\n"+key1) { + if !strings.Contains(out, "WAN:\n "+key1) { t.Fatalf("bad: %#v", out) } if strings.Contains(out, key2) { @@ -53,10 +53,10 @@ func TestKeyringCommandRun(t *testing.T) { // Only key2 is present now out = listKeys(t, a1.addr) - if !strings.Contains(out, "dc1 (LAN):\n"+key2) { + if !strings.Contains(out, "dc1 (LAN):\n "+key2) { t.Fatalf("bad: %#v", out) } - if !strings.Contains(out, "WAN:\n"+key2) { + if !strings.Contains(out, "WAN:\n "+key2) { t.Fatalf("bad: %#v", out) } if strings.Contains(out, key1) {