mirror of https://github.com/status-im/consul.git
116 lines
2.3 KiB
Go
116 lines
2.3 KiB
Go
package members
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/hashicorp/consul/agent"
|
|
"github.com/mitchellh/cli"
|
|
)
|
|
|
|
func TestMembersCommandRun(t *testing.T) {
|
|
t.Parallel()
|
|
a := agent.NewTestAgent(t.Name(), ``)
|
|
defer a.Shutdown()
|
|
|
|
ui := cli.NewMockUi()
|
|
c := New(ui)
|
|
c.flags.SetOutput(ui.ErrorWriter)
|
|
|
|
args := []string{"-http-addr=" + a.HTTPAddr()}
|
|
|
|
code := c.Run(args)
|
|
if code != 0 {
|
|
t.Fatalf("bad: %d. %#v", code, ui.ErrorWriter.String())
|
|
}
|
|
|
|
// Name
|
|
if !strings.Contains(ui.OutputWriter.String(), a.Config.NodeName) {
|
|
t.Fatalf("bad: %#v", ui.OutputWriter.String())
|
|
}
|
|
|
|
// 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())
|
|
}
|
|
}
|
|
|
|
func TestMembersCommandRun_WAN(t *testing.T) {
|
|
t.Parallel()
|
|
a := agent.NewTestAgent(t.Name(), ``)
|
|
defer a.Shutdown()
|
|
|
|
ui := cli.NewMockUi()
|
|
c := New(ui)
|
|
c.flags.SetOutput(ui.ErrorWriter)
|
|
|
|
args := []string{"-http-addr=" + a.HTTPAddr(), "-wan"}
|
|
|
|
code := c.Run(args)
|
|
if code != 0 {
|
|
t.Fatalf("bad: %d. %#v", code, ui.ErrorWriter.String())
|
|
}
|
|
|
|
if !strings.Contains(ui.OutputWriter.String(), fmt.Sprintf("%d", a.Config.SerfPortWAN)) {
|
|
t.Fatalf("bad: %#v", ui.OutputWriter.String())
|
|
}
|
|
}
|
|
|
|
func TestMembersCommandRun_statusFilter(t *testing.T) {
|
|
t.Parallel()
|
|
a := agent.NewTestAgent(t.Name(), ``)
|
|
defer a.Shutdown()
|
|
|
|
ui := cli.NewMockUi()
|
|
c := New(ui)
|
|
c.flags.SetOutput(ui.ErrorWriter)
|
|
|
|
args := []string{
|
|
"-http-addr=" + a.HTTPAddr(),
|
|
"-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(), a.Config.NodeName) {
|
|
t.Fatalf("bad: %#v", ui.OutputWriter.String())
|
|
}
|
|
}
|
|
|
|
func TestMembersCommandRun_statusFilter_failed(t *testing.T) {
|
|
t.Parallel()
|
|
a := agent.NewTestAgent(t.Name(), ``)
|
|
defer a.Shutdown()
|
|
|
|
ui := cli.NewMockUi()
|
|
c := New(ui)
|
|
c.flags.SetOutput(ui.ErrorWriter)
|
|
|
|
args := []string{
|
|
"-http-addr=" + a.HTTPAddr(),
|
|
"-status=(fail|left)",
|
|
}
|
|
|
|
code := c.Run(args)
|
|
if code == 1 {
|
|
t.Fatalf("bad: %d. %#v", code, ui.ErrorWriter.String())
|
|
}
|
|
|
|
if strings.Contains(ui.OutputWriter.String(), a.Config.NodeName) {
|
|
t.Fatalf("bad: %#v", ui.OutputWriter.String())
|
|
}
|
|
|
|
if code != 2 {
|
|
t.Fatalf("bad: %d", code)
|
|
}
|
|
}
|