github.com/hhrutter/nomad@v0.6.0-rc2.0.20170723054333-80c4b03f0705/command/stop_test.go (about) 1 package command 2 3 import ( 4 "strings" 5 "testing" 6 7 "github.com/mitchellh/cli" 8 ) 9 10 func TestStopCommand_Implements(t *testing.T) { 11 t.Parallel() 12 var _ cli.Command = &StopCommand{} 13 } 14 15 func TestStopCommand_Fails(t *testing.T) { 16 t.Parallel() 17 srv, _, url := testServer(t, false, nil) 18 defer srv.Shutdown() 19 20 ui := new(cli.MockUi) 21 cmd := &StopCommand{Meta: Meta{Ui: ui}} 22 23 // Fails on misuse 24 if code := cmd.Run([]string{"some", "bad", "args"}); code != 1 { 25 t.Fatalf("expected exit code 1, got: %d", code) 26 } 27 if out := ui.ErrorWriter.String(); !strings.Contains(out, cmd.Help()) { 28 t.Fatalf("expected help output, got: %s", out) 29 } 30 ui.ErrorWriter.Reset() 31 32 // Fails on non-existent job ID 33 if code := cmd.Run([]string{"-address=" + url, "nope"}); code != 1 { 34 t.Fatalf("expect exit 1, got: %d", code) 35 } 36 if out := ui.ErrorWriter.String(); !strings.Contains(out, "No job(s) with prefix or id") { 37 t.Fatalf("expect not found error, got: %s", out) 38 } 39 ui.ErrorWriter.Reset() 40 41 // Fails on connection failure 42 if code := cmd.Run([]string{"-address=nope", "nope"}); code != 1 { 43 t.Fatalf("expected exit code 1, got: %d", code) 44 } 45 if out := ui.ErrorWriter.String(); !strings.Contains(out, "Error deregistering job") { 46 t.Fatalf("expected failed query error, got: %s", out) 47 } 48 }