From e78c235dcffe6fddf5ed2c69afc46c75be214062 Mon Sep 17 00:00:00 2001 From: Ryan Uber Date: Wed, 10 Sep 2014 10:20:40 -0700 Subject: [PATCH] command/keys: test network connection failure --- command/keys_test.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/command/keys_test.go b/command/keys_test.go index b326e7b3dc..903d13b19f 100644 --- a/command/keys_test.go +++ b/command/keys_test.go @@ -112,11 +112,26 @@ func TestKeysCommandRun_help(t *testing.T) { if code != 1 { t.Fatalf("bad: %d. %#v", code, ui.ErrorWriter.String()) } + + // Test that we didn't actually try to dial the RPC server. if !strings.Contains(ui.ErrorWriter.String(), "Usage:") { t.Fatalf("bad: %#v", ui.ErrorWriter.String()) } } +func TestKeysCommandRun_failedConnection(t *testing.T) { + ui := new(cli.MockUi) + c := &KeysCommand{Ui: ui} + args := []string{"-list", "-rpc-addr=127.0.0.1:0"} + code := c.Run(args) + if code != 1 { + t.Fatalf("bad: %d, %#v", code, ui.ErrorWriter.String()) + } + if !strings.Contains(ui.ErrorWriter.String(), "dial") { + t.Fatalf("bad: %#v", ui.OutputWriter.String()) + } +} + func listKeys(t *testing.T, addr string, wan bool) string { ui := new(cli.MockUi) c := &KeysCommand{Ui: ui}