Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

command: error when no node is found for monitor #6828

Merged
merged 1 commit into from
Dec 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions command/agent_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ func (c *MonitorCommand) Run(args []string) int {
return 1
}

if len(nodes) == 0 {
c.Ui.Error(fmt.Sprintf("No node(s) with prefix or id %q found", nodeID))
return 1
}

if len(nodes) > 1 {
out := formatNodeStubList(nodes, false)
c.Ui.Output(fmt.Sprintf("Prefix matched multiple nodes\n\n%s", out))
Expand Down
11 changes: 10 additions & 1 deletion command/agent_monitor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func TestMonitorCommand_Implements(t *testing.T) {

func TestMonitorCommand_Fails(t *testing.T) {
t.Parallel()
srv, _, _ := testServer(t, false, nil)
srv, _, url := testServer(t, false, nil)
defer srv.Shutdown()

ui := new(cli.MockUi)
Expand All @@ -33,4 +33,13 @@ func TestMonitorCommand_Fails(t *testing.T) {
if code := cmd.Run([]string{"-address=nope"}); code != 1 {
t.Fatalf("exepected exit code 1, got: %d", code)
}

// Fails on nonexistent node
if code := cmd.Run([]string{"-address=" + url, "-node-id=12345678-abcd-efab-cdef-123456789abc"}); code != 1 {
t.Fatalf("expected exit 1, got: %d", code)
}
if out := ui.ErrorWriter.String(); !strings.Contains(out, "No node(s) with prefix") {
t.Fatalf("expected not found error, got: %s", out)
}
ui.ErrorWriter.Reset()
}