github.com/thomasobenaus/nomad@v0.11.1/command/operator_raft_remove_test.go (about)

     1  package command
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/mitchellh/cli"
     7  	"github.com/stretchr/testify/assert"
     8  )
     9  
    10  func TestOperator_Raft_RemovePeers_Implements(t *testing.T) {
    11  	t.Parallel()
    12  	var _ cli.Command = &OperatorRaftRemoveCommand{}
    13  }
    14  
    15  func TestOperator_Raft_RemovePeer(t *testing.T) {
    16  	t.Parallel()
    17  	assert := assert.New(t)
    18  	s, _, addr := testServer(t, false, nil)
    19  	defer s.Shutdown()
    20  
    21  	ui := new(cli.MockUi)
    22  	c := &OperatorRaftRemoveCommand{Meta: Meta{Ui: ui}}
    23  	args := []string{"-address=" + addr, "-peer-address=nope", "-peer-id=nope"}
    24  
    25  	// Give both an address and ID
    26  	code := c.Run(args)
    27  	if code != 1 {
    28  		t.Fatalf("bad: %d. %#v", code, ui.ErrorWriter.String())
    29  	}
    30  
    31  	assert.Contains(ui.ErrorWriter.String(), "cannot give both an address and id")
    32  
    33  	// Neither address nor ID present
    34  	args = args[:1]
    35  	code = c.Run(args)
    36  	if code != 1 {
    37  		t.Fatalf("bad: %d. %#v", code, ui.ErrorWriter.String())
    38  	}
    39  
    40  	assert.Contains(ui.ErrorWriter.String(), "an address or id is required for the peer to remove")
    41  }
    42  
    43  func TestOperator_Raft_RemovePeerAddress(t *testing.T) {
    44  	t.Parallel()
    45  	assert := assert.New(t)
    46  	s, _, addr := testServer(t, false, nil)
    47  	defer s.Shutdown()
    48  
    49  	ui := new(cli.MockUi)
    50  	c := &OperatorRaftRemoveCommand{Meta: Meta{Ui: ui}}
    51  	args := []string{"-address=" + addr, "-peer-address=nope"}
    52  
    53  	code := c.Run(args)
    54  	if code != 1 {
    55  		t.Fatalf("bad: %d. %#v", code, ui.ErrorWriter.String())
    56  	}
    57  
    58  	// If we get this error, it proves we sent the address all they through.
    59  	assert.Contains(ui.ErrorWriter.String(), "address \"nope\" was not found in the Raft configuration")
    60  }
    61  
    62  func TestOperator_Raft_RemovePeerID(t *testing.T) {
    63  	t.Parallel()
    64  	assert := assert.New(t)
    65  	s, _, addr := testServer(t, false, nil)
    66  	defer s.Shutdown()
    67  
    68  	ui := new(cli.MockUi)
    69  	c := &OperatorRaftRemoveCommand{Meta: Meta{Ui: ui}}
    70  	args := []string{"-address=" + addr, "-peer-id=nope"}
    71  
    72  	code := c.Run(args)
    73  	if code != 1 {
    74  		t.Fatalf("bad: %d. %#v", code, ui.ErrorWriter.String())
    75  	}
    76  
    77  	// If we get this error, it proves we sent the address all they through.
    78  	assert.Contains(ui.ErrorWriter.String(), "id \"nope\" was not found in the Raft configuration")
    79  }