github.com/marwan-at-work/consul@v1.4.5/command/leave/leave_test.go (about) 1 package leave 2 3 import ( 4 "strings" 5 "testing" 6 7 "github.com/hashicorp/consul/agent" 8 "github.com/mitchellh/cli" 9 ) 10 11 func TestLeaveCommand_noTabs(t *testing.T) { 12 t.Parallel() 13 if strings.ContainsRune(New(nil).Help(), '\t') { 14 t.Fatal("help has tabs") 15 } 16 } 17 18 func TestLeaveCommand(t *testing.T) { 19 t.Parallel() 20 a := agent.NewTestAgent(t, t.Name(), ``) 21 defer a.Shutdown() 22 23 ui := cli.NewMockUi() 24 c := New(ui) 25 args := []string{"-http-addr=" + a.HTTPAddr()} 26 27 code := c.Run(args) 28 if code != 0 { 29 t.Fatalf("bad: %d. %#v", code, ui.ErrorWriter.String()) 30 } 31 32 if !strings.Contains(ui.OutputWriter.String(), "leave complete") { 33 t.Fatalf("bad: %#v", ui.OutputWriter.String()) 34 } 35 } 36 37 func TestLeaveCommand_FailOnNonFlagArgs(t *testing.T) { 38 t.Parallel() 39 a := agent.NewTestAgent(t, t.Name(), ``) 40 defer a.Shutdown() 41 42 ui := cli.NewMockUi() 43 c := New(ui) 44 args := []string{"-http-addr=" + a.HTTPAddr(), "appserver1"} 45 46 code := c.Run(args) 47 if code == 0 { 48 t.Fatalf("bad: failed to check for unexpected args") 49 } 50 }