2013-12-31 21:06:33 +00:00
|
|
|
package command
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"github.com/mitchellh/cli"
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestMembersCommand_implements(t *testing.T) {
|
|
|
|
var _ cli.Command = &MembersCommand{}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestMembersCommandRun(t *testing.T) {
|
|
|
|
a1 := testAgent(t)
|
|
|
|
defer a1.Shutdown()
|
|
|
|
|
|
|
|
ui := new(cli.MockUi)
|
|
|
|
c := &MembersCommand{Ui: ui}
|
|
|
|
args := []string{"-rpc-addr=" + a1.addr}
|
|
|
|
|
|
|
|
code := c.Run(args)
|
|
|
|
if code != 0 {
|
|
|
|
t.Fatalf("bad: %d. %#v", code, ui.ErrorWriter.String())
|
|
|
|
}
|
|
|
|
|
2015-05-15 21:26:23 +00:00
|
|
|
// Name
|
2013-12-31 21:06:33 +00:00
|
|
|
if !strings.Contains(ui.OutputWriter.String(), a1.config.NodeName) {
|
|
|
|
t.Fatalf("bad: %#v", ui.OutputWriter.String())
|
|
|
|
}
|
2015-05-15 21:26:23 +00:00
|
|
|
|
|
|
|
// Agent type
|
|
|
|
if !strings.Contains(ui.OutputWriter.String(), "server") {
|
|
|
|
t.Fatalf("bad: %#v", ui.OutputWriter.String())
|
|
|
|
}
|
|
|
|
|
|
|
|
// Datacenter
|
|
|
|
if !strings.Contains(ui.OutputWriter.String(), "dc1") {
|
|
|
|
t.Fatalf("bad: %#v", ui.OutputWriter.String())
|
|
|
|
}
|
2013-12-31 21:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestMembersCommandRun_WAN(t *testing.T) {
|
|
|
|
a1 := testAgent(t)
|
|
|
|
defer a1.Shutdown()
|
|
|
|
|
|
|
|
ui := new(cli.MockUi)
|
|
|
|
c := &MembersCommand{Ui: ui}
|
|
|
|
args := []string{"-rpc-addr=" + a1.addr, "-wan"}
|
|
|
|
|
|
|
|
code := c.Run(args)
|
|
|
|
if code != 0 {
|
|
|
|
t.Fatalf("bad: %d. %#v", code, ui.ErrorWriter.String())
|
|
|
|
}
|
|
|
|
|
2014-04-11 23:34:29 +00:00
|
|
|
if !strings.Contains(ui.OutputWriter.String(), fmt.Sprintf("%d", a1.config.Ports.SerfWan)) {
|
2013-12-31 21:06:33 +00:00
|
|
|
t.Fatalf("bad: %#v", ui.OutputWriter.String())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestMembersCommandRun_statusFilter(t *testing.T) {
|
|
|
|
a1 := testAgent(t)
|
|
|
|
defer a1.Shutdown()
|
|
|
|
|
|
|
|
ui := new(cli.MockUi)
|
|
|
|
c := &MembersCommand{Ui: ui}
|
|
|
|
args := []string{
|
|
|
|
"-rpc-addr=" + a1.addr,
|
|
|
|
"-status=a.*e",
|
|
|
|
}
|
|
|
|
|
|
|
|
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())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestMembersCommandRun_statusFilter_failed(t *testing.T) {
|
|
|
|
a1 := testAgent(t)
|
|
|
|
defer a1.Shutdown()
|
|
|
|
|
|
|
|
ui := new(cli.MockUi)
|
|
|
|
c := &MembersCommand{Ui: ui}
|
|
|
|
args := []string{
|
|
|
|
"-rpc-addr=" + a1.addr,
|
|
|
|
"-status=(fail|left)",
|
|
|
|
}
|
|
|
|
|
|
|
|
code := c.Run(args)
|
2014-05-04 09:54:45 +00:00
|
|
|
if code == 1 {
|
2013-12-31 21:06:33 +00:00
|
|
|
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())
|
|
|
|
}
|
2014-05-04 09:54:45 +00:00
|
|
|
|
|
|
|
if code != 2 {
|
|
|
|
t.Fatalf("bad: %d", code)
|
|
|
|
}
|
2013-12-31 21:06:33 +00:00
|
|
|
}
|