github.com/hhrutter/nomad@v0.6.0-rc2.0.20170723054333-80c4b03f0705/command/logs_test.go (about) 1 package command 2 3 import ( 4 "strings" 5 "testing" 6 7 "github.com/mitchellh/cli" 8 ) 9 10 func TestLogsCommand_Implements(t *testing.T) { 11 t.Parallel() 12 var _ cli.Command = &LogsCommand{} 13 } 14 15 func TestLogsCommand_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 := &LogsCommand{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 connection failure 33 if code := cmd.Run([]string{"-address=nope", "foobar"}); code != 1 { 34 t.Fatalf("expected exit code 1, got: %d", code) 35 } 36 if out := ui.ErrorWriter.String(); !strings.Contains(out, "Error querying allocation") { 37 t.Fatalf("expected failed query error, got: %s", out) 38 } 39 ui.ErrorWriter.Reset() 40 41 // Fails on missing alloc 42 if code := cmd.Run([]string{"-address=" + url, "26470238-5CF2-438F-8772-DC67CFB0705C"}); code != 1 { 43 t.Fatalf("expected exit 1, got: %d", code) 44 } 45 if out := ui.ErrorWriter.String(); !strings.Contains(out, "No allocation(s) with prefix or id") { 46 t.Fatalf("expected not found error, got: %s", out) 47 } 48 ui.ErrorWriter.Reset() 49 50 // Fail on identifier with too few characters 51 if code := cmd.Run([]string{"-address=" + url, "2"}); code != 1 { 52 t.Fatalf("expected exit 1, got: %d", code) 53 } 54 if out := ui.ErrorWriter.String(); !strings.Contains(out, "must contain at least two characters.") { 55 t.Fatalf("expected too few characters error, got: %s", out) 56 } 57 ui.ErrorWriter.Reset() 58 59 // Identifiers with uneven length should produce a query result 60 if code := cmd.Run([]string{"-address=" + url, "123"}); code != 1 { 61 t.Fatalf("expected exit 1, got: %d", code) 62 } 63 if out := ui.ErrorWriter.String(); !strings.Contains(out, "No allocation(s) with prefix or id") { 64 t.Fatalf("expected not found error, got: %s", out) 65 } 66 67 }