github.com/diptanu/nomad@v0.5.7-0.20170516172507-d72e86cbe3d9/command/eval_status_test.go (about)

     1  package command
     2  
     3  import (
     4  	"strings"
     5  	"testing"
     6  
     7  	"github.com/mitchellh/cli"
     8  )
     9  
    10  func TestEvalStatusCommand_Implements(t *testing.T) {
    11  	var _ cli.Command = &EvalStatusCommand{}
    12  }
    13  
    14  func TestEvalStatusCommand_Fails(t *testing.T) {
    15  	srv, _, url := testServer(t, nil)
    16  	defer srv.Stop()
    17  
    18  	ui := new(cli.MockUi)
    19  	cmd := &EvalStatusCommand{Meta: Meta{Ui: ui}}
    20  
    21  	// Fails on misuse
    22  	if code := cmd.Run([]string{"some", "bad", "args"}); code != 1 {
    23  		t.Fatalf("expected exit code 1, got: %d", code)
    24  	}
    25  	if out := ui.ErrorWriter.String(); !strings.Contains(out, cmd.Help()) {
    26  		t.Fatalf("expected help output, got: %s", out)
    27  	}
    28  	ui.ErrorWriter.Reset()
    29  
    30  	// Fails on eval lookup failure
    31  	if code := cmd.Run([]string{"-address=" + url, "3E55C771-76FC-423B-BCED-3E5314F433B1"}); code != 1 {
    32  		t.Fatalf("expect exit 1, got: %d", code)
    33  	}
    34  	if out := ui.ErrorWriter.String(); !strings.Contains(out, "No evaluation(s) with prefix or id") {
    35  		t.Fatalf("expect not found error, got: %s", out)
    36  	}
    37  	ui.ErrorWriter.Reset()
    38  
    39  	// Fails on connection failure
    40  	if code := cmd.Run([]string{"-address=nope", "12345678-abcd-efab-cdef-123456789abc"}); code != 1 {
    41  		t.Fatalf("expected exit code 1, got: %d", code)
    42  	}
    43  	if out := ui.ErrorWriter.String(); !strings.Contains(out, "Error querying evaluation") {
    44  		t.Fatalf("expected failed query error, got: %s", out)
    45  	}
    46  	ui.ErrorWriter.Reset()
    47  
    48  	// Failed on both -json and -t options are specified
    49  	if code := cmd.Run([]string{"-address=" + url, "-json", "-t", "{{.ID}}"}); code != 1 {
    50  		t.Fatalf("expected exit 1, got: %d", code)
    51  	}
    52  	if out := ui.ErrorWriter.String(); !strings.Contains(out, "Both -json and -t are not allowed") {
    53  		t.Fatalf("expected getting formatter error, got: %s", out)
    54  	}
    55  
    56  }