1package command
2
3import (
4	"strings"
5	"testing"
6
7	"github.com/mitchellh/cli"
8)
9
10func TestMonitorCommand_Implements(t *testing.T) {
11	t.Parallel()
12	var _ cli.Command = &MonitorCommand{}
13}
14
15func TestMonitorCommand_Fails(t *testing.T) {
16	t.Parallel()
17	srv, _, url := testServer(t, false, nil)
18	defer srv.Shutdown()
19
20	ui := new(cli.MockUi)
21	cmd := &MonitorCommand{Meta: Meta{Ui: ui}}
22
23	// Fails on misuse
24	if code := cmd.Run([]string{"some", "bad", "args"}); code != 1 {
25		t.Fatalf("exepected exit code 1, got: %d", code)
26	}
27	if out := ui.ErrorWriter.String(); !strings.Contains(out, commandErrorText(cmd)) {
28		t.Fatalf("expected help output, got: %s", out)
29	}
30
31	ui.ErrorWriter.Reset()
32
33	if code := cmd.Run([]string{"-address=nope"}); code != 1 {
34		t.Fatalf("exepected exit code 1, got: %d", code)
35	}
36
37	// Fails on nonexistent node
38	if code := cmd.Run([]string{"-address=" + url, "-node-id=12345678-abcd-efab-cdef-123456789abc"}); code != 1 {
39		t.Fatalf("expected exit 1, got: %d", code)
40	}
41	if out := ui.ErrorWriter.String(); !strings.Contains(out, "No node(s) with prefix") {
42		t.Fatalf("expected not found error, got: %s", out)
43	}
44	ui.ErrorWriter.Reset()
45}
46