2014-08-21 16:08:21 -07:00
|
|
|
package command
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
"testing"
|
2017-02-09 20:36:01 -05:00
|
|
|
|
2017-05-22 13:59:36 +02:00
|
|
|
"github.com/hashicorp/consul/command/agent"
|
2017-02-09 20:36:01 -05:00
|
|
|
"github.com/hashicorp/consul/command/base"
|
|
|
|
"github.com/mitchellh/cli"
|
2014-08-21 16:08:21 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestWatchCommand_implements(t *testing.T) {
|
2017-05-22 20:18:53 +02:00
|
|
|
t.Parallel()
|
2014-08-21 16:08:21 -07:00
|
|
|
var _ cli.Command = &WatchCommand{}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestWatchCommandRun(t *testing.T) {
|
2017-05-22 20:18:53 +02:00
|
|
|
t.Parallel()
|
2017-05-22 13:59:36 +02:00
|
|
|
a := agent.NewTestAgent(t.Name(), nil)
|
|
|
|
defer a.Shutdown()
|
2014-08-21 16:08:21 -07:00
|
|
|
|
2017-05-23 01:26:30 +02:00
|
|
|
ui := cli.NewMockUi()
|
2017-02-09 20:36:01 -05:00
|
|
|
c := &WatchCommand{
|
|
|
|
Command: base.Command{
|
2017-04-20 17:02:42 -07:00
|
|
|
UI: ui,
|
2017-02-09 20:36:01 -05:00
|
|
|
Flags: base.FlagSetHTTP,
|
|
|
|
},
|
|
|
|
}
|
2017-05-22 13:59:36 +02:00
|
|
|
args := []string{"-http-addr=" + a.HTTPAddr(), "-type=nodes"}
|
2014-08-21 16:08:21 -07:00
|
|
|
|
|
|
|
code := c.Run(args)
|
|
|
|
if code != 0 {
|
|
|
|
t.Fatalf("bad: %d. %#v", code, ui.ErrorWriter.String())
|
|
|
|
}
|
|
|
|
|
2017-05-22 13:59:36 +02:00
|
|
|
if !strings.Contains(ui.OutputWriter.String(), a.Config.NodeName) {
|
2014-08-21 16:08:21 -07:00
|
|
|
t.Fatalf("bad: %#v", ui.OutputWriter.String())
|
|
|
|
}
|
|
|
|
}
|