mirror of
https://github.com/kemko/nomad.git
synced 2026-01-01 16:05:42 +03:00
cli: Ensure JSON flag is respected in autopilot health command. (#24655)
This commit is contained in:
3
.changelog/24655.txt
Normal file
3
.changelog/24655.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
```release-note:bug
|
||||
cli: Ensure the `operator autopilot health` command only outputs JSON when the `json` flag is supplied
|
||||
```
|
||||
@@ -59,10 +59,10 @@ func (c *OperatorAutopilotHealthCommand) Run(args []string) int {
|
||||
return 1
|
||||
}
|
||||
c.Ui.Output(string(bytes))
|
||||
} else {
|
||||
c.Ui.Output(formatAutopilotState(state))
|
||||
}
|
||||
|
||||
c.Ui.Output(formatAutopilotState(state))
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
|
||||
@@ -4,8 +4,10 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/nomad/api"
|
||||
"github.com/hashicorp/nomad/ci"
|
||||
"github.com/mitchellh/cli"
|
||||
"github.com/shoenig/test/must"
|
||||
@@ -31,3 +33,24 @@ func TestOperatorAutopilotStateCommand(t *testing.T) {
|
||||
out := ui.OutputWriter.String()
|
||||
must.StrContains(t, out, "Healthy")
|
||||
}
|
||||
|
||||
func TestOperatorAutopilotStateCommand_JSON(t *testing.T) {
|
||||
ci.Parallel(t)
|
||||
s, _, addr := testServer(t, false, nil)
|
||||
defer s.Shutdown()
|
||||
|
||||
ui := cli.NewMockUi()
|
||||
c := &OperatorAutopilotHealthCommand{Meta: Meta{Ui: ui}}
|
||||
args := []string{"-address=" + addr, "-json"}
|
||||
|
||||
code := c.Run(args)
|
||||
must.Eq(t, 0, code, must.Sprintf("got error for exit code: %v", ui.ErrorWriter.String()))
|
||||
|
||||
// Attempt to unmarshal the data which tests that the output is JSON and
|
||||
// peak into the data, checking that healthy is an expected and no-default
|
||||
// value.
|
||||
operatorHealthyReply := api.OperatorHealthReply{}
|
||||
|
||||
must.NoError(t, json.Unmarshal(ui.OutputWriter.Bytes(), &operatorHealthyReply))
|
||||
must.True(t, operatorHealthyReply.Healthy)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user