diff --git a/command/util_test.go b/command/util_test.go index 8d492b1733..0366f760bb 100644 --- a/command/util_test.go +++ b/command/util_test.go @@ -22,16 +22,19 @@ func init() { } type agentWrapper struct { - dir string - config *agent.Config - agent *agent.Agent - rpc *agent.AgentRPC - addr string + dir string + config *agent.Config + agent *agent.Agent + rpc *agent.AgentRPC + http *agent.HTTPServer + addr string + httpAddr string } func (a *agentWrapper) Shutdown() { a.rpc.Shutdown() a.agent.Shutdown() + a.http.Shutdown() os.RemoveAll(a.dir) } @@ -59,12 +62,22 @@ func testAgent(t *testing.T) *agentWrapper { } rpc := agent.NewAgentRPC(a, l, mult, lw) + + httpAddr := fmt.Sprintf("127.0.0.1:%d", conf.Ports.HTTP) + http, err := agent.NewHTTPServer(a, "", false, os.Stderr, httpAddr) + if err != nil { + os.RemoveAll(dir) + t.Fatalf(fmt.Sprintf("err: %v", err)) + } + return &agentWrapper{ - dir: dir, - config: conf, - agent: a, - rpc: rpc, - addr: l.Addr().String(), + dir: dir, + config: conf, + agent: a, + rpc: rpc, + http: http, + addr: l.Addr().String(), + httpAddr: httpAddr, } } diff --git a/command/watch_test.go b/command/watch_test.go new file mode 100644 index 0000000000..eaa9376d5a --- /dev/null +++ b/command/watch_test.go @@ -0,0 +1,29 @@ +package command + +import ( + "github.com/mitchellh/cli" + "strings" + "testing" +) + +func TestWatchCommand_implements(t *testing.T) { + var _ cli.Command = &WatchCommand{} +} + +func TestWatchCommandRun(t *testing.T) { + a1 := testAgent(t) + defer a1.Shutdown() + + ui := new(cli.MockUi) + c := &WatchCommand{Ui: ui} + args := []string{"-http-addr=" + a1.httpAddr, "-type=nodes"} + + code := c.Run(args) + if code != 0 { + t.Fatalf("bad: %d. %#v", code, ui.ErrorWriter.String()) + } + + if !strings.Contains(ui.OutputWriter.String(), a1.config.NodeName) { + t.Fatalf("bad: %#v", ui.OutputWriter.String()) + } +}