github.com/jrxfive/nomad@v0.6.1-0.20170802162750-1fef470e89bf/command/fs_test.go (about) 1 package command 2 3 import ( 4 "strings" 5 "testing" 6 7 "github.com/mitchellh/cli" 8 ) 9 10 func TestFSCommand_Implements(t *testing.T) { 11 t.Parallel() 12 var _ cli.Command = &FSCommand{} 13 } 14 15 func TestFSCommand_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 := &FSCommand{Meta: Meta{Ui: ui}} 22 23 // Fails on lack of job ID 24 if code := cmd.Run([]string{"-job"}); code != 1 { 25 t.Fatalf("expected exit code 1, got: %d", code) 26 } 27 if out := ui.ErrorWriter.String(); !strings.Contains(out, "job ID is required") { 28 t.Fatalf("expected help output, got: %s", out) 29 } 30 ui.ErrorWriter.Reset() 31 32 // Fails on lack of allocation ID 33 if code := cmd.Run([]string{}); code != 1 { 34 t.Fatalf("expected exit code 1, got: %d", code) 35 } 36 if out := ui.ErrorWriter.String(); !strings.Contains(out, "allocation ID is required") { 37 t.Fatalf("expected help output, got: %s", out) 38 } 39 ui.ErrorWriter.Reset() 40 41 // Fails on misuse 42 if code := cmd.Run([]string{"some", "bad", "args"}); code != 1 { 43 t.Fatalf("expected exit code 1, got: %d", code) 44 } 45 if out := ui.ErrorWriter.String(); !strings.Contains(out, cmd.Help()) { 46 t.Fatalf("expected help output, got: %s", out) 47 } 48 ui.ErrorWriter.Reset() 49 50 // Fails on connection failure 51 if code := cmd.Run([]string{"-address=nope", "foobar"}); code != 1 { 52 t.Fatalf("expected exit code 1, got: %d", code) 53 } 54 if out := ui.ErrorWriter.String(); !strings.Contains(out, "Error querying allocation") { 55 t.Fatalf("expected failed query error, got: %s", out) 56 } 57 ui.ErrorWriter.Reset() 58 59 // Fails on missing alloc 60 if code := cmd.Run([]string{"-address=" + url, "26470238-5CF2-438F-8772-DC67CFB0705C"}); 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 ui.ErrorWriter.Reset() 67 68 // Fail on identifier with too few characters 69 if code := cmd.Run([]string{"-address=" + url, "2"}); code != 1 { 70 t.Fatalf("expected exit 1, got: %d", code) 71 } 72 if out := ui.ErrorWriter.String(); !strings.Contains(out, "must contain at least two characters.") { 73 t.Fatalf("expected too few characters error, got: %s", out) 74 } 75 ui.ErrorWriter.Reset() 76 77 // Identifiers with uneven length should produce a query result 78 if code := cmd.Run([]string{"-address=" + url, "123"}); code != 1 { 79 t.Fatalf("expected exit 1, got: %d", code) 80 } 81 if out := ui.ErrorWriter.String(); !strings.Contains(out, "No allocation(s) with prefix or id") { 82 t.Fatalf("expected not found error, got: %s", out) 83 } 84 85 }