github.com/jrxfive/nomad@v0.6.1-0.20170802162750-1fef470e89bf/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  	t.Parallel()
    12  	var _ cli.Command = &JobDispatchCommand{}
    13  }
    14  
    15  func TestJobDispatchCommand_Fails(t *testing.T) {
    16  	t.Parallel()
    17  	ui := new(cli.MockUi)
    18  	cmd := &JobDispatchCommand{Meta: Meta{Ui: ui}}
    19  
    20  	// Fails on misuse
    21  	if code := cmd.Run([]string{"some", "bad", "args"}); code != 1 {
    22  		t.Fatalf("expected exit code 1, got: %d", code)
    23  	}
    24  	if out := ui.ErrorWriter.String(); !strings.Contains(out, cmd.Help()) {
    25  		t.Fatalf("expected help output, got: %s", out)
    26  	}
    27  	ui.ErrorWriter.Reset()
    28  
    29  	// Fails when specified file does not exist
    30  	if code := cmd.Run([]string{"foo", "/unicorns/leprechauns"}); code != 1 {
    31  		t.Fatalf("expect exit 1, got: %d", code)
    32  	}
    33  	if out := ui.ErrorWriter.String(); !strings.Contains(out, "Error reading input data") {
    34  		t.Fatalf("expect error reading input data: %v", out)
    35  	}
    36  	ui.ErrorWriter.Reset()
    37  
    38  	if code := cmd.Run([]string{"-address=nope", "foo"}); code != 1 {
    39  		t.Fatalf("expected exit code 1, got: %d", code)
    40  	}
    41  	if out := ui.ErrorWriter.String(); !strings.Contains(out, "Failed to dispatch") {
    42  		t.Fatalf("expected failed query error, got: %s", out)
    43  	}
    44  	ui.ErrorWriter.Reset()
    45  }