Skip to content

Commit

Permalink
Fix failing test and add tests.
Browse files Browse the repository at this point in the history
Signed-off-by: Shishir Mahajan <[email protected]>
  • Loading branch information
shishir-a412ed committed Apr 4, 2022
1 parent 1615457 commit 5a0b133
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 12 deletions.
24 changes: 12 additions & 12 deletions command/node_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,18 @@ func (c *NodeStatusCommand) Run(args []string) int {
return 1
}

// If output format is specified, format and output the node data list
if c.json || len(c.tmpl) > 0 {
out, err := Format(c.json, c.tmpl, nodes)
if err != nil {
c.Ui.Error(err.Error())
return 1
}

c.Ui.Output(out)
return 0
}

// Return nothing if no nodes found
if len(nodes) == 0 {
return 0
Expand All @@ -203,18 +215,6 @@ func (c *NodeStatusCommand) Run(args []string) int {
return 0
}

// If output format is specified, format and output the node data list
if c.json || len(c.tmpl) > 0 {
out, err := Format(c.json, c.tmpl, nodes)
if err != nil {
c.Ui.Error(err.Error())
return 1
}

c.Ui.Output(out)
return 0
}

out[0] = "ID|DC|Name|Class|"

if c.os {
Expand Down
20 changes: 20 additions & 0 deletions command/node_status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,26 @@ func TestNodeStatusCommand_Fails(t *testing.T) {
if out := ui.ErrorWriter.String(); !strings.Contains(out, "Both json and template formatting are not allowed") {
t.Fatalf("expected getting formatter error, got: %s", out)
}
ui.ErrorWriter.Reset()

// Fail if -quiet is passed with -verbose
if code := cmd.Run([]string{"-address=" + url, "-quiet", "-verbose"}); code != 1 {
t.Fatalf("expected exit 1, got: %d", code)
}

if out := ui.ErrorWriter.String(); !strings.Contains(out, "-quiet cannot be used with -verbose or -json") {
t.Fatalf("expected getting formatter error, got: %s", out)
}
ui.ErrorWriter.Reset()

// Fail if -quiet is passed with -json
if code := cmd.Run([]string{"-address=" + url, "-quiet", "-json"}); code != 1 {
t.Fatalf("expected exit 1, got: %d", code)
}

if out := ui.ErrorWriter.String(); !strings.Contains(out, "-quiet cannot be used with -verbose or -json") {
t.Fatalf("expected getting formatter error, got: %s", out)
}
}

func TestNodeStatusCommand_AutocompleteArgs(t *testing.T) {
Expand Down

0 comments on commit 5a0b133

Please sign in to comment.