mirror of https://github.com/hashicorp/consul
Gives RTT class a more Go-like name.
parent
99cfbb8a47
commit
439110f384
|
@ -10,13 +10,13 @@ import (
|
||||||
"github.com/mitchellh/cli"
|
"github.com/mitchellh/cli"
|
||||||
)
|
)
|
||||||
|
|
||||||
// RttCommand is a Command implementation that allows users to query the
|
// RTTCommand is a Command implementation that allows users to query the
|
||||||
// estimated round trip time between nodes using network coordinates.
|
// estimated round trip time between nodes using network coordinates.
|
||||||
type RttCommand struct {
|
type RTTCommand struct {
|
||||||
Ui cli.Ui
|
Ui cli.Ui
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *RttCommand) Help() string {
|
func (c *RTTCommand) Help() string {
|
||||||
helpText := `
|
helpText := `
|
||||||
Usage: consul rtt [options] node1 [node2]
|
Usage: consul rtt [options] node1 [node2]
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ Options:
|
||||||
return strings.TrimSpace(helpText)
|
return strings.TrimSpace(helpText)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *RttCommand) Run(args []string) int {
|
func (c *RTTCommand) Run(args []string) int {
|
||||||
var wan bool
|
var wan bool
|
||||||
|
|
||||||
cmdFlags := flag.NewFlagSet("rtt", flag.ContinueOnError)
|
cmdFlags := flag.NewFlagSet("rtt", flag.ContinueOnError)
|
||||||
|
@ -56,7 +56,7 @@ func (c *RttCommand) Run(args []string) int {
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
// They must provide a pair of nodes.
|
// They must provide at least one node.
|
||||||
nodes := cmdFlags.Args()
|
nodes := cmdFlags.Args()
|
||||||
if len(nodes) < 1 || len(nodes) > 2 {
|
if len(nodes) < 1 || len(nodes) > 2 {
|
||||||
c.Ui.Error("One or two node names must be specified")
|
c.Ui.Error("One or two node names must be specified")
|
||||||
|
@ -179,6 +179,6 @@ SHOW_RTT:
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *RttCommand) Synopsis() string {
|
func (c *RTTCommand) Synopsis() string {
|
||||||
return "Estimates network round trip time between nodes"
|
return "Estimates network round trip time between nodes"
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,13 +12,13 @@ import (
|
||||||
"github.com/mitchellh/cli"
|
"github.com/mitchellh/cli"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestRttCommand_Implements(t *testing.T) {
|
func TestRTTCommand_Implements(t *testing.T) {
|
||||||
var _ cli.Command = &RttCommand{}
|
var _ cli.Command = &RTTCommand{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRttCommand_Run_BadArgs(t *testing.T) {
|
func TestRTTCommand_Run_BadArgs(t *testing.T) {
|
||||||
ui := new(cli.MockUi)
|
ui := new(cli.MockUi)
|
||||||
c := &RttCommand{Ui: ui}
|
c := &RTTCommand{Ui: ui}
|
||||||
|
|
||||||
if code := c.Run([]string{}); code != 1 {
|
if code := c.Run([]string{}); code != 1 {
|
||||||
t.Fatalf("expected return code 1, got %d", code)
|
t.Fatalf("expected return code 1, got %d", code)
|
||||||
|
@ -41,7 +41,7 @@ func TestRttCommand_Run_BadArgs(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRttCommand_Run_LAN(t *testing.T) {
|
func TestRTTCommand_Run_LAN(t *testing.T) {
|
||||||
updatePeriod := 10 * time.Millisecond
|
updatePeriod := 10 * time.Millisecond
|
||||||
a := testAgentWithConfig(t, func(c *agent.Config) {
|
a := testAgentWithConfig(t, func(c *agent.Config) {
|
||||||
c.ConsulConfig.CoordinateUpdatePeriod = updatePeriod
|
c.ConsulConfig.CoordinateUpdatePeriod = updatePeriod
|
||||||
|
@ -80,7 +80,7 @@ func TestRttCommand_Run_LAN(t *testing.T) {
|
||||||
// Try two known nodes.
|
// Try two known nodes.
|
||||||
{
|
{
|
||||||
ui := new(cli.MockUi)
|
ui := new(cli.MockUi)
|
||||||
c := &RttCommand{Ui: ui}
|
c := &RTTCommand{Ui: ui}
|
||||||
args := []string{
|
args := []string{
|
||||||
"-http-addr=" + a.httpAddr,
|
"-http-addr=" + a.httpAddr,
|
||||||
a.config.NodeName,
|
a.config.NodeName,
|
||||||
|
@ -101,7 +101,7 @@ func TestRttCommand_Run_LAN(t *testing.T) {
|
||||||
// Default to the agent's node.
|
// Default to the agent's node.
|
||||||
{
|
{
|
||||||
ui := new(cli.MockUi)
|
ui := new(cli.MockUi)
|
||||||
c := &RttCommand{Ui: ui}
|
c := &RTTCommand{Ui: ui}
|
||||||
args := []string{
|
args := []string{
|
||||||
"-http-addr=" + a.httpAddr,
|
"-http-addr=" + a.httpAddr,
|
||||||
"dogs",
|
"dogs",
|
||||||
|
@ -121,7 +121,7 @@ func TestRttCommand_Run_LAN(t *testing.T) {
|
||||||
// Try an unknown node.
|
// Try an unknown node.
|
||||||
{
|
{
|
||||||
ui := new(cli.MockUi)
|
ui := new(cli.MockUi)
|
||||||
c := &RttCommand{Ui: ui}
|
c := &RTTCommand{Ui: ui}
|
||||||
args := []string{
|
args := []string{
|
||||||
"-http-addr=" + a.httpAddr,
|
"-http-addr=" + a.httpAddr,
|
||||||
a.config.NodeName,
|
a.config.NodeName,
|
||||||
|
@ -134,7 +134,7 @@ func TestRttCommand_Run_LAN(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRttCommand_Run_WAN(t *testing.T) {
|
func TestRTTCommand_Run_WAN(t *testing.T) {
|
||||||
a := testAgent(t)
|
a := testAgent(t)
|
||||||
defer a.Shutdown()
|
defer a.Shutdown()
|
||||||
waitForLeader(t, a.httpAddr)
|
waitForLeader(t, a.httpAddr)
|
||||||
|
@ -145,7 +145,7 @@ func TestRttCommand_Run_WAN(t *testing.T) {
|
||||||
// node with itself.
|
// node with itself.
|
||||||
{
|
{
|
||||||
ui := new(cli.MockUi)
|
ui := new(cli.MockUi)
|
||||||
c := &RttCommand{Ui: ui}
|
c := &RTTCommand{Ui: ui}
|
||||||
args := []string{
|
args := []string{
|
||||||
"-wan",
|
"-wan",
|
||||||
"-http-addr=" + a.httpAddr,
|
"-http-addr=" + a.httpAddr,
|
||||||
|
@ -166,7 +166,7 @@ func TestRttCommand_Run_WAN(t *testing.T) {
|
||||||
// Default to the agent's node.
|
// Default to the agent's node.
|
||||||
{
|
{
|
||||||
ui := new(cli.MockUi)
|
ui := new(cli.MockUi)
|
||||||
c := &RttCommand{Ui: ui}
|
c := &RTTCommand{Ui: ui}
|
||||||
args := []string{
|
args := []string{
|
||||||
"-wan",
|
"-wan",
|
||||||
"-http-addr=" + a.httpAddr,
|
"-http-addr=" + a.httpAddr,
|
||||||
|
@ -186,7 +186,7 @@ func TestRttCommand_Run_WAN(t *testing.T) {
|
||||||
// Try an unknown node.
|
// Try an unknown node.
|
||||||
{
|
{
|
||||||
ui := new(cli.MockUi)
|
ui := new(cli.MockUi)
|
||||||
c := &RttCommand{Ui: ui}
|
c := &RTTCommand{Ui: ui}
|
||||||
args := []string{
|
args := []string{
|
||||||
"-wan",
|
"-wan",
|
||||||
"-http-addr=" + a.httpAddr,
|
"-http-addr=" + a.httpAddr,
|
||||||
|
|
|
@ -115,7 +115,7 @@ func init() {
|
||||||
},
|
},
|
||||||
|
|
||||||
"rtt": func() (cli.Command, error) {
|
"rtt": func() (cli.Command, error) {
|
||||||
return &command.RttCommand{
|
return &command.RTTCommand{
|
||||||
Ui: ui,
|
Ui: ui,
|
||||||
}, nil
|
}, nil
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue