github.com/kardianos/nomad@v0.1.3-0.20151022182107-b13df73ee850/command/alloc_status_test.go (about) 1 package command 2 3 import ( 4 "strings" 5 "testing" 6 7 "github.com/mitchellh/cli" 8 ) 9 10 func TestAllocStatusCommand_Implements(t *testing.T) { 11 var _ cli.Command = &AllocStatusCommand{} 12 } 13 14 func TestAllocStatusCommand_Fails(t *testing.T) { 15 srv, _, url := testServer(t, nil) 16 defer srv.Stop() 17 18 ui := new(cli.MockUi) 19 cmd := &AllocStatusCommand{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 connection failure 31 if code := cmd.Run([]string{"-address=nope", "foo"}); code != 1 { 32 t.Fatalf("expected exit code 1, got: %d", code) 33 } 34 if out := ui.ErrorWriter.String(); !strings.Contains(out, "Error querying allocation") { 35 t.Fatalf("expected failed query error, got: %s", out) 36 } 37 38 // Fails on missing alloc 39 if code := cmd.Run([]string{"-address=" + url, "26470238-5CF2-438F-8772-DC67CFB0705C"}); code != 1 { 40 t.Fatalf("expected exit 1, got: %d", code) 41 } 42 if out := ui.ErrorWriter.String(); !strings.Contains(out, "not found") { 43 t.Fatalf("expected not found error, got: %s", out) 44 } 45 }