github.com/hhrutter/nomad@v0.6.0-rc2.0.20170723054333-80c4b03f0705/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 t.Parallel() 12 var _ cli.Command = &EvalStatusCommand{} 13 } 14 15 func TestEvalStatusCommand_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 := &EvalStatusCommand{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 eval lookup failure 33 if code := cmd.Run([]string{"-address=" + url, "3E55C771-76FC-423B-BCED-3E5314F433B1"}); code != 1 { 34 t.Fatalf("expect exit 1, got: %d", code) 35 } 36 if out := ui.ErrorWriter.String(); !strings.Contains(out, "No evaluation(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", "12345678-abcd-efab-cdef-123456789abc"}); code != 1 { 43 t.Fatalf("expected exit code 1, got: %d", code) 44 } 45 if out := ui.ErrorWriter.String(); !strings.Contains(out, "Error querying evaluation") { 46 t.Fatalf("expected failed query error, got: %s", out) 47 } 48 ui.ErrorWriter.Reset() 49 50 // Failed on both -json and -t options are specified 51 if code := cmd.Run([]string{"-address=" + url, "-json", "-t", "{{.ID}}"}); code != 1 { 52 t.Fatalf("expected exit 1, got: %d", code) 53 } 54 if out := ui.ErrorWriter.String(); !strings.Contains(out, "Both json and template formatting are not allowed") { 55 t.Fatalf("expected getting formatter error, got: %s", out) 56 } 57 58 }