2019-10-07 20:41:52 +00:00
|
|
|
package command
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2022-03-15 12:42:43 +00:00
|
|
|
"github.com/hashicorp/nomad/ci"
|
2019-10-07 20:41:52 +00:00
|
|
|
"github.com/mitchellh/cli"
|
2022-08-18 13:51:53 +00:00
|
|
|
"github.com/shoenig/test/must"
|
2019-10-07 20:41:52 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestMonitorCommand_Implements(t *testing.T) {
|
2022-03-15 12:42:43 +00:00
|
|
|
ci.Parallel(t)
|
2019-10-07 20:41:52 +00:00
|
|
|
var _ cli.Command = &MonitorCommand{}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestMonitorCommand_Fails(t *testing.T) {
|
2022-03-15 12:42:43 +00:00
|
|
|
ci.Parallel(t)
|
2019-12-10 12:03:37 +00:00
|
|
|
srv, _, url := testServer(t, false, nil)
|
2022-08-18 13:51:53 +00:00
|
|
|
defer stopTestAgent(srv)
|
2019-10-07 20:41:52 +00:00
|
|
|
|
2020-10-05 14:07:41 +00:00
|
|
|
ui := cli.NewMockUi()
|
2019-10-07 20:41:52 +00:00
|
|
|
cmd := &MonitorCommand{Meta: Meta{Ui: ui}}
|
|
|
|
|
|
|
|
// Fails on misuse
|
2022-08-18 13:51:53 +00:00
|
|
|
code := cmd.Run([]string{"some", "bad", "args"})
|
|
|
|
must.One(t, code)
|
|
|
|
|
|
|
|
out := ui.ErrorWriter.String()
|
|
|
|
must.StrContains(t, out, commandErrorText(cmd))
|
2019-10-07 20:41:52 +00:00
|
|
|
|
|
|
|
ui.ErrorWriter.Reset()
|
|
|
|
|
2022-08-18 13:51:53 +00:00
|
|
|
code = cmd.Run([]string{"-address=nope"})
|
|
|
|
must.One(t, code)
|
2019-12-10 12:03:37 +00:00
|
|
|
|
|
|
|
// Fails on nonexistent node
|
2022-08-18 13:51:53 +00:00
|
|
|
code = cmd.Run([]string{"-address=" + url, "-node-id=12345678-abcd-efab-cdef-123456789abc"})
|
|
|
|
must.One(t, code)
|
|
|
|
|
|
|
|
out = ui.ErrorWriter.String()
|
|
|
|
must.StrContains(t, out, "No node(s) with prefix")
|
2019-10-07 20:41:52 +00:00
|
|
|
}
|