2017-02-15 21:30:07 +00:00
|
|
|
package command
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
|
2017-05-22 11:59:36 +00:00
|
|
|
"github.com/hashicorp/consul/command/agent"
|
2017-02-15 21:30:07 +00:00
|
|
|
"github.com/hashicorp/consul/command/base"
|
|
|
|
"github.com/mitchellh/cli"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestOperator_Raft_RemovePeer_Implements(t *testing.T) {
|
2017-05-22 18:18:53 +00:00
|
|
|
t.Parallel()
|
2017-02-15 21:30:07 +00:00
|
|
|
var _ cli.Command = &OperatorRaftRemoveCommand{}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestOperator_Raft_RemovePeer(t *testing.T) {
|
2017-05-22 18:18:53 +00:00
|
|
|
t.Parallel()
|
2017-05-22 11:59:36 +00:00
|
|
|
a := agent.NewTestAgent(t.Name(), nil)
|
|
|
|
defer a.Shutdown()
|
2017-02-15 21:30:07 +00:00
|
|
|
|
|
|
|
// Test the legacy mode with 'consul operator raft -remove-peer'
|
|
|
|
{
|
|
|
|
ui, c := testOperatorRaftCommand(t)
|
2017-05-22 11:59:36 +00:00
|
|
|
args := []string{"-http-addr=" + a.HTTPAddr(), "-remove-peer", "-address=nope"}
|
2017-02-15 21:30:07 +00:00
|
|
|
|
|
|
|
code := c.Run(args)
|
|
|
|
if code != 1 {
|
|
|
|
t.Fatalf("bad: %d. %#v", code, ui.ErrorWriter.String())
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we get this error, it proves we sent the address all they through.
|
|
|
|
output := strings.TrimSpace(ui.ErrorWriter.String())
|
|
|
|
if !strings.Contains(output, "address \"nope\" was not found in the Raft configuration") {
|
|
|
|
t.Fatalf("bad: %s", output)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test the remove-peer subcommand directly
|
|
|
|
{
|
|
|
|
ui := new(cli.MockUi)
|
|
|
|
c := OperatorRaftRemoveCommand{
|
|
|
|
Command: base.Command{
|
2017-04-21 00:02:42 +00:00
|
|
|
UI: ui,
|
2017-02-15 21:30:07 +00:00
|
|
|
Flags: base.FlagSetHTTP,
|
|
|
|
},
|
|
|
|
}
|
2017-05-22 11:59:36 +00:00
|
|
|
args := []string{"-http-addr=" + a.HTTPAddr(), "-address=nope"}
|
2017-02-15 21:30:07 +00:00
|
|
|
|
|
|
|
code := c.Run(args)
|
|
|
|
if code != 1 {
|
|
|
|
t.Fatalf("bad: %d. %#v", code, ui.ErrorWriter.String())
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we get this error, it proves we sent the address all they through.
|
|
|
|
output := strings.TrimSpace(ui.ErrorWriter.String())
|
|
|
|
if !strings.Contains(output, "address \"nope\" was not found in the Raft configuration") {
|
|
|
|
t.Fatalf("bad: %s", output)
|
|
|
|
}
|
|
|
|
}
|
2017-03-30 01:09:41 +00:00
|
|
|
|
|
|
|
// Test the remove-peer subcommand with -id
|
|
|
|
{
|
|
|
|
ui := new(cli.MockUi)
|
|
|
|
c := OperatorRaftRemoveCommand{
|
|
|
|
Command: base.Command{
|
2017-04-21 00:02:42 +00:00
|
|
|
UI: ui,
|
2017-03-30 01:09:41 +00:00
|
|
|
Flags: base.FlagSetHTTP,
|
|
|
|
},
|
|
|
|
}
|
2017-05-22 11:59:36 +00:00
|
|
|
args := []string{"-http-addr=" + a.HTTPAddr(), "-id=nope"}
|
2017-03-30 01:09:41 +00:00
|
|
|
|
|
|
|
code := c.Run(args)
|
|
|
|
if code != 1 {
|
|
|
|
t.Fatalf("bad: %d. %#v", code, ui.ErrorWriter.String())
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we get this error, it proves we sent the address all they through.
|
|
|
|
output := strings.TrimSpace(ui.ErrorWriter.String())
|
|
|
|
if !strings.Contains(output, "id \"nope\" was not found in the Raft configuration") {
|
|
|
|
t.Fatalf("bad: %s", output)
|
|
|
|
}
|
|
|
|
}
|
2017-02-15 21:30:07 +00:00
|
|
|
}
|