github.com/diptanu/nomad@v0.5.7-0.20170516172507-d72e86cbe3d9/command/job_dispatch_test.go (about) 1 package command 2 3 import ( 4 "strings" 5 "testing" 6 7 "github.com/mitchellh/cli" 8 ) 9 10 func TestJobDispatchCommand_Implements(t *testing.T) { 11 var _ cli.Command = &JobDispatchCommand{} 12 } 13 14 func TestJobDispatchCommand_Fails(t *testing.T) { 15 ui := new(cli.MockUi) 16 cmd := &JobDispatchCommand{Meta: Meta{Ui: ui}} 17 18 // Fails on misuse 19 if code := cmd.Run([]string{"some", "bad", "args"}); code != 1 { 20 t.Fatalf("expected exit code 1, got: %d", code) 21 } 22 if out := ui.ErrorWriter.String(); !strings.Contains(out, cmd.Help()) { 23 t.Fatalf("expected help output, got: %s", out) 24 } 25 ui.ErrorWriter.Reset() 26 27 // Fails when specified file does not exist 28 if code := cmd.Run([]string{"foo", "/unicorns/leprechauns"}); code != 1 { 29 t.Fatalf("expect exit 1, got: %d", code) 30 } 31 if out := ui.ErrorWriter.String(); !strings.Contains(out, "Error reading input data") { 32 t.Fatalf("expect error reading input data: %v", out) 33 } 34 ui.ErrorWriter.Reset() 35 36 if code := cmd.Run([]string{"-address=nope", "foo"}); code != 1 { 37 t.Fatalf("expected exit code 1, got: %d", code) 38 } 39 if out := ui.ErrorWriter.String(); !strings.Contains(out, "Failed to dispatch") { 40 t.Fatalf("expected failed query error, got: %s", out) 41 } 42 ui.ErrorWriter.Reset() 43 }