From a03738c11758b56b0038677e38eed2ec8ea3f1c1 Mon Sep 17 00:00:00 2001 From: Frank Schroeder Date: Tue, 17 Oct 2017 13:46:25 +0200 Subject: [PATCH] commands: cleanup catalog list nodes tests --- .../list/nodes/catalog_list_nodes_test.go | 38 +++---------------- 1 file changed, 5 insertions(+), 33 deletions(-) diff --git a/command/catalog/list/nodes/catalog_list_nodes_test.go b/command/catalog/list/nodes/catalog_list_nodes_test.go index de95da9339..df683fd5b6 100644 --- a/command/catalog/list/nodes/catalog_list_nodes_test.go +++ b/command/catalog/list/nodes/catalog_list_nodes_test.go @@ -20,34 +20,12 @@ func TestCatalogListNodesCommand_Validation(t *testing.T) { ui := cli.NewMockUi() c := New(ui) - cases := map[string]struct { - args []string - output string - }{ - "args": { - []string{"foo"}, - "Too many arguments", - }, + code := c.Run([]string{"foo"}) + if code == 0 { + t.Fatal("expected non-zero exit") } - - for name, tc := range cases { - // Ensure our buffer is always clear - if ui.ErrorWriter != nil { - ui.ErrorWriter.Reset() - } - if ui.OutputWriter != nil { - ui.OutputWriter.Reset() - } - - code := c.Run(tc.args) - if code == 0 { - t.Errorf("%s: expected non-zero exit", name) - } - - output := ui.ErrorWriter.String() - if !strings.Contains(output, tc.output) { - t.Errorf("%s: expected %q to contain %q", name, output, tc.output) - } + if got, want := ui.ErrorWriter.String(), "Too many arguments"; !strings.Contains(got, want) { + t.Fatalf("expected %q to contain %q", got, want) } } @@ -66,7 +44,6 @@ func TestCatalogListNodesCommand_Run(t *testing.T) { if code != 0 { t.Fatalf("bad exit code %d: %s", code, ui.ErrorWriter.String()) } - output := ui.OutputWriter.String() for _, s := range []string{"Node", "ID", "Address", "DC"} { if !strings.Contains(output, s) { @@ -91,7 +68,6 @@ func TestCatalogListNodesCommand_Run(t *testing.T) { if code != 0 { t.Fatalf("bad exit code %d: %s", code, ui.ErrorWriter.String()) } - output := ui.OutputWriter.String() for _, s := range []string{"Node", "ID", "Address", "DC", "TaggedAddresses", "Meta"} { if !strings.Contains(output, s) { @@ -111,7 +87,6 @@ func TestCatalogListNodesCommand_Run(t *testing.T) { if code != 0 { t.Fatalf("bad exit code %d: %s", code, ui.ErrorWriter.String()) } - output := ui.ErrorWriter.String() if expected := "No nodes match the given query"; !strings.Contains(output, expected) { t.Errorf("expected %q to contain %q", output, expected) @@ -129,7 +104,6 @@ func TestCatalogListNodesCommand_Run(t *testing.T) { if code != 0 { t.Fatalf("bad exit code %d: %s", code, ui.ErrorWriter.String()) } - output := ui.OutputWriter.String() if expected := "127.0.0.1"; !strings.Contains(output, expected) { t.Errorf("expected %q to contain %q", output, expected) @@ -147,7 +121,6 @@ func TestCatalogListNodesCommand_Run(t *testing.T) { if code != 0 { t.Fatalf("bad exit code %d: %s", code, ui.ErrorWriter.String()) } - output := ui.OutputWriter.String() if expected := "127.0.0.1"; !strings.Contains(output, expected) { t.Errorf("expected %q to contain %q", output, expected) @@ -165,7 +138,6 @@ func TestCatalogListNodesCommand_Run(t *testing.T) { if code != 0 { t.Fatalf("bad exit code %d: %s", code, ui.ErrorWriter.String()) } - output := ui.ErrorWriter.String() if expected := "No nodes match the given query"; !strings.Contains(output, expected) { t.Errorf("expected %q to contain %q", output, expected)