commands: cleanup catalog list nodes tests

This commit is contained in:
Frank Schroeder 2017-10-17 13:46:25 +02:00 committed by Frank Schröder
parent 7d7281ab54
commit 915034da78
1 changed files with 5 additions and 33 deletions

View File

@ -20,34 +20,12 @@ func TestCatalogListNodesCommand_Validation(t *testing.T) {
ui := cli.NewMockUi() ui := cli.NewMockUi()
c := New(ui) c := New(ui)
cases := map[string]struct { code := c.Run([]string{"foo"})
args []string if code == 0 {
output string t.Fatal("expected non-zero exit")
}{
"args": {
[]string{"foo"},
"Too many arguments",
},
} }
if got, want := ui.ErrorWriter.String(), "Too many arguments"; !strings.Contains(got, want) {
for name, tc := range cases { t.Fatalf("expected %q to contain %q", got, want)
// 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)
}
} }
} }
@ -66,7 +44,6 @@ func TestCatalogListNodesCommand_Run(t *testing.T) {
if code != 0 { if code != 0 {
t.Fatalf("bad exit code %d: %s", code, ui.ErrorWriter.String()) t.Fatalf("bad exit code %d: %s", code, ui.ErrorWriter.String())
} }
output := ui.OutputWriter.String() output := ui.OutputWriter.String()
for _, s := range []string{"Node", "ID", "Address", "DC"} { for _, s := range []string{"Node", "ID", "Address", "DC"} {
if !strings.Contains(output, s) { if !strings.Contains(output, s) {
@ -91,7 +68,6 @@ func TestCatalogListNodesCommand_Run(t *testing.T) {
if code != 0 { if code != 0 {
t.Fatalf("bad exit code %d: %s", code, ui.ErrorWriter.String()) t.Fatalf("bad exit code %d: %s", code, ui.ErrorWriter.String())
} }
output := ui.OutputWriter.String() output := ui.OutputWriter.String()
for _, s := range []string{"Node", "ID", "Address", "DC", "TaggedAddresses", "Meta"} { for _, s := range []string{"Node", "ID", "Address", "DC", "TaggedAddresses", "Meta"} {
if !strings.Contains(output, s) { if !strings.Contains(output, s) {
@ -111,7 +87,6 @@ func TestCatalogListNodesCommand_Run(t *testing.T) {
if code != 0 { if code != 0 {
t.Fatalf("bad exit code %d: %s", code, ui.ErrorWriter.String()) t.Fatalf("bad exit code %d: %s", code, ui.ErrorWriter.String())
} }
output := ui.ErrorWriter.String() output := ui.ErrorWriter.String()
if expected := "No nodes match the given query"; !strings.Contains(output, expected) { if expected := "No nodes match the given query"; !strings.Contains(output, expected) {
t.Errorf("expected %q to contain %q", output, expected) t.Errorf("expected %q to contain %q", output, expected)
@ -129,7 +104,6 @@ func TestCatalogListNodesCommand_Run(t *testing.T) {
if code != 0 { if code != 0 {
t.Fatalf("bad exit code %d: %s", code, ui.ErrorWriter.String()) t.Fatalf("bad exit code %d: %s", code, ui.ErrorWriter.String())
} }
output := ui.OutputWriter.String() output := ui.OutputWriter.String()
if expected := "127.0.0.1"; !strings.Contains(output, expected) { if expected := "127.0.0.1"; !strings.Contains(output, expected) {
t.Errorf("expected %q to contain %q", output, expected) t.Errorf("expected %q to contain %q", output, expected)
@ -147,7 +121,6 @@ func TestCatalogListNodesCommand_Run(t *testing.T) {
if code != 0 { if code != 0 {
t.Fatalf("bad exit code %d: %s", code, ui.ErrorWriter.String()) t.Fatalf("bad exit code %d: %s", code, ui.ErrorWriter.String())
} }
output := ui.OutputWriter.String() output := ui.OutputWriter.String()
if expected := "127.0.0.1"; !strings.Contains(output, expected) { if expected := "127.0.0.1"; !strings.Contains(output, expected) {
t.Errorf("expected %q to contain %q", output, expected) t.Errorf("expected %q to contain %q", output, expected)
@ -165,7 +138,6 @@ func TestCatalogListNodesCommand_Run(t *testing.T) {
if code != 0 { if code != 0 {
t.Fatalf("bad exit code %d: %s", code, ui.ErrorWriter.String()) t.Fatalf("bad exit code %d: %s", code, ui.ErrorWriter.String())
} }
output := ui.ErrorWriter.String() output := ui.ErrorWriter.String()
if expected := "No nodes match the given query"; !strings.Contains(output, expected) { if expected := "No nodes match the given query"; !strings.Contains(output, expected) {
t.Errorf("expected %q to contain %q", output, expected) t.Errorf("expected %q to contain %q", output, expected)