github.com/sl1pm4t/consul@v1.4.5-0.20190325224627-74c31c540f9c/command/operator/raft/removepeer/operator_raft_remove_test.go (about) 1 package removepeer 2 3 import ( 4 "strings" 5 "testing" 6 7 "github.com/hashicorp/consul/agent" 8 "github.com/mitchellh/cli" 9 ) 10 11 func TestOperatorRaftRemovePeerCommand_noTabs(t *testing.T) { 12 t.Parallel() 13 if strings.ContainsRune(New(cli.NewMockUi()).Help(), '\t') { 14 t.Fatal("help has tabs") 15 } 16 } 17 18 func TestOperatorRaftRemovePeerCommand(t *testing.T) { 19 t.Parallel() 20 a := agent.NewTestAgent(t, t.Name(), ``) 21 defer a.Shutdown() 22 23 t.Run("Test the remove-peer subcommand directly", func(t *testing.T) { 24 ui := cli.NewMockUi() 25 c := New(ui) 26 args := []string{"-http-addr=" + a.HTTPAddr(), "-address=nope"} 27 28 code := c.Run(args) 29 if code != 1 { 30 t.Fatalf("bad: %d. %#v", code, ui.ErrorWriter.String()) 31 } 32 33 // If we get this error, it proves we sent the address all they through. 34 output := strings.TrimSpace(ui.ErrorWriter.String()) 35 if !strings.Contains(output, "address \"nope\" was not found in the Raft configuration") { 36 t.Fatalf("bad: %s", output) 37 } 38 }) 39 40 t.Run("Test the remove-peer subcommand with -id", func(t *testing.T) { 41 ui := cli.NewMockUi() 42 c := New(ui) 43 args := []string{"-http-addr=" + a.HTTPAddr(), "-id=nope"} 44 45 code := c.Run(args) 46 if code != 1 { 47 t.Fatalf("bad: %d. %#v", code, ui.ErrorWriter.String()) 48 } 49 50 // If we get this error, it proves we sent the address all they through. 51 output := strings.TrimSpace(ui.ErrorWriter.String()) 52 if !strings.Contains(output, "id \"nope\" was not found in the Raft configuration") { 53 t.Fatalf("bad: %s", output) 54 } 55 }) 56 }