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()
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)