2023-04-10 15:36:59 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
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-12-21 14:23:58 +00:00
|
|
|
defer srv.Shutdown()
|
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")
|
2023-10-20 07:35:54 +00:00
|
|
|
|
|
|
|
ui.ErrorWriter.Reset()
|
|
|
|
|
|
|
|
// Fails on passing a log-include-location flag which cannot be parsed.
|
|
|
|
code = cmd.Run([]string{"-address=" + url, "-log-include-location=maybe"})
|
|
|
|
must.One(t, code)
|
|
|
|
|
|
|
|
out = ui.ErrorWriter.String()
|
|
|
|
must.StrContains(t, out, `invalid boolean value "maybe" for -log-include-location`)
|
2019-10-07 20:41:52 +00:00
|
|
|
}
|